Jump to content
  • Advertisement
Sign in to follow this  

Peculiar Banding Normal Mapping

This topic is 3555 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've got a strange problem normal mapping. For the most part, the mapping looks fine, but there is a strange bright band that sometimes appears--more with some maps than others. Especially with low intensity normal maps, the band becomes a serious issue. I think the problem lies in the shader code, which is a Frankenstein of shaders I found, assembled naively by me. Here's a screenshot of a particularly nasty banding pattern (normally, it's not this bad): Normal Map Failure Here's the vertex shader (glsl):
varying vec3 lightVec; 
varying vec3 eyeVec;
varying vec2 texCoord;
attribute vec3 vTangent; 

void main(void)
    gl_Position = ftransform();
    texCoord = gl_MultiTexCoord0.xy;

    vec3 c1 = cross(gl_Normal, vec3(0.0, 0.0, 1.0)); 
    vec3 c2 = cross(gl_Normal, vec3(0.0, 1.0, 0.0)); 
        vTangent = c1;
        vTangent = c2;
    vTangent = normalize(vTangent);

    vec3 n = normalize(gl_NormalMatrix * gl_Normal);
    vec3 t = normalize(gl_NormalMatrix * vTangent);
    vec3 b = cross(n, t);

    vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);
    vec3 tmpVec = gl_LightSource[0].position.xyz - vVertex;

    lightVec.x = dot(tmpVec, t);
    lightVec.y = dot(tmpVec, b);
    lightVec.z = dot(tmpVec, n);

    tmpVec = -vVertex;
    eyeVec.x = dot(tmpVec, t);
    eyeVec.y = dot(tmpVec, b);
    eyeVec.z = dot(tmpVec, n);

and here is the fragment shader:
varying vec3 lightVec;
varying vec3 eyeVec;
varying vec2 texCoord;
uniform sampler2D normalMap;
uniform float invRadius;

void main (void)
	float distSqr = dot(lightVec, lightVec);
	float att = clamp(1.0 - invRadius * sqrt(distSqr), 0.0, 1.0);
        att = 1.0;
	vec3 lVec = lightVec * inversesqrt(distSqr);

	vec3 vVec = normalize(eyeVec);
	vec3 bump = normalize( texture2D(normalMap, texCoord).xyz * 2.0 - 1.0);

	vec4 vAmbient = gl_LightSource[0].ambient * gl_FrontMaterial.ambient;

	float diffuse = max( dot(lVec, bump), 0.0 );
	vec4 vDiffuse = gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * diffuse;	

	float specular = pow(clamp(dot(reflect(-lVec, bump), vVec), 0.0, 1.0), gl_FrontMaterial.shininess );
	vec4 vSpecular = gl_LightSource[0].specular * gl_FrontMaterial.specular * specular;	
	gl_FragColor = ( vAmbient + vDiffuse + vSpecular) * att;

I really need this problem fixed. Can anyone give me any pointers or help on the matter? Thanks, Geometrian

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!