How to get fragment world coordinates in canvas item shader?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By t17dr

From the built-ins FRAGCOORD seems to be a position in window/viewport space. VERTEX is a local position and I wasn’t able to correctly use the transform matrices to get world coordinates from it - multiplying VERTEX by WORLD_MATRIX makes the result still dependent on camera position.

I see that spatial shaders have a render mode called world_vertex_coords that changes the vertex info (for example, VERTEX) to world space. Not sure if that helps with canvas item shaders though. I do see that canvas item shader have a render mode called skip_vertex_transform, whose description is “VERTEX/NORMAL/etc need to be transformed manually in VS.” Maybe you need to set this render mode before you try to transform by the world matrix? Not sure, I’m brand new to shaders.

Diet Estus | 2018-04-14 23:04

I have tried that too, but it doesn’t seem to change anything:

world_pos = (WORLD_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
VERTEX = (EXTRA_MATRIX * (WORLD_MATRIX * vec4(VERTEX, 0.0, 1.0))).xy;

and world_pos still changes when moving the camera.

t17dr | 2018-04-15 08:59

Did you resolve this? I’m having trouble with this too.

hedgehog90 | 2018-05-23 11:56

There’s a bug report related to this: World_vertex_coords flag required in canvas_item shaders · Issue #19800 · godotengine/godot · GitHub

John Watson | 2018-07-30 22:36