From 6e8f1b7fee98f17f31b7c8a3d2601c63d2a82276 Mon Sep 17 00:00:00 2001 From: Emilian Huminiuc Date: Sat, 6 Oct 2012 14:11:39 +0300 Subject: [PATCH] Restore the foam to the Rembrandt water shader Signed-off-by: Emilian Huminiuc --- Shaders/water-gbuffer.frag | 7 ++++--- Shaders/water-gbuffer.vert | 2 ++ Shaders/water_sine-gbuffer.frag | 11 ++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Shaders/water-gbuffer.frag b/Shaders/water-gbuffer.frag index 74ea6a9eb..4b607ddd0 100644 --- a/Shaders/water-gbuffer.frag +++ b/Shaders/water-gbuffer.frag @@ -38,7 +38,7 @@ varying vec4 waterTex1; //moving texcoords varying vec4 waterTex2; //moving texcoords varying vec3 viewerdir; varying vec3 normal; -varying vec3 Vnormal; +varying vec3 rawNormal; varying vec3 VTangent; varying vec3 VBinormal; @@ -65,7 +65,7 @@ void main(void) vec3 E = normalize(viewerdir); vec3 Normal = normalize(normal); - vec3 vNormal = normalize(Vnormal); + vec3 vNormal = normalize(rawNormal); const float water_shininess = 240.0; @@ -171,7 +171,8 @@ void main(void) vec3 N2 = normalize(mix(N0, N1, mixFactor) * waveRoughness); Normal = normalize(N2.x * VTangent + N2.y * VBinormal + N2.z * Normal); - vNormal = normalize(mix(vNormal + N0, vNormal + N1, mixFactor) * waveRoughness); + //vNormal = normalize(mix(vNormal + N0, vNormal + N1, mixFactor) * waveRoughness); + vNormal = normalize(N2.x * vec3(1.,0.,0.) + N2.y * vec3(0.,1.,0.) + N2.z * vNormal); if (normalmap_dds > 0){ Normal = -Normal; //dds fix diff --git a/Shaders/water-gbuffer.vert b/Shaders/water-gbuffer.vert index ba9a4babf..cdddea895 100644 --- a/Shaders/water-gbuffer.vert +++ b/Shaders/water-gbuffer.vert @@ -13,6 +13,7 @@ varying vec4 waterTex2; varying vec3 viewerdir; varying vec3 lightdir; varying vec3 normal; +varying vec3 rawNormal; varying vec3 VTangent; varying vec3 VBinormal; @@ -37,6 +38,7 @@ void rotationmatrix(in float angle, out mat4 rotmat) void main(void) { mat4 RotationMatrix; + rawNormal= gl_Normal; normal = gl_NormalMatrix * gl_Normal; VTangent = normalize(gl_NormalMatrix * tangent); VBinormal = normalize(gl_NormalMatrix * binormal); diff --git a/Shaders/water_sine-gbuffer.frag b/Shaders/water_sine-gbuffer.frag index c9e084a26..93e540261 100644 --- a/Shaders/water_sine-gbuffer.frag +++ b/Shaders/water_sine-gbuffer.frag @@ -46,7 +46,7 @@ varying vec4 waterTex2 ; //moving texcoords varying vec3 viewerdir ; varying vec3 lightdir ; varying vec3 normal ; -varying vec3 Vnormal ; +varying vec3 rawNormal ; varying vec3 VTangent ; varying vec3 VBinormal ; @@ -147,8 +147,8 @@ void main(void) //vec3 H = normalize(L + E); vec3 Normal = normalize(normal) ; - vec3 vNormal = normalize(Vnormal) ; - const float water_shininess = 128.0 ; + vec3 vNormal = normalize(rawNormal) ; + const float water_shininess = 240.0 ; // float range = gl_ProjectionMatrix[3].z/(gl_FragCoord.z * -2.0 + 1.0 - gl_ProjectionMatrix[2].z); @@ -334,7 +334,8 @@ void main(void) N0.g += ddySum; vec3 N2 = normalize(mix(N0, N1, mixFactor) * waveRoughness); Normal = normalize(N2.x * VTangent + N2.y * VBinormal + N2.z * Normal); - vNormal = normalize(mix(vNormal + N0, vNormal + N1, mixFactor) * waveRoughness); + //vNormal = normalize(mix(vNormal + N0, vNormal + N1, mixFactor) * waveRoughness); + vNormal = normalize(N2.x * vec3(1.0, 0.0, 0.0) + N2.y * vec3(0.0, 1., 0.0) + N2.z * vNormal); if (normalmap_dds > 0){ //dds fix Normal = -Normal; vNormal = -vNormal; @@ -379,5 +380,5 @@ void main(void) vec3( 0.3, 0.59, 0.11 ) ); float specular = smoothstep(0.0, 3.5, cover); - encode_gbuffer(Normal, finalColor.rgb, 254, specular, water_shininess, emission, gl_FragCoord.z); + encode_gbuffer(Normal, finalColor.rgb, 254, specular, water_shininess, emission, gl_FragCoord.z); }