|
@@ -20,6 +20,7 @@
|
|
// IN THE SOFTWARE.
|
|
// IN THE SOFTWARE.
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
+#include "../../gl/hlslCompat.glsl"
|
|
#include "shadergen:/autogenConditioners.h"
|
|
#include "shadergen:/autogenConditioners.h"
|
|
#include "../../gl/torque.glsl"
|
|
#include "../../gl/torque.glsl"
|
|
|
|
|
|
@@ -27,10 +28,7 @@
|
|
// Defines
|
|
// Defines
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
-#ifdef TORQUE_BASIC_LIGHTING
|
|
|
|
- #define BASIC
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
|
|
+#define PIXEL_DIST IN_rippleTexCoord2.z
|
|
// miscParams
|
|
// miscParams
|
|
#define FRESNEL_BIAS miscParams[0]
|
|
#define FRESNEL_BIAS miscParams[0]
|
|
#define FRESNEL_POWER miscParams[1]
|
|
#define FRESNEL_POWER miscParams[1]
|
|
@@ -57,33 +55,54 @@
|
|
#define DISTORT_FULL_DEPTH distortionParams[2]
|
|
#define DISTORT_FULL_DEPTH distortionParams[2]
|
|
|
|
|
|
// foamParams
|
|
// foamParams
|
|
-#define FOAM_SCALE foamParams[0]
|
|
|
|
|
|
+#define FOAM_OPACITY foamParams[0]
|
|
#define FOAM_MAX_DEPTH foamParams[1]
|
|
#define FOAM_MAX_DEPTH foamParams[1]
|
|
|
|
+#define FOAM_AMBIENT_LERP foamParams[2]
|
|
|
|
+#define FOAM_RIPPLE_INFLUENCE foamParams[3]
|
|
|
|
+
|
|
|
|
+// specularParams
|
|
|
|
+#define SPEC_POWER specularParams[3]
|
|
|
|
+#define SPEC_COLOR specularParams.xyz
|
|
|
|
+
|
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
|
+// Structures
|
|
|
|
+//-----------------------------------------------------------------------------
|
|
|
|
+
|
|
|
|
+//ConnectData IN
|
|
|
|
|
|
-// Incoming data
|
|
|
|
-// Worldspace position of this pixel
|
|
|
|
-varying vec3 worldPos;
|
|
|
|
|
|
+in vec4 hpos;
|
|
|
|
|
|
// TexCoord 0 and 1 (xy,zw) for ripple texture lookup
|
|
// TexCoord 0 and 1 (xy,zw) for ripple texture lookup
|
|
-varying vec4 rippleTexCoord01;
|
|
|
|
|
|
+in vec4 rippleTexCoord01;
|
|
|
|
|
|
-// TexCoord 2 for ripple texture lookup
|
|
|
|
-varying vec2 rippleTexCoord2;
|
|
|
|
|
|
+// xy is TexCoord 2 for ripple texture lookup
|
|
|
|
+// z is the Worldspace unit distance/depth of this vertex/pixel
|
|
|
|
+// w is amount of the crestFoam ( more at crest of waves ).
|
|
|
|
+in vec4 rippleTexCoord2;
|
|
|
|
|
|
// Screenspace vert position BEFORE wave transformation
|
|
// Screenspace vert position BEFORE wave transformation
|
|
-varying vec4 posPreWave;
|
|
|
|
|
|
+in vec4 posPreWave;
|
|
|
|
|
|
// Screenspace vert position AFTER wave transformation
|
|
// Screenspace vert position AFTER wave transformation
|
|
-varying vec4 posPostWave;
|
|
|
|
|
|
+in vec4 posPostWave;
|
|
|
|
|
|
-// Worldspace unit distance/depth of this vertex/pixel
|
|
|
|
-varying float pixelDist;
|
|
|
|
|
|
+// Objectspace vert position BEFORE wave transformation
|
|
|
|
+// w coord is world space z position.
|
|
|
|
+in vec4 objPos;
|
|
|
|
|
|
-varying vec3 fogPos;
|
|
|
|
|
|
+in vec4 foamTexCoords;
|
|
|
|
|
|
-varying float worldSpaceZ;
|
|
|
|
|
|
+in mat3 tangentMat;
|
|
|
|
|
|
-varying vec4 foamTexCoords;
|
|
|
|
|
|
+
|
|
|
|
+#define IN_hpos hpos
|
|
|
|
+#define IN_rippleTexCoord01 rippleTexCoord01
|
|
|
|
+#define IN_rippleTexCoord2 rippleTexCoord2
|
|
|
|
+#define IN_posPreWave posPreWave
|
|
|
|
+#define IN_posPostWave posPostWave
|
|
|
|
+#define IN_objPos objPos
|
|
|
|
+#define IN_foamTexCoords foamTexCoords
|
|
|
|
+#define IN_tangentMat tangentMat
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
// approximate Fresnel function
|
|
// approximate Fresnel function
|
|
@@ -100,10 +119,10 @@ uniform sampler2D bumpMap;
|
|
uniform sampler2D prepassTex;
|
|
uniform sampler2D prepassTex;
|
|
uniform sampler2D reflectMap;
|
|
uniform sampler2D reflectMap;
|
|
uniform sampler2D refractBuff;
|
|
uniform sampler2D refractBuff;
|
|
-uniform samplerCUBE skyMap;
|
|
|
|
|
|
+uniform samplerCube skyMap;
|
|
uniform sampler2D foamMap;
|
|
uniform sampler2D foamMap;
|
|
-uniform vec4 specularColor;
|
|
|
|
-uniform float specularPower;
|
|
|
|
|
|
+uniform sampler1D depthGradMap;
|
|
|
|
+uniform vec4 specularParams;
|
|
uniform vec4 baseColor;
|
|
uniform vec4 baseColor;
|
|
uniform vec4 miscParams;
|
|
uniform vec4 miscParams;
|
|
uniform vec2 fogParams;
|
|
uniform vec2 fogParams;
|
|
@@ -112,64 +131,45 @@ uniform vec3 reflectNormal;
|
|
uniform vec2 wetnessParams;
|
|
uniform vec2 wetnessParams;
|
|
uniform float farPlaneDist;
|
|
uniform float farPlaneDist;
|
|
uniform vec3 distortionParams;
|
|
uniform vec3 distortionParams;
|
|
-//uniform vec4 renderTargetParams;
|
|
|
|
-uniform vec2 foamParams;
|
|
|
|
-uniform vec3 foamColorMod;
|
|
|
|
|
|
+uniform vec4 foamParams;
|
|
uniform vec3 ambientColor;
|
|
uniform vec3 ambientColor;
|
|
-uniform vec3 eyePos;
|
|
|
|
-uniform vec3 inLightVec;
|
|
|
|
|
|
+uniform vec3 eyePos; // This is in object space!
|
|
uniform vec3 fogData;
|
|
uniform vec3 fogData;
|
|
uniform vec4 fogColor;
|
|
uniform vec4 fogColor;
|
|
-//uniform vec4 rtParams;
|
|
|
|
-uniform vec2 rtScale;
|
|
|
|
-uniform vec2 rtHalfPixel;
|
|
|
|
-uniform vec4 rtOffset;
|
|
|
|
-uniform vec3 rippleMagnitude;
|
|
|
|
|
|
+uniform vec4 rippleMagnitude;
|
|
|
|
+uniform vec4 rtParams1;
|
|
|
|
+uniform float depthGradMax;
|
|
|
|
+uniform vec3 inLightVec;
|
|
|
|
+uniform mat4 modelMat;
|
|
|
|
+uniform vec4 sunColor;
|
|
|
|
+uniform float sunBrightness;
|
|
|
|
+uniform float reflectivity;
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
// Main
|
|
// Main
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
void main()
|
|
void main()
|
|
{
|
|
{
|
|
- vec4 rtParams = vec4( rtOffset.x / rtOffset.z + rtHalfPixel.x,
|
|
|
|
- rtOffset.y / rtOffset.w + rtHalfPixel.x,
|
|
|
|
- rtScale );
|
|
|
|
-
|
|
|
|
- // Modulate baseColor by the ambientColor.
|
|
|
|
- vec4 waterBaseColor = baseColor * vec4( ambientColor.rgb, 1 );
|
|
|
|
-
|
|
|
|
// Get the bumpNorm...
|
|
// Get the bumpNorm...
|
|
- vec3 bumpNorm = ( tex2D( bumpMap, IN.rippleTexCoord01.xy ) * 2.0 - 1.0 ) * rippleMagnitude.x;
|
|
|
|
- bumpNorm += ( tex2D( bumpMap, IN.rippleTexCoord01.zw ) * 2.0 - 1.0 ) * rippleMagnitude.y;
|
|
|
|
- bumpNorm += ( tex2D( bumpMap, IN.rippleTexCoord2 ) * 2.0 - 1.0 ) * rippleMagnitude.z;
|
|
|
|
-
|
|
|
|
- // JCF: this was here, but seems to make the dot product against the bump
|
|
|
|
- // normal we use below for cubeMap fade-in to be less reliable.
|
|
|
|
- //bumpNorm.xy *= 0.75;
|
|
|
|
- //bumpNorm = normalize( bumpNorm );
|
|
|
|
- //return vec4( bumpNorm, 1 );
|
|
|
|
|
|
+ vec3 bumpNorm = ( texture( bumpMap, IN_rippleTexCoord01.xy ).rgb * 2.0 - 1.0 ) * rippleMagnitude.x;
|
|
|
|
+ bumpNorm += ( texture( bumpMap, IN_rippleTexCoord01.zw ).rgb * 2.0 - 1.0 ) * rippleMagnitude.y;
|
|
|
|
+ bumpNorm += ( texture( bumpMap, IN_rippleTexCoord2.xy ).rgb * 2.0 - 1.0 ) * rippleMagnitude.z;
|
|
|
|
+
|
|
|
|
+ bumpNorm = normalize( bumpNorm );
|
|
|
|
+ bumpNorm = mix( bumpNorm, vec3(0,0,1), 1.0 - rippleMagnitude.w );
|
|
|
|
+ bumpNorm = tMul( bumpNorm, IN_tangentMat );
|
|
|
|
|
|
// Get depth of the water surface (this pixel).
|
|
// Get depth of the water surface (this pixel).
|
|
// Convert from WorldSpace to EyeSpace.
|
|
// Convert from WorldSpace to EyeSpace.
|
|
- float pixelDepth = IN.pixelDist / farPlaneDist;
|
|
|
|
|
|
+ float pixelDepth = PIXEL_DIST / farPlaneDist;
|
|
|
|
|
|
- // Get prepass depth at the undistorted pixel.
|
|
|
|
- //vec4 prepassCoord = IN.posPostWave;
|
|
|
|
- //prepassCoord.xy += renderTargetParams.xy;
|
|
|
|
- vec2 prepassCoord = viewportCoordToRenderTarget( IN.posPostWave, rtParams );
|
|
|
|
- //vec2 prepassCoord = IN.posPostWave.xy;
|
|
|
|
|
|
+ vec2 prepassCoord = viewportCoordToRenderTarget( IN_posPostWave, rtParams1 );
|
|
|
|
|
|
- float startDepth = prepassUncondition( tex2D( prepassTex, prepassCoord ) ).w;
|
|
|
|
- //return vec4( startDepth.rrr, 1 );
|
|
|
|
|
|
+ float startDepth = prepassUncondition( prepassTex, prepassCoord ).w;
|
|
|
|
|
|
// The water depth in world units of the undistorted pixel.
|
|
// The water depth in world units of the undistorted pixel.
|
|
float startDelta = ( startDepth - pixelDepth );
|
|
float startDelta = ( startDepth - pixelDepth );
|
|
- if ( startDelta <= 0.0 )
|
|
|
|
- {
|
|
|
|
- //return vec4( 1, 0, 0, 1 );
|
|
|
|
- startDelta = 0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ startDelta = max( startDelta, 0.0 );
|
|
startDelta *= farPlaneDist;
|
|
startDelta *= farPlaneDist;
|
|
|
|
|
|
// Calculate the distortion amount for the water surface.
|
|
// Calculate the distortion amount for the water surface.
|
|
@@ -177,23 +177,22 @@ void main()
|
|
// We subtract a little from it so that we don't
|
|
// We subtract a little from it so that we don't
|
|
// distort where the water surface intersects the
|
|
// distort where the water surface intersects the
|
|
// camera near plane.
|
|
// camera near plane.
|
|
- float distortAmt = saturate( ( IN.pixelDist - DISTORT_START_DIST ) / DISTORT_END_DIST );
|
|
|
|
|
|
+ float distortAmt = saturate( ( PIXEL_DIST - DISTORT_START_DIST ) / DISTORT_END_DIST );
|
|
|
|
|
|
// Scale down distortion in shallow water.
|
|
// Scale down distortion in shallow water.
|
|
distortAmt *= saturate( startDelta / DISTORT_FULL_DEPTH );
|
|
distortAmt *= saturate( startDelta / DISTORT_FULL_DEPTH );
|
|
- //distortAmt = 0;
|
|
|
|
|
|
|
|
// Do the intial distortion... we might remove it below.
|
|
// Do the intial distortion... we might remove it below.
|
|
vec2 distortDelta = bumpNorm.xy * distortAmt;
|
|
vec2 distortDelta = bumpNorm.xy * distortAmt;
|
|
- vec4 distortPos = IN.posPostWave;
|
|
|
|
|
|
+ vec4 distortPos = IN_posPostWave;
|
|
distortPos.xy += distortDelta;
|
|
distortPos.xy += distortDelta;
|
|
|
|
|
|
- prepassCoord = viewportCoordToRenderTarget( distortPos, rtParams );
|
|
|
|
- //prepassCoord = distortPos;
|
|
|
|
- //prepassCoord.xy += renderTargetParams.xy;
|
|
|
|
|
|
+ prepassCoord = viewportCoordToRenderTarget( distortPos, rtParams1 );
|
|
|
|
|
|
// Get prepass depth at the position of this distorted pixel.
|
|
// Get prepass depth at the position of this distorted pixel.
|
|
- float prepassDepth = prepassUncondition( tex2D( prepassTex, prepassCoord ) ).w;
|
|
|
|
|
|
+ float prepassDepth = prepassUncondition( prepassTex, prepassCoord ).w;
|
|
|
|
+ if ( prepassDepth > 0.99 )
|
|
|
|
+ prepassDepth = 5.0;
|
|
|
|
|
|
float delta = ( prepassDepth - pixelDepth ) * farPlaneDist;
|
|
float delta = ( prepassDepth - pixelDepth ) * farPlaneDist;
|
|
|
|
|
|
@@ -202,7 +201,7 @@ void main()
|
|
// If we got a negative delta then the distorted
|
|
// If we got a negative delta then the distorted
|
|
// sample is above the water surface. Mask it out
|
|
// sample is above the water surface. Mask it out
|
|
// by removing the distortion.
|
|
// by removing the distortion.
|
|
- distortPos = IN.posPostWave;
|
|
|
|
|
|
+ distortPos = IN_posPostWave;
|
|
delta = startDelta;
|
|
delta = startDelta;
|
|
distortAmt = 0;
|
|
distortAmt = 0;
|
|
}
|
|
}
|
|
@@ -212,20 +211,20 @@ void main()
|
|
|
|
|
|
if ( diff < 0 )
|
|
if ( diff < 0 )
|
|
{
|
|
{
|
|
- distortAmt = saturate( ( IN.pixelDist - DISTORT_START_DIST ) / DISTORT_END_DIST );
|
|
|
|
|
|
+ distortAmt = saturate( ( PIXEL_DIST - DISTORT_START_DIST ) / DISTORT_END_DIST );
|
|
distortAmt *= saturate( delta / DISTORT_FULL_DEPTH );
|
|
distortAmt *= saturate( delta / DISTORT_FULL_DEPTH );
|
|
|
|
|
|
distortDelta = bumpNorm.xy * distortAmt;
|
|
distortDelta = bumpNorm.xy * distortAmt;
|
|
|
|
|
|
- distortPos = IN.posPostWave;
|
|
|
|
|
|
+ distortPos = IN_posPostWave;
|
|
distortPos.xy += distortDelta;
|
|
distortPos.xy += distortDelta;
|
|
|
|
|
|
- prepassCoord = viewportCoordToRenderTarget( distortPos, rtParams );
|
|
|
|
- //prepassCoord = distortPos;
|
|
|
|
- //prepassCoord.xy += renderTargetParams.xy;
|
|
|
|
|
|
+ prepassCoord = viewportCoordToRenderTarget( distortPos, rtParams1 );
|
|
|
|
|
|
// Get prepass depth at the position of this distorted pixel.
|
|
// Get prepass depth at the position of this distorted pixel.
|
|
- prepassDepth = prepassUncondition( tex2D( prepassTex, prepassCoord ) ).w;
|
|
|
|
|
|
+ prepassDepth = prepassUncondition( prepassTex, prepassCoord ).w;
|
|
|
|
+ if ( prepassDepth > 0.99 )
|
|
|
|
+ prepassDepth = 5.0;
|
|
delta = ( prepassDepth - pixelDepth ) * farPlaneDist;
|
|
delta = ( prepassDepth - pixelDepth ) * farPlaneDist;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -234,133 +233,78 @@ void main()
|
|
// If we got a negative delta then the distorted
|
|
// If we got a negative delta then the distorted
|
|
// sample is above the water surface. Mask it out
|
|
// sample is above the water surface. Mask it out
|
|
// by removing the distortion.
|
|
// by removing the distortion.
|
|
- distortPos = IN.posPostWave;
|
|
|
|
|
|
+ distortPos = IN_posPostWave;
|
|
delta = startDelta;
|
|
delta = startDelta;
|
|
distortAmt = 0;
|
|
distortAmt = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- //return vec4( prepassDepth.rrr, 1 );
|
|
|
|
-
|
|
|
|
- vec4 temp = IN.posPreWave;
|
|
|
|
|
|
+ vec4 temp = IN_posPreWave;
|
|
temp.xy += bumpNorm.xy * distortAmt;
|
|
temp.xy += bumpNorm.xy * distortAmt;
|
|
- vec2 reflectCoord = viewportCoordToRenderTarget( temp, rtParams );
|
|
|
|
|
|
+ vec2 reflectCoord = viewportCoordToRenderTarget( temp, rtParams1 );
|
|
|
|
|
|
- vec2 refractCoord = viewportCoordToRenderTarget( distortPos, rtParams );
|
|
|
|
|
|
+ vec2 refractCoord = viewportCoordToRenderTarget( distortPos, rtParams1 );
|
|
|
|
|
|
- // Use cubemap colors instead of reflection colors in several cases...
|
|
|
|
-
|
|
|
|
- // First lookup the CubeMap color
|
|
|
|
- // JCF: which do we want to use here, the reflectNormal or the bumpNormal
|
|
|
|
- // neithor of them is exactly right and how can we combine the two together?
|
|
|
|
- //bumpNorm = reflectNormal;
|
|
|
|
- vec3 eyeVec = IN.worldPos - eyePos;
|
|
|
|
|
|
+ vec4 fakeColor = vec4(ambientColor,1);
|
|
|
|
+ vec3 eyeVec = IN_objPos.xyz - eyePos;
|
|
|
|
+ eyeVec = tMul( mat3(modelMat), eyeVec );
|
|
|
|
+ eyeVec = tMul( IN_tangentMat, eyeVec );
|
|
vec3 reflectionVec = reflect( eyeVec, bumpNorm );
|
|
vec3 reflectionVec = reflect( eyeVec, bumpNorm );
|
|
- //vec4 cubeColor = texCUBE( skyMap, reflectionVec );
|
|
|
|
- //return cubeColor;
|
|
|
|
- // JCF: using ambient color instead of cubeColor for waterPlane, how do we still use the cubemap for rivers?
|
|
|
|
- vec4 cubeColor = vec4(ambientColor,1);
|
|
|
|
- //cubeColor.rgb = vec3( 0, 0, 1 );
|
|
|
|
|
|
|
|
- // Use cubeColor for waves that are angled towards camera
|
|
|
|
|
|
+ // Use fakeColor for ripple-normals that are angled towards the camera
|
|
eyeVec = -eyeVec;
|
|
eyeVec = -eyeVec;
|
|
eyeVec = normalize( eyeVec );
|
|
eyeVec = normalize( eyeVec );
|
|
float ang = saturate( dot( eyeVec, bumpNorm ) );
|
|
float ang = saturate( dot( eyeVec, bumpNorm ) );
|
|
- float cubeAmt = ang;
|
|
|
|
|
|
+ float fakeColorAmt = ang;
|
|
|
|
|
|
- //float rplaneDist = (reflectPlane.x * IN.pos.x + reflectPlane.y * IN.pos.y + reflectPlane.z * IN.pos.z) + reflectPlane.w;
|
|
|
|
- //rplaneDist = saturate( abs( rplaneDist ) / 0.5 );
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-//#ifdef RIVER
|
|
|
|
// for verts far from the reflect plane z position
|
|
// for verts far from the reflect plane z position
|
|
- float rplaneDist = abs( REFLECT_PLANE_Z - IN.worldPos.z );
|
|
|
|
|
|
+ float rplaneDist = abs( REFLECT_PLANE_Z - IN_objPos.w );
|
|
rplaneDist = saturate( ( rplaneDist - 1.0 ) / 2.0 );
|
|
rplaneDist = saturate( ( rplaneDist - 1.0 ) / 2.0 );
|
|
- //rplaneDist = REFLECT_PLANE_Z / eyePos.z;
|
|
|
|
rplaneDist *= ISRIVER;
|
|
rplaneDist *= ISRIVER;
|
|
- cubeAmt = max( cubeAmt, rplaneDist );
|
|
|
|
-//#endif
|
|
|
|
-
|
|
|
|
- //rplaneDist = IN.worldPos.z / eyePos.z;
|
|
|
|
-
|
|
|
|
- //return vec4( rplaneDist.rrr, 1 );
|
|
|
|
- //return vec4( (reflectParams[REFLECT_PLANE_Z] / 86.0 ).rrr, 1 );
|
|
|
|
-
|
|
|
|
- // and for verts farther from the camera
|
|
|
|
- //float cubeAmt = ( eyeDist - reflectParams[REFLECT_MIN_DIST] ) / ( reflectParams[REFLECT_MAX_DIST] - reflectParams[REFLECT_MIN_DIST] );
|
|
|
|
- //cubeAmt = saturate ( cubeAmt );
|
|
|
|
-
|
|
|
|
- //float temp = ( eyeDist - reflectParams[REFLECT_MIN_DIST] ) / ( reflectParams[REFLECT_MAX_DIST] - reflectParams[REFLECT_MIN_DIST] );
|
|
|
|
- //temp = saturate ( temp );
|
|
|
|
-
|
|
|
|
- // If the camera is very very close to the reflect plane.
|
|
|
|
- //float eyeToPlaneDist = eyePos.z - REFLECT_PLANE_Z; // dot( reflectNormal, eyePos ) + REFLECT_PLANE_Z;
|
|
|
|
- //eyeToPlaneDist = abs( eyeToPlaneDist );
|
|
|
|
- //eyeToPlaneDist = 1.0 - saturate( abs( eyeToPlaneDist ) / 1 );
|
|
|
|
-
|
|
|
|
- //return vec4( eyeToPlaneDist.rrr, 1 );
|
|
|
|
-
|
|
|
|
- //cubeAmt = max( cubeAmt, eyeToPlaneDist );
|
|
|
|
- //cubeAmt = max( cubeAmt, rplaneDist );
|
|
|
|
- //cubeAmt = max( cubeAmt, ang );
|
|
|
|
- //cubeAmt = max( cubeAmt, rplaneDist );
|
|
|
|
- //cubeAmt = max( cubeAmt, IN.depth.w );
|
|
|
|
-
|
|
|
|
- // All cubemap if fullReflect is specifically user disabled
|
|
|
|
- cubeAmt = max( cubeAmt, NO_REFLECT );
|
|
|
|
|
|
+ fakeColorAmt = max( fakeColorAmt, rplaneDist );
|
|
|
|
|
|
#ifndef UNDERWATER
|
|
#ifndef UNDERWATER
|
|
|
|
|
|
-
|
|
|
|
// Get foam color and amount
|
|
// Get foam color and amount
|
|
- IN.foamTexCoords.xy += distortDelta * 0.5;
|
|
|
|
- IN.foamTexCoords.zw += distortDelta * 0.5;
|
|
|
|
|
|
+ vec2 foamRippleOffset = bumpNorm.xy * FOAM_RIPPLE_INFLUENCE;
|
|
|
|
+ vec4 IN_foamTexCoords = IN_foamTexCoords;
|
|
|
|
+ IN_foamTexCoords.xy += foamRippleOffset;
|
|
|
|
+ IN_foamTexCoords.zw += foamRippleOffset;
|
|
|
|
|
|
- vec4 foamColor = tex2D( foamMap, IN.foamTexCoords.xy );
|
|
|
|
- foamColor += tex2D( foamMap, IN.foamTexCoords.zw );
|
|
|
|
- //foamColor += tex2D( foamMap, IN.rippleTexCoord2 ) * 0.3;
|
|
|
|
|
|
+ vec4 foamColor = texture( foamMap, IN_foamTexCoords.xy );
|
|
|
|
+ foamColor += texture( foamMap, IN_foamTexCoords.zw );
|
|
foamColor = saturate( foamColor );
|
|
foamColor = saturate( foamColor );
|
|
- // Modulate foam color by ambient color so we don't have glowing white
|
|
|
|
- // foam at night.
|
|
|
|
- foamColor.rgb = lerp( foamColor.rgb, ambientColor.rgb, foamColorMod.rgb );
|
|
|
|
|
|
+
|
|
|
|
+ // Modulate foam color by ambient color
|
|
|
|
+ // so we don't have glowing white foam at night.
|
|
|
|
+ foamColor.rgb = mix( foamColor.rgb, ambientColor.rgb, FOAM_AMBIENT_LERP );
|
|
|
|
|
|
float foamDelta = saturate( delta / FOAM_MAX_DEPTH );
|
|
float foamDelta = saturate( delta / FOAM_MAX_DEPTH );
|
|
- float foamAmt = 1.0 - foamDelta;
|
|
|
|
|
|
+ float foamAmt = 1 - pow( foamDelta, 2 );
|
|
|
|
|
|
// Fade out the foam in very very low depth,
|
|
// Fade out the foam in very very low depth,
|
|
// this improves the shoreline a lot.
|
|
// this improves the shoreline a lot.
|
|
float diff = 0.8 - foamAmt;
|
|
float diff = 0.8 - foamAmt;
|
|
if ( diff < 0.0 )
|
|
if ( diff < 0.0 )
|
|
- {
|
|
|
|
- //return vec4( 1,0,0,1 );
|
|
|
|
foamAmt -= foamAmt * abs( diff ) / 0.2;
|
|
foamAmt -= foamAmt * abs( diff ) / 0.2;
|
|
- }
|
|
|
|
- //return vec4( foamAmt.rrr, 1 );
|
|
|
|
-
|
|
|
|
- foamAmt *= FOAM_SCALE * foamColor.a;
|
|
|
|
- //return vec4( foamAmt.rrr, 1 );
|
|
|
|
|
|
|
|
- // Get reflection map color
|
|
|
|
- vec4 refMapColor = tex2D( reflectMap, reflectCoord );
|
|
|
|
-
|
|
|
|
- //cubeAmt = 0;
|
|
|
|
|
|
+ foamAmt *= FOAM_OPACITY * foamColor.a;
|
|
|
|
|
|
- // Combine cube and foam colors into reflect color
|
|
|
|
- vec4 reflectColor = lerp( refMapColor, cubeColor, cubeAmt );
|
|
|
|
- //return refMapColor;
|
|
|
|
|
|
+ foamColor.rgb *= FOAM_OPACITY * foamAmt * foamColor.a;
|
|
|
|
|
|
- // This doesn't work because REFLECT_PLANE_Z is in worldSpace
|
|
|
|
- // while eyePos is actually in objectSpace!
|
|
|
|
|
|
+ // Get reflection map color.
|
|
|
|
+ vec4 refMapColor = hdrDecode( texture( reflectMap, reflectCoord ) );
|
|
|
|
|
|
- //float eyeToPlaneDist = eyePos.z - REFLECT_PLANE_Z; // dot( reflectNormal, eyePos ) + REFLECT_PLANE_Z;
|
|
|
|
- //float transitionFactor = 1.0 - saturate( ( abs( eyeToPlaneDist ) - 0.5 ) / 5 );
|
|
|
|
- //reflectColor = lerp( reflectColor, waterBaseColor, transitionFactor );
|
|
|
|
|
|
+ // If we do not have a reflection texture then we use the cubemap.
|
|
|
|
+ refMapColor = mix( refMapColor, texture( skyMap, reflectionVec ), NO_REFLECT );
|
|
|
|
|
|
- //return reflectColor;
|
|
|
|
|
|
+ fakeColor = ( texture( skyMap, reflectionVec ) );
|
|
|
|
+ fakeColor.a = 1;
|
|
|
|
+ // Combine reflection color and fakeColor.
|
|
|
|
+ vec4 reflectColor = mix( refMapColor, fakeColor, fakeColorAmt );
|
|
|
|
|
|
// Get refract color
|
|
// Get refract color
|
|
- vec4 refractColor = tex2D( refractBuff, refractCoord );
|
|
|
|
- //return refractColor;
|
|
|
|
|
|
+ vec4 refractColor = hdrDecode( texture( refractBuff, refractCoord ) );
|
|
|
|
|
|
// We darken the refraction color a bit to make underwater
|
|
// We darken the refraction color a bit to make underwater
|
|
// elements look wet. We fade out this darkening near the
|
|
// elements look wet. We fade out this darkening near the
|
|
@@ -371,86 +315,80 @@ void main()
|
|
|
|
|
|
// Add Water fog/haze.
|
|
// Add Water fog/haze.
|
|
float fogDelta = delta - FOG_DENSITY_OFFSET;
|
|
float fogDelta = delta - FOG_DENSITY_OFFSET;
|
|
- //return vec4( fogDelta.rrr, 1 );
|
|
|
|
|
|
+
|
|
if ( fogDelta < 0.0 )
|
|
if ( fogDelta < 0.0 )
|
|
fogDelta = 0.0;
|
|
fogDelta = 0.0;
|
|
float fogAmt = 1.0 - saturate( exp( -FOG_DENSITY * fogDelta ) );
|
|
float fogAmt = 1.0 - saturate( exp( -FOG_DENSITY * fogDelta ) );
|
|
- //return vec4( fogAmt.rrr, 1 );
|
|
|
|
|
|
+
|
|
|
|
+ // Calculate the water "base" color based on depth.
|
|
|
|
+ vec4 waterBaseColor = baseColor * texture( depthGradMap, saturate( delta / depthGradMax ) );
|
|
|
|
+
|
|
|
|
+ // Modulate baseColor by the ambientColor.
|
|
|
|
+ waterBaseColor *= vec4( ambientColor.rgb, 1 );
|
|
|
|
|
|
// calc "diffuse" color by lerping from the water color
|
|
// calc "diffuse" color by lerping from the water color
|
|
// to refraction image based on the water clarity.
|
|
// to refraction image based on the water clarity.
|
|
- vec4 diffuseColor = lerp( refractColor, waterBaseColor, fogAmt );
|
|
|
|
|
|
+ vec4 diffuseColor = mix( refractColor, waterBaseColor, fogAmt );
|
|
|
|
|
|
// fresnel calculation
|
|
// fresnel calculation
|
|
float fresnelTerm = fresnel( ang, FRESNEL_BIAS, FRESNEL_POWER );
|
|
float fresnelTerm = fresnel( ang, FRESNEL_BIAS, FRESNEL_POWER );
|
|
- //return vec4( fresnelTerm.rrr, 1 );
|
|
|
|
|
|
|
|
// Scale the frensel strength by fog amount
|
|
// Scale the frensel strength by fog amount
|
|
// so that parts that are very clear get very little reflection.
|
|
// so that parts that are very clear get very little reflection.
|
|
fresnelTerm *= fogAmt;
|
|
fresnelTerm *= fogAmt;
|
|
- //return vec4( fresnelTerm.rrr, 1 );
|
|
|
|
|
|
|
|
// Also scale the frensel by our distance to the
|
|
// Also scale the frensel by our distance to the
|
|
// water surface. This removes the hard reflection
|
|
// water surface. This removes the hard reflection
|
|
// when really close to the water surface.
|
|
// when really close to the water surface.
|
|
- fresnelTerm *= saturate( IN.pixelDist - 0.1 );
|
|
|
|
|
|
+ fresnelTerm *= saturate( PIXEL_DIST - 0.1 );
|
|
|
|
+
|
|
|
|
+ fresnelTerm *= reflectivity;
|
|
|
|
|
|
// Combine the diffuse color and reflection image via the
|
|
// Combine the diffuse color and reflection image via the
|
|
// fresnel term and set out output color.
|
|
// fresnel term and set out output color.
|
|
- vec4 gl_FragColor = lerp( diffuseColor, reflectColor, fresnelTerm );
|
|
|
|
|
|
+ vec4 OUT = mix( diffuseColor, reflectColor, fresnelTerm );
|
|
|
|
+
|
|
|
|
+ vec3 lightVec = inLightVec;
|
|
|
|
|
|
- //float brightness = saturate( 1.0 - ( waterHeight - eyePosWorld.z - 5.0 ) / 50.0 );
|
|
|
|
- //gl_FragColor.rgb *= brightness;
|
|
|
|
|
|
+ // Get some specular reflection.
|
|
|
|
+ vec3 newbump = bumpNorm;
|
|
|
|
+ newbump.xy *= 3.5;
|
|
|
|
+ newbump = normalize( bumpNorm );
|
|
|
|
+ vec3 halfAng = normalize( eyeVec + -lightVec );
|
|
|
|
+ float specular = saturate( dot( newbump, halfAng ) );
|
|
|
|
+ specular = pow( specular, SPEC_POWER );
|
|
|
|
+
|
|
|
|
+ // Scale down specularity in very shallow water to improve the transparency of the shoreline.
|
|
|
|
+ specular *= saturate( delta / 2 );
|
|
|
|
+ OUT.rgb = OUT.rgb + ( SPEC_COLOR * vec3(specular) );
|
|
|
|
|
|
#else
|
|
#else
|
|
- vec4 refractColor = tex2D( refractBuff, refractCoord );
|
|
|
|
- vec4 gl_FragColor = refractColor;
|
|
|
|
|
|
+
|
|
|
|
+ vec4 refractColor = hdrDecode( texture( refractBuff, refractCoord ) );
|
|
|
|
+ vec4 OUT = refractColor;
|
|
|
|
+
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#ifndef UNDERWATER
|
|
#ifndef UNDERWATER
|
|
- gl_FragColor.rgb = lerp( gl_FragColor.rgb, foamColor.rgb, foamAmt );
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
- gl_FragColor.a = 1.0;
|
|
|
|
-
|
|
|
|
- // specular experiments
|
|
|
|
-
|
|
|
|
-// 1:
|
|
|
|
-/*
|
|
|
|
- float fDot = dot( bumpNorm, inLightVec );
|
|
|
|
- vec3 reflect = normalize( 2.0 * bumpNorm * fDot - eyeVec );
|
|
|
|
- // float specular = saturate(dot( reflect, inLightVec ) );
|
|
|
|
- float specular = pow( reflect, specularPower );
|
|
|
|
- gl_FragColor += specularColor * specular;
|
|
|
|
-*/
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// 2: This almost looks good
|
|
|
|
-/*
|
|
|
|
- bumpNorm.xy *= 2.0;
|
|
|
|
- bumpNorm = normalize( bumpNorm );
|
|
|
|
-
|
|
|
|
- vec3 halfAng = normalize( eyeVec + inLightVec );
|
|
|
|
- float specular = saturate( dot( bumpNorm, halfAng) );
|
|
|
|
- specular = pow(specular, specularPower);
|
|
|
|
- gl_FragColor += specularColor * specular;
|
|
|
|
-*/
|
|
|
|
-
|
|
|
|
-#ifndef UNDERWATER
|
|
|
|
|
|
+ OUT.rgb = OUT.rgb + foamColor.rgb;
|
|
|
|
|
|
float factor = computeSceneFog( eyePos,
|
|
float factor = computeSceneFog( eyePos,
|
|
- IN.fogPos,
|
|
|
|
- IN.worldSpaceZ,
|
|
|
|
|
|
+ IN_objPos.xyz,
|
|
|
|
+ IN_objPos.w,
|
|
fogData.x,
|
|
fogData.x,
|
|
fogData.y,
|
|
fogData.y,
|
|
fogData.z );
|
|
fogData.z );
|
|
|
|
|
|
- gl_FragColor.rgb = lerp( gl_FragColor.rgb, fogColor.rgb, 1.0 - saturate( factor ) );
|
|
|
|
|
|
+ OUT.rgb = mix( OUT.rgb, fogColor.rgb, 1.0 - saturate( factor ) );
|
|
|
|
+
|
|
|
|
+ //OUT.rgb = fogColor.rgb;
|
|
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|
|
- //return vec4( refMapColor.rgb, 1 );
|
|
|
|
- gl_FragColor.a = 1.0;
|
|
|
|
|
|
+ OUT.a = 1.0;
|
|
|
|
+
|
|
|
|
+ //return OUT;
|
|
|
|
|
|
- return gl_FragColor;
|
|
|
|
|
|
+ OUT_FragColor0 = hdrEncode( OUT );
|
|
}
|
|
}
|