I've been working for the past while on a shader that renders Tsutomu Nihei-inspired megastructures, but for all my efforts I can't get the collisions (raymarched in my KinematicBody gdscript) and the shader to line up properly. I think I've narrowed down the problem to the following vertex() function in my shader:
void vertex() {
POSITION = vec4(VERTEX, 1.0);
}
and I believe I need to somehow convert VERTEX from local space to World Space using WORLD_MATRIX (I'm in Godot 3), but when I do so my shader breaks. Also not entirely sure if "local space" (which is what I found in the documentation) refers to model space or something else. Here's the fragment:
void fragment() {
vec2 uv = SCREEN_UV * 2.0 - 1.0;
vec3 ray_origin = (CAMERA_MATRIX * vec4(0., 0., 0., 1.)).xyz;
vec4 camera = CAMERA_MATRIX * INV_PROJECTION_MATRIX * vec4(uv, 1, 1);
vec3 ray_dir = normalize(camera.xyz);
vec4 raymarchColor = raymarch(ray_dir, ray_origin);
ALBEDO = raymarchColor.rgb*raymarchColor.a;
ALPHA = 1.0;
}
My understanding is that the ray_origin takes the position of the camera in world space and ray direction converts the screen space pixel to its world space position through a couple transforms, but maybe the camera position isn't in world space due to using local co-ordinates in the vertex function. I might also be completely off-course! I've been teaching myself shaders through the project so if anybody can point me in the right direction I'd be extremely grateful