fix water shader

experimental
Miloslav Číž 7 years ago
parent 658fa0fdae
commit 8df79625e8

@ -112,7 +112,7 @@ class ClipCullNode : public osg::Group
}
// move the plane back along its normal a little bit to prevent bleeding at the water shore
const float clipFudge = -5;
const float clipFudge = -6;
modelViewMatrix->preMultTranslate(mCullPlane->getNormal() * clipFudge);
cv->pushModelViewMatrix(modelViewMatrix, osg::Transform::RELATIVE_RF);

@ -76,7 +76,7 @@ uniform float near;
uniform float far;
uniform vec3 nodePosition;
float transformDepth(float depth) // helper for transforming refraction depth
float transformDepth(float depth) // helper for transforming water depth
{
float z_n = 2.0 * depth - 1.0;
depth = 2.0 * near * far / (far + near - z_n * (far - near));
@ -156,27 +156,30 @@ void main(void)
fresnel = clamp(fresnel, 0.0, 1.0);
#if REFRACTION
float realWaterDepth = transformDepth(texture2D(refractionDepthMap, screenCoords).x);
float shore = clamp(realWaterDepth / REFLECTION_BUMP_SUPPRESS_DEPTH,0,1);
#else
float shore = 1.0;
#endif
// reflection
vec3 reflection = texture2D(reflectionMap, screenCoords+(normal.xy*REFL_BUMP*shore)).rgb;
// refraction
#if REFRACTION
vec3 refraction = texture2D(refractionMap, screenCoords-(normal.xy*REFR_BUMP)).rgb;
vec3 refraction = texture2D(refractionMap, screenCoords-(normal.xy*REFR_BUMP*shore)).rgb;
// brighten up the refraction underwater
refraction = (cameraPos.z < 0.0) ? clamp(refraction * 1.5, 0.0, 1.0) : refraction;
#endif
// specular
vec3 R = reflect(vVec, normal);
float specular = pow(max(dot(R, lVec), 0.0),SPEC_HARDNESS) * shadow;
vec3 waterColor = WATER_COLOR;
waterColor = waterColor * length(gl_LightModel.ambient.xyz);
#if REFRACTION
float refractionDepth = transformDepth(texture2D(refractionDepthMap, screenCoords-(normal.xy*REFR_BUMP)).x);
float waterDepth = refractionDepth - depthPassthrough;

Loading…
Cancel
Save