1
0
forked from 0ad/0ad

Actually fix bugs on ATI cards. Switch reflection and refractions to use POT textures in an attempt to improve compatibility.

This was SVN commit r15598.
This commit is contained in:
wraitii 2014-08-02 12:54:45 +00:00
parent 608c27fe10
commit 4028cd425e
3 changed files with 43 additions and 27 deletions

View File

@ -28,6 +28,11 @@ varying vec3 worldPos;
varying float waterDepth;
varying vec2 waterInfo;
varying vec4 normalCoords;
varying vec3 reflectionCoords;
varying vec3 refractionCoords;
varying vec2 losCoords;
varying float fwaviness;
uniform float mapSize;
@ -153,16 +158,16 @@ void main()
// This method uses 60 animated water frames. We're blending between each two frames
// TODO: could probably have fewer frames thanks to this blending.
// Scale the normal textures by waviness so that big waviness means bigger waves.
vec3 ww1 = texture2D(normalMap, (gl_TexCoord[0].st + gl_TexCoord[0].zw * BigMovement*waviness/10.0) * (baseScale - waviness/wavyEffect)).xzy;
vec3 ww2 = texture2D(normalMap2, (gl_TexCoord[0].st + gl_TexCoord[0].zw * BigMovement*waviness/10.0) * (baseScale - waviness/wavyEffect)).xzy;
vec3 ww1 = texture2D(normalMap, (normalCoords.st + normalCoords.zw * BigMovement*waviness/10.0) * (baseScale - waviness/wavyEffect)).xzy;
vec3 ww2 = texture2D(normalMap2, (normalCoords.st + normalCoords.zw * BigMovement*waviness/10.0) * (baseScale - waviness/wavyEffect)).xzy;
vec3 wwInterp = mix(ww1, ww2, moddedTime) - vec3(0.5,0.0,0.5);
ww1.x = wwInterp.x * WindCosSin.x - wwInterp.z * WindCosSin.y;
ww1.z = wwInterp.x * WindCosSin.y + wwInterp.z * WindCosSin.x;
ww1.y = wwInterp.y;
vec3 smallWW = texture2D(normalMap, (gl_TexCoord[0].st + gl_TexCoord[0].zw * SmallMovement*waviness/10.0) * baseScale*3.0).xzy;
vec3 smallWW2 = texture2D(normalMap2, (gl_TexCoord[0].st + gl_TexCoord[0].zw * SmallMovement*waviness/10.0) * baseScale*3.0).xzy;
vec3 smallWW = texture2D(normalMap, (normalCoords.st + normalCoords.zw * SmallMovement*waviness/10.0) * baseScale*3.0).xzy;
vec3 smallWW2 = texture2D(normalMap2, (normalCoords.st + normalCoords.zw * SmallMovement*waviness/10.0) * baseScale*3.0).xzy;
vec3 smallWWInterp = mix(smallWW, smallWW2, moddedTime) - vec3(0.5,0.0,0.5);
smallWW.x = smallWWInterp.x * WindCosSin.x - smallWWInterp.z * WindCosSin.y;
@ -258,11 +263,11 @@ void main()
float murky = mix(200.0,0.1,pow(murkiness,0.25));
#if USE_REFRACTION
refrCoords = clamp( (0.5*gl_TexCoord[2].xy - n.xz * distoFactor*7.0) / gl_TexCoord[2].z + 0.5,0.0,1.0); // Unbias texture coords
refrCoords = clamp( (0.5*refractionCoords.xy - n.xz * distoFactor*7.0) / refractionCoords.z + 0.5,0.0,1.0); // Unbias texture coords
vec3 refColor = texture2D(refractionMap, refrCoords).rgb;
if (refColor.r > refColor.g + refColor.b + 0.25)
{
refrCoords = clamp( (0.5*gl_TexCoord[2].xy + n.xz) / gl_TexCoord[2].z + 0.5,0.0,1.0); // Unbias texture coords
refrCoords = clamp( (0.5*refractionCoords.xy + n.xz) / refractionCoords.z + 0.5,0.0,1.0); // Unbias texture coords
refColor = texture2D(refractionMap, refrCoords).rgb;
}
@ -308,15 +313,15 @@ void main()
//gl_FragColor = vec4(clamp(disttt/300.0*disttt/300.0,0.0,1.0),clamp(disttt/300.0*disttt/300.0,0.0,1.0),clamp(disttt/300.0*disttt/300.0,0.0,1.0),1.0);
//return;
reflCoords = clamp( (0.5*gl_TexCoord[1].xy - waviness * mix(1.0, 4.0,waviness/10.0) * n.zx) / gl_TexCoord[1].z + 0.5,0.0,1.0); // Unbias texture coords
reflCoords = clamp( (0.5*reflectionCoords.xy - waviness * mix(1.0, 4.0,waviness/10.0) * n.zx) / reflectionCoords.z + 0.5,0.0,1.0); // Unbias texture coords
vec4 refTex = texture2D(reflectionMap, reflCoords);
reflColor = refTex.rgb * refTex.a + reflColor*(1.0-refTex.a);
#else
// Temp fix for some ATI cards (see irc logs on th 1st of august betwee, fexor and wraitii)
//reflCoords = clamp( (0.5*gl_TexCoord[1].xy - waviness * mix(1.0, 20.0,waviness/10.0) * n.zx) / gl_TexCoord[1].z + 0.5,0.0,1.0); // Unbias texture coords
//reflCoords = clamp( (0.5*reflectionCoords.xy - waviness * mix(1.0, 20.0,waviness/10.0) * n.zx) / reflectionCoords.z + 0.5,0.0,1.0); // Unbias texture coords
//vec3 refTex = texture2D(reflectionMap, reflCoords).rgb;
//reflColor = refTex.rgb;
reflColor = vec3(0.15, 0.7, 0.92);
reflColor = vec3(0.15, 0.7, 0.82);
#endif
// TODO: At very low angles the reflection stuff doesn't really work any more:
@ -332,7 +337,7 @@ void main()
// Specular.
specular = pow(ndoth, mix(5.0,2000.0, clamp(v.y*v.y*2.0,0.0,1.0)))*sunColor * 1.5;// * sunColor * 1.5 * ww.r;
losMod = texture2D(losMap, gl_TexCoord[3].st).a;
losMod = texture2D(losMap, losCoords.st).a;
losMod = losMod < 0.03 ? 0.0 : losMod;
float wavesFresnel = 1.0;
@ -358,10 +363,10 @@ void main()
#if USE_FANCY_EFFECTS
vec4 FoamEffects = texture2D(waterEffectsTexOther, gl_FragCoord.xy/screenSize);
vec3 foam1 = texture2D(normalMap, (gl_TexCoord[0].st + gl_TexCoord[0].zw * BigMovement*waviness/10.0) * (baseScale - waviness/wavyEffect)).aaa;
vec3 foam2 = texture2D(normalMap2, (gl_TexCoord[0].st + gl_TexCoord[0].zw * BigMovement*waviness/10.0) * (baseScale - waviness/wavyEffect)).aaa;
vec3 foam3 = texture2D(normalMap, gl_TexCoord[0].st/6.0 - gl_TexCoord[0].zw * 0.02).aaa;
vec3 foam4 = texture2D(normalMap2, gl_TexCoord[0].st/6.0 - gl_TexCoord[0].zw * 0.02).aaa;
vec3 foam1 = texture2D(normalMap, (normalCoords.st + normalCoords.zw * BigMovement*waviness/10.0) * (baseScale - waviness/wavyEffect)).aaa;
vec3 foam2 = texture2D(normalMap2, (normalCoords.st + normalCoords.zw * BigMovement*waviness/10.0) * (baseScale - waviness/wavyEffect)).aaa;
vec3 foam3 = texture2D(normalMap, normalCoords.st/6.0 - normalCoords.zw * 0.02).aaa;
vec3 foam4 = texture2D(normalMap2, normalCoords.st/6.0 - normalCoords.zw * 0.02).aaa;
vec3 foaminterp = mix(foam1, foam2, moddedTime);
foaminterp *= mix(foam3, foam4, moddedTime);

View File

@ -22,6 +22,11 @@ varying vec3 worldPos;
varying float waterDepth;
varying vec2 waterInfo;
varying vec4 normalCoords;
varying vec3 reflectionCoords;
varying vec3 refractionCoords;
varying vec2 losCoords;
varying float fwaviness;
varying vec2 WindCosSin;
@ -44,11 +49,11 @@ void main()
float newX = a_vertex.x * WindCosSin.x - a_vertex.z * WindCosSin.y;
float newY = a_vertex.x * WindCosSin.y + a_vertex.z * WindCosSin.x;
gl_TexCoord[0] = vec4(newX,newY,time,0.0);
gl_TexCoord[0].xy *= repeatScale;
gl_TexCoord[1].rgb = (reflectionMatrix * vec4(a_vertex, 1.0)).rga; // projective texturing
gl_TexCoord[2].rgb = (refractionMatrix * vec4(a_vertex, 1.0)).rga;
gl_TexCoord[3].rg = (losMatrix * vec4(a_vertex, 1.0)).rg;
normalCoords = vec4(newX,newY,time,0.0);
normalCoords.xy *= repeatScale;
reflectionCoords = (reflectionMatrix * vec4(a_vertex, 1.0)).rga; // projective texturing
refractionCoords = (refractionMatrix * vec4(a_vertex, 1.0)).rga;
losCoords = (losMatrix * vec4(a_vertex, 1.0)).rg;
#if USE_SHADOW && USE_SHADOWS_ON_WATER
v_shadow = shadowTransform * vec4(a_vertex, 1.0);

View File

@ -214,27 +214,33 @@ int WaterManager::LoadWaterTextures()
m_ReflectionTextureSize = g_Renderer.GetHeight() * 0.66; // Higher settings give a better result
m_RefractionTextureSize = g_Renderer.GetHeight() * 0.33; // Lower settings actually sorta look better since it blurs.
if (round_down_to_pow2(m_ReflectionTextureSize)/m_ReflectionTextureSize < 0.65)
m_ReflectionTextureSize = round_up_to_pow2(m_ReflectionTextureSize);
else
m_ReflectionTextureSize = round_down_to_pow2(m_ReflectionTextureSize);
if (round_down_to_pow2(m_RefractionTextureSize)/m_RefractionTextureSize < 0.7)
m_RefractionTextureSize = round_up_to_pow2(m_RefractionTextureSize);
else
m_RefractionTextureSize = round_down_to_pow2(m_RefractionTextureSize);
// Create reflection texture
glGenTextures(1, &m_ReflectionTexture);
glBindTexture(GL_TEXTURE_2D, m_ReflectionTexture);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
(GLsizei)m_ReflectionTextureSize, (GLsizei)m_ReflectionTextureSize,
0, GL_RGB, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, (GLsizei)m_ReflectionTextureSize, (GLsizei)m_ReflectionTextureSize, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
// Create refraction texture
glGenTextures(1, &m_RefractionTexture);
glBindTexture(GL_TEXTURE_2D, m_RefractionTexture);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB,
(GLsizei)m_RefractionTextureSize, (GLsizei)m_RefractionTextureSize,
0, GL_RGB, GL_UNSIGNED_BYTE, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, (GLsizei)m_RefractionTextureSize, (GLsizei)m_RefractionTextureSize, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
// Create depth textures
glGenTextures(1, &m_ReflFboDepthTexture);
@ -243,7 +249,7 @@ int WaterManager::LoadWaterTextures()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, (GLsizei)m_ReflectionTextureSize, (GLsizei)m_ReflectionTextureSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, (GLsizei)m_ReflectionTextureSize, (GLsizei)m_ReflectionTextureSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL);
glGenTextures(1, &m_RefrFboDepthTexture);
glBindTexture(GL_TEXTURE_2D, m_RefrFboDepthTexture);
@ -251,7 +257,7 @@ int WaterManager::LoadWaterTextures()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, (GLsizei)m_RefractionTextureSize, (GLsizei)m_RefractionTextureSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL);
glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, (GLsizei)m_RefractionTextureSize, (GLsizei)m_RefractionTextureSize, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL);
// Create the Fancy Effects texture
glGenTextures(1, &m_FancyTextureNormal);