Godot Version
v4.3.stable.official
Question
Hi - i’m following along with the advanced post processing docs -
the following shader works and produces the desired effect:
shader_type spatial;
render_mode unshaded, fog_disabled;
uniform sampler2D depth_texture : hint_depth_texture;
void vertex() {
POSITION = vec4(VERTEX.xy, 1.0, 1.0);
}
void fragment() {
float depth = texture(depth_texture, SCREEN_UV).x;
vec3 ndc = vec3(SCREEN_UV, depth) * 2.0 - 1.0;
vec4 view = INV_PROJECTION_MATRIX * vec4(ndc, 1.0);
view.xyz /= view.w;
float linear_depth = -view.z;
// Visualize linear depth
ALBEDO.rgb = vec3(fract(linear_depth));
}
However, when I try to use the same code in this DepthVS function, the shader no longer works. It also doesn’t produce any console errors.
shader_type spatial;
render_mode unshaded, fog_disabled;
uniform sampler2D depth_texture : hint_depth_texture;
void vertex() {
POSITION = vec4(VERTEX.xy, 1.0, 1.0);
}
float DepthVS(vec2 uv, mat4 inv_projection_mat) {
float depth = texture(depth_texture, uv).x;
vec3 ndc = vec3(uv, depth) * 2.0 - 1.0;
vec4 view = inv_projection_mat * vec4(ndc, 1.0);
view.xyz /= view.w;
float linear_depth = -view.z;
return linear_depth;
}
void fragment() {
float linear_depth = DepthVS(SCREEN_UV, INV_PROJECTION_MATRIX); // todo: for some reason when separating below code into separate function it doesn't work
// Visualize linear depth
ALBEDO.rgb = vec3(fract(linear_depth));
}
This only happens in Compatibility mode. Switching to forward+ (and accounting for clip space changes) works fine.
Any idea what might be going on?