Skip to content

Commit fe936f1

Browse files
committed
Minimize false depth intersections
Clamps depth with 'real' depth. Fixes #18
1 parent b599b2b commit fe936f1

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

godot/Shaders/water_3d.shader

+5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ void vertex() {
2929
void fragment() {
3030
vec2 uv = SCREEN_UV + (texture(refraction_noise, UV + (TIME * movement_direction) * refraction_speed).rg * 2.0 - 1.0) * refraction_strength;
3131

32+
float real_depth = texture(DEPTH_TEXTURE, SCREEN_UV).r * 2.0 - 1.0;
33+
real_depth = PROJECTION_MATRIX[3][2] / (real_depth + PROJECTION_MATRIX[2][2]) + VERTEX.z;
34+
3235
//Get the raw linear depth from the depth texture into a [-1, 1] range
3336
float depth = texture(DEPTH_TEXTURE, uv).r * 2.0 - 1.0;
3437
//Recreate linear depth of the intersecting geometry using projection matrix, and subtract the vertex of the sphere
3538
depth = PROJECTION_MATRIX[3][2] / (depth + PROJECTION_MATRIX[2][2]) + VERTEX.z;
3639

40+
depth = max(depth, real_depth);
41+
3742
float intersection = clamp(depth / foam_amount, 0, 1) * foam_cutoff;
3843

3944
vec4 out_color = mix(shallow_color, deep_color, clamp((depth / depth_distance), 0, 1));

godot/project.godot

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@ jump={
104104
quality/2d/use_pixel_snap=true
105105
quality/shadows/filter_mode=2
106106
quality/reflections/irradiance_max_size=2048
107-
quality/filters/msaa=3
107+
quality/filters/msaa=2
108108
environment/default_environment="res://default_env.tres"

0 commit comments

Comments
 (0)