diff --git a/files/shaders/water_fragment.glsl b/files/shaders/water_fragment.glsl index 931422d5e..f04a9d8a8 100644 --- a/files/shaders/water_fragment.glsl +++ b/files/shaders/water_fragment.glsl @@ -142,6 +142,9 @@ uniform vec3 nodePosition; uniform float rainIntensity; +uniform sampler2DShadow shadowTexture0; +varying vec4 shadowSpaceCoords; + float frustumDepth; float linearizeDepth(float depth) // takes <0,1> non-linear depth value and returns <0,1> linearized value @@ -158,7 +161,7 @@ void main(void) vec2 UV = worldPos.xy / (8192.0*5.0) * 3.0; UV.y *= -1.0; - float shadow = 1.0; + float shadow = shadow2DProj(shadowTexture0, shadowSpaceCoords).r; vec2 screenCoords = screenCoordsPassthrough.xy / screenCoordsPassthrough.z; screenCoords.y = (1.0-screenCoords.y); diff --git a/files/shaders/water_vertex.glsl b/files/shaders/water_vertex.glsl index 7d7b7b18a..513edc730 100644 --- a/files/shaders/water_vertex.glsl +++ b/files/shaders/water_vertex.glsl @@ -4,6 +4,8 @@ varying vec3 screenCoordsPassthrough; varying vec4 position; varying float depthPassthrough; +varying vec4 shadowSpaceCoords; + void main(void) { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; @@ -19,4 +21,8 @@ void main(void) position = gl_Vertex; depthPassthrough = gl_Position.z; + + // This matrix has the opposite handedness to the others used here, so multiplication must have the vector to the left. Alternatively it could be transposed after construction, but that's extra work for the GPU just to make the code look a tiny bit cleaner. + mat4 eyePlaneMat = mat4(gl_EyePlaneS[1], gl_EyePlaneT[1], gl_EyePlaneR[1], gl_EyePlaneQ[1]); + shadowSpaceCoords = (gl_ModelViewMatrix * gl_Vertex) * eyePlaneMat; }