Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NODE_POSITION_WORLD and NODE_POSITION_VIEW shader built-ins do not yield the expected results ('model_matrix' : undeclared identifier) #67894

Closed
alfredbaudisch opened this issue Oct 26, 2022 · 6 comments · Fixed by #67907 or #68966

Comments

@alfredbaudisch
Copy link
Contributor

alfredbaudisch commented Oct 26, 2022

Godot version

Godot4-beta3

System information

Windows 10

Issue description

The NODE_* built-ins implemented in #63597 are currently null/0.

UPDATE: By pulling Godot from the master branch, there's now a related crash when using the NODE_* built-ins (either in a Shader and VS):

ERROR: 0:2121: 'model_matrix' : undeclared identifier 
ERROR: 0:2121: 'model_matrix' :  left of '[' is not of type array, matrix, or vector  
ERROR: 0:2121: 'assign' :  cannot convert from ' const float' to ' temp highp 3-component vector of float'
ERROR: 0:2121: '' : compilation terminated 
ERROR: 4 compilation errors.  No code generated.

To make it easy to visualize for this Issue, I set them both to the Albedo channel, so it would be possible to visualize the RGB colors changing, but no matter where in the world, there are no changes:

image

image

Expected - NODE_POSITION_WORLD / World Position

Unity:
image

UE:
image

Expected - NODE_POSITION_VIEW / Object Position

Unity:
image

UE:
image

Steps to reproduce

Use NODE_POSITION_WORLD and/or NODE_POSITION_VIEW in any shader (VS or GDShader), the result is always 0.

void fragment() {
ALBEDO = NODE_POSITION_VIEW;
}

Minimal reproduction project

NodePositionSample.zip

@alfredbaudisch alfredbaudisch changed the title NODE_POSITION_WORLD and NODE_POSITION_VIEW shader built-ins do not yield the expected results NODE_POSITION_WORLD and NODE_POSITION_VIEW shader built-ins do not yield the expected results ('model_matrix' : undeclared identifier) Oct 26, 2022
@clayjohn clayjohn added this to the 4.0 milestone Oct 26, 2022
@clayjohn
Copy link
Member

Cc @paddy-exe

@paddy-exe
Copy link
Contributor

@clayjohn From testing I can say that there must be a regression between beta 2 and beta 3

This is how it looks like when it's working in beta 2:

_.Test.-.Godot.Engine.2022-10-26.18-05-02.mp4

@clayjohn
Copy link
Member

@paddy-exe the issue must be from my double precision changes, I will take a look

@alekseym88
Copy link

alekseym88 commented Nov 19, 2022

@akien-mga @clayjohn Hello! Seems this problem is still exist, I have same problem for last godot build on MacOS Monterey, graphics: Intel Iris Graphics 550 1536 MB.

shader_type spatial;
render_mode unshaded;

void fragment() {

	vec4 view = VIEW_MATRIX * vec4(NODE_POSITION_WORLD, 1.0);
	vec3 view_n = view.xyz/view.w;
	
	if (view_n == NODE_POSITION_VIEW){
		ALBEDO = vec3(1.0, 0.0, 0.0);
	}
}

and

shader_type spatial;
render_mode unshaded;

void fragment() {

	vec4 world = INV_VIEW_MATRIX * vec4(NODE_POSITION_VIEW, 1.0);
	vec3 world_n = world.xyz/world.w;
		
	if (world_n == NODE_POSITION_WORLD){
		ALBEDO = vec3(1.0, 0.0, 0.0);
	}
}

gives a white screen instead red (as should be on IF condition)

@clayjohn
Copy link
Member

@alekseym88 this bug report was reporting a shader compilation error that came from using those builtins. The fact that your shader compiles means you are not facing the same issue.

Your issue comes from floating point precision. By doing multiple operations, you are losing precision such that the equality operator fails. Take a look at this site for a deeper explanation about how floating point numbers work and why avoiding == between two floats is important

@Lunarexxy
Copy link

Lunarexxy commented Nov 21, 2022

It appears that model_matrix being undeclared is still an issue in web exports. Godot 4 beta 5, tested on Firefox.

image

Using only this in my visual shader. (node_position_view has a similar "model_matrix undeclared" error)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment