Problems finding ray direction in post-processing raymarcher

Godot Version

4.3

Question

I’m creating a raymarcher (pretty similar to a raytracer)
Until now, I was rendering everything on a big plane at the center of the scene
To determine the direction towards which to shoot the ray, I used this code:

normalize(VERTEX-CAMERA_POSITION_WORLD)

and everything worked perfectly
To make the plane “follow” the camera, I’m currently using this code

void vertex() {
	POSITION = vec4(VERTEX.xy, 1.0, 1.0);
}

to make the object fully cover the screen
But now in the fragment shader the values I get from VERTEX are totally wrong and the rest of the shader is totally broken
Does anybody know how to solve this problem?
Thanks in advance

VERTEX isn’t in world coordinates unless you specify the render_mode world_vertex_coords

1 Like

Thanks for the reply!
I tried it, but it didn’t change anything and everything is still broken…
Have you got any other ideas to determine the ray direction?
Thanks a lot for your help!

Damn I love chatGPT:

	vec3 ro = CAMERA_POSITION_WORLD;
	vec4 clip_position = vec4(SCREEN_UV * 2.0 - 1.0, 1.0, 1.0);
	vec4 view_position = INV_PROJECTION_MATRIX * clip_position;
	vec4 world_position = INV_VIEW_MATRIX * view_position;
	vec3 rd = normalize(world_position.xyz-ro);//The Secret Forbidden RAY DIRECTION!

Thank you anyway!