I’m getting dancing pixels near polygon borders with mipmapping on the following terrain fragment shader:
uniform sampler2D texture0; // color texture
uniform sampler2D texture1; // mixmap texture
uniform sampler2D texture2; // detail texture 1
uniform sampler2D texture3; // detail texture 2
uniform sampler2D texture4; // detail texture 3
uniform sampler2D texture5; // detail texture 4
varying vec2 uv0;
varying vec2 uv1;
varying vec2 uv2;
void main()
{
vec4 color;
vec4 mixmap;
vec4 detail;
vec4 dc; // detail texture color
float da; // detail mixing alpha
// get color
color = texture2D(texture0, uv0);
// get mixmap
mixmap = texture2D(texture1, uv2);
// detail 1
if (mixmap.r > 0.0) {
detail.rgb = texture2D(texture2, uv1);
}
// detail 2
if (mixmap.g > 0.0) {
dc = texture2D(texture3, uv1);
da = clamp( (mixmap.g - (dc.a*0.75)) * 4 ,0.0,1.0);
detail.rgb = mix(detail.rgb,dc.rgb,da);
}
// detail 3
if (mixmap.b) { // !!comment out to fix!!
dc = texture2D(texture4, uv1);
da = clamp( (mixmap.b - (dc.a*0.75)) * 4 ,0.0,1.0);
detail.rgb = mix(detail.rgb,dc.rgb,da);
} // !!comment out to fix!!
// detail 4
if (mixmap.a > 0.0) { // !!comment out to fix!!
dc = texture2D(texture5, uv1);
da = clamp( (mixmap.a - (dc.a*0.75)) * 4 ,0.0,1.0);
detail.rgb = mix(detail.rgb,dc.rgb,da);
} // !!comment out to fix!!
// mix color with detail
color.rgb = (color.rgb) + (detail.rgb - 0.5);
// apply fog
float fog;
fog = (gl_Fog.end - gl_FogFragCoord) * gl_Fog.scale;
fog = clamp(fog, 0.0, 1.0);
color.rgb = mix(gl_Fog.color.rgb, color.rgb, fog);
gl_FragColor = color;
}
Result (animated GIF):
Pixels jitter, even when the viewpoint is not moving, it is not texture aliasing.
WinXP SP2
H/W: 8800GT
Driver: 169.21 / 174.74 Beta
Changing bi/tri-linear/anisotropic filter, FSAA, various driver optimizations has no effect.
Commenting out the if-clauses fixes the problem, but wastes an unneeded texture fetch in most situations. Note that the first if-clause (detail 1 and detail 2) don’t cause any problems.
This isn’t the first time I have reported a bug with if-clauses. I guess if-clauses are a bit to advanced for the nVidia GLSL compiler?
Any workarounds?