Do not send Reflection and Refraction matrices to shader when not needed
Patch By: Angen Reviewed By: wraitii Differential Revision: https://code.wildfiregames.com/D1954 This was SVN commit r22971.
This commit is contained in:
parent
077c4f2576
commit
987b36d53c
@ -32,8 +32,12 @@ varying vec2 waterInfo;
|
||||
varying vec3 v;
|
||||
|
||||
varying vec4 normalCoords;
|
||||
#if USE_REFLECTION
|
||||
varying vec3 reflectionCoords;
|
||||
#endif
|
||||
#if USE_REFRACTION
|
||||
varying vec3 refractionCoords;
|
||||
#endif
|
||||
varying vec2 losCoords;
|
||||
|
||||
varying float fwaviness;
|
||||
@ -53,7 +57,9 @@ uniform sampler2D normalMap2;
|
||||
uniform vec4 waveParams1; // wavyEffect, BaseScale, Flattenism, Basebump
|
||||
uniform vec4 waveParams2; // Smallintensity, Smallbase, Bigmovement, Smallmovement
|
||||
|
||||
uniform sampler2D reflectionMap;
|
||||
#if USE_REFLECTION
|
||||
uniform sampler2D reflectionMap;
|
||||
#endif
|
||||
|
||||
#if USE_REFRACTION
|
||||
uniform sampler2D refractionMap;
|
||||
@ -157,13 +163,13 @@ void main()
|
||||
// Flatten them based on waviness.
|
||||
vec3 n = normalize(mix(vec3(0.0, 1.0, 0.0), ww1, clamp(baseBump + fwaviness / flattenism, 0.0, 1.0)));
|
||||
|
||||
#if USE_FANCY_EFFECTS
|
||||
vec4 fancyeffects = texture2D(waterEffectsTexNorm, gl_FragCoord.xy / screenSize);
|
||||
n = mix(vec3(0.0, 1.0, 0.0), n, 0.5 + waterInfo.r / 2.0);
|
||||
n.xz = mix(n.xz, fancyeffects.rb, fancyeffects.a / 2.0);
|
||||
#else
|
||||
n = mix(vec3(0.0, 1.0, 0.0), n, 0.5 + waterInfo.r / 2.0);
|
||||
#endif
|
||||
#if USE_FANCY_EFFECTS
|
||||
vec4 fancyeffects = texture2D(waterEffectsTexNorm, gl_FragCoord.xy / screenSize);
|
||||
n = mix(vec3(0.0, 1.0, 0.0), n, 0.5 + waterInfo.r / 2.0);
|
||||
n.xz = mix(n.xz, fancyeffects.rb, fancyeffects.a / 2.0);
|
||||
#else
|
||||
n = mix(vec3(0.0, 1.0, 0.0), n, 0.5 + waterInfo.r / 2.0);
|
||||
#endif
|
||||
|
||||
n = vec3(-n.x, n.y, -n.z); // The final wave normal vector.
|
||||
|
||||
@ -213,7 +219,6 @@ void main()
|
||||
depth = waterDepth / (min(0.5, v.y) * 1.5 * min(0.5, v.y) * 2.0);
|
||||
#endif
|
||||
|
||||
|
||||
#if USE_REFRACTION
|
||||
// for refraction we want to distort more as depth goes down.
|
||||
// 1) compute a distortion based on depth at the pixel.
|
||||
@ -266,26 +271,19 @@ void main()
|
||||
float blurFactor = (distoFactor / 7.0);
|
||||
refColor = (refColor + blurColor.rgb * blurFactor) / (1.0 + blurFactor);
|
||||
|
||||
// Apply water tint and murk color.
|
||||
float extFact = max(0.0, 1.0 - (depth * fixedVy / murky));
|
||||
float ColextFact = max(0.0, 1.0 - (depth * fixedVy / murky));
|
||||
vec3 colll = mix(refColor * tint, refColor, ColextFact);
|
||||
|
||||
|
||||
refrColor = mix(color, colll, extFact);
|
||||
#else
|
||||
#else // !USE_REFRACTION
|
||||
|
||||
#if USE_FANCY_EFFECTS
|
||||
depth = max(depth, fancyeffects.a);
|
||||
#endif
|
||||
vec3 refColor = color;
|
||||
#endif
|
||||
|
||||
// Apply water tint and murk color only.
|
||||
// Apply water tint and murk color.
|
||||
float extFact = max(0.0, 1.0 - (depth * fixedVy / murky));
|
||||
float ColextFact = max(0.0, 1.0 - (depth * fixedVy / murky));
|
||||
vec3 colll = mix(color * tint, color, ColextFact);
|
||||
|
||||
vec3 colll = mix(refColor * tint, refColor, ColextFact);
|
||||
refrColor = mix(color, colll, extFact);
|
||||
#endif
|
||||
|
||||
// Reflections
|
||||
// 3 level of settings:
|
||||
@ -318,7 +316,7 @@ void main()
|
||||
reflColor = textureCube(skyCube, (vec4(eye, 0.0) * skyBoxRot).xyz).rgb;
|
||||
#endif
|
||||
|
||||
#else
|
||||
#else // !USE_REFLECTION && !USE_REFRACTION
|
||||
// Simplest case for reflection, return a gradient of blue based on Y component.
|
||||
reflColor = mix(vec3(0.76, 0.84, 0.92), vec3(0.24, 0.43, 0.71), -eye.y);
|
||||
#endif
|
||||
|
@ -29,8 +29,12 @@ varying vec2 waterInfo;
|
||||
varying vec3 v;
|
||||
|
||||
varying vec4 normalCoords;
|
||||
#if USE_REFLECTION
|
||||
varying vec3 reflectionCoords;
|
||||
#endif
|
||||
#if USE_REFRACTION
|
||||
varying vec3 refractionCoords;
|
||||
#endif
|
||||
varying vec2 losCoords;
|
||||
|
||||
varying float fwaviness;
|
||||
@ -58,8 +62,12 @@ void main()
|
||||
normalCoords = vec4(newX, newY, time, 0.0);
|
||||
normalCoords.xy *= repeatScale;
|
||||
// Projective texturing
|
||||
#if USE_REFLECTION
|
||||
reflectionCoords = (reflectionMatrix * vec4(a_vertex, 1.0)).rga;
|
||||
#endif
|
||||
#if USE_REFRACTION
|
||||
refractionCoords = (refractionMatrix * vec4(a_vertex, 1.0)).rga;
|
||||
#endif
|
||||
losCoords = (losMatrix * vec4(a_vertex, 1.0)).rg;
|
||||
|
||||
#if USE_SHADOW && USE_SHADOWS_ON_WATER
|
||||
|
@ -757,8 +757,8 @@ bool TerrainRenderer::RenderFancyWater(const CShaderDefines& context, int cullGr
|
||||
|
||||
if (WaterMgr->m_WaterRefraction)
|
||||
m->fancyWaterShader->BindTexture(str_refractionMap, WaterMgr->m_RefractionTexture);
|
||||
|
||||
m->fancyWaterShader->BindTexture(str_reflectionMap, WaterMgr->m_ReflectionTexture);
|
||||
if (WaterMgr->m_WaterReflection)
|
||||
m->fancyWaterShader->BindTexture(str_reflectionMap, WaterMgr->m_ReflectionTexture);
|
||||
m->fancyWaterShader->BindTexture(str_losMap, losTexture.GetTextureSmooth());
|
||||
|
||||
const CLightEnv& lightEnv = g_Renderer.GetLightEnv();
|
||||
@ -774,6 +774,11 @@ bool TerrainRenderer::RenderFancyWater(const CShaderDefines& context, int cullGr
|
||||
skyBoxRotation.SetIdentity();
|
||||
skyBoxRotation.RotateY(M_PI + lightEnv.GetRotation());
|
||||
m->fancyWaterShader->Uniform(str_skyBoxRot, skyBoxRotation);
|
||||
|
||||
if (WaterMgr->m_WaterRefraction)
|
||||
m->fancyWaterShader->Uniform(str_refractionMatrix, WaterMgr->m_RefractionMatrix);
|
||||
if (WaterMgr->m_WaterReflection)
|
||||
m->fancyWaterShader->Uniform(str_reflectionMatrix, WaterMgr->m_ReflectionMatrix);
|
||||
}
|
||||
m->fancyWaterShader->Uniform(str_sunDir, lightEnv.GetSunDir());
|
||||
m->fancyWaterShader->Uniform(str_sunColor, lightEnv.m_SunColor);
|
||||
@ -783,8 +788,6 @@ bool TerrainRenderer::RenderFancyWater(const CShaderDefines& context, int cullGr
|
||||
m->fancyWaterShader->Uniform(str_murkiness, WaterMgr->m_Murkiness);
|
||||
m->fancyWaterShader->Uniform(str_windAngle, WaterMgr->m_WindAngle);
|
||||
m->fancyWaterShader->Uniform(str_repeatScale, 1.0f / repeatPeriod);
|
||||
m->fancyWaterShader->Uniform(str_reflectionMatrix, WaterMgr->m_ReflectionMatrix);
|
||||
m->fancyWaterShader->Uniform(str_refractionMatrix, WaterMgr->m_RefractionMatrix);
|
||||
m->fancyWaterShader->Uniform(str_losMatrix, losTexture.GetTextureMatrix());
|
||||
m->fancyWaterShader->Uniform(str_cameraPos, camPos);
|
||||
m->fancyWaterShader->Uniform(str_fogColor, lightEnv.m_FogColor);
|
||||
|
Loading…
Reference in New Issue
Block a user