4.3
I am trying to make a shader that fades things away in darkens behind it, eg dark tunnels and holes, this is actually what the proximity does, but the proximity looks more like a wall instead of darkness, and i am completely stuck.
any idea?
shader_type spatial;
uniform vec4 albedo : source_color;
uniform float fade_distance : hint_range(0.5, 5.0, 0.5);
uniform sampler2D depth_texture : hint_depth_texture, repeat_disable, filter_nearest;
void fragment() {
ALBEDO = albedo.rgb;
float depth_tex = textureLod(depth_texture, SCREEN_UV, 1.0).r;
//regular proximity code
//vec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV, depth_tex, 1.0);
//world_pos.xyz /= world_pos.w;
//ALPHA *= clamp(1.0 - smoothstep(world_pos.z + fade_distance, world_pos.z, VERTEX.z), 0.0, 1.0);
//kinda works as i want but the camera position are messing it up
vec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV, depth_tex, 1.0);
world_pos.xyz *= world_pos.w;
ALPHA -= mix(ALPHA + smoothstep(world_pos.z + fade_distance, world_pos.z, VERTEX.z), 1.0, 2.0);
}