Texture filtering on normal and specular maps

Started by
9 comments, last by newObjekt 11 years ago

Hey, I have a quick question about my normal and specular maps causing really bad texture artifacts at a distance.

Here's some pictures of the problem. (ignore the weird blue lights, was messing with glow lights in my shader)

http://inferno.codebrainshideout.net/Images/hangemhigh%201.png

http://inferno.codebrainshideout.net/Images/hangemhigh%202.png

Should I look into anti aliasing or anistropic filtering? Or do I need to filter the maps in my glsl shader?


Here is my GLSL fragment shader as well, it's a mess right now, I know :P

http://inferno.codebrainshideout.net/modelShader.frag

Relevant code is inside of the if(useNormal) { }

Thanks : )

Advertisement

For starters, it looks like you are just simply using bilinear filtering for those texture maps. Before you can use anisotropic filtering, you got to have trilinear filtering enabled (which is mipmapping). Are you creating mipmaps for your normal and specular maps? Do that first, then use anisotropic filtering. Antialiasing isn't going to help with this.

I wrote an example on how to use anisotropic filtering, but that HDD crapped out and I might have lost it for good =(

Shogun.

You should definitely mipmap, use trilinear filtering, but in addition to that you should renormalize the normal map lookup result before putting it into your lighting calculation.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Yeah it looks simply like you're not using mipmapping, so when the texture is shrunk by more than 2x, bilinear filtering (which blends 4 texels) won't be able to stop it from shimmering.

Yeah I'm not. I'll research that tonight. Thanks for pointing me in the right direction.

Alright I've got mipmap generation and Anistrophic filtering working and it's given very nice results.

http://inferno.codebrainshideout.net/Images/mipmaps%20a.png

Though I've noticed an odd issue. At extreme angles textures seem to turn completely black. I think this might be a specular problem? I'm not sure.

http://inferno.codebrainshideout.net/Images/mipmaps%20b.png - Wall at a normal angle.

http://inferno.codebrainshideout.net/Images/mipmaps%20c.png - Wall at a extreme angle.

Additionally I don't know what mhagain meant by "renormalize" the normal maps. Is that the same as calculating the tangent and binormal and applying those to the normal map?

-edit-

It's not a specular problem. It's a problem the tangent and binormals I think. I disabled normal maps but left specular maps enabled and the black faces effect was gone. But I noticed that the specularity was completely gone at the angles that caused the black faces.

Up to date frag and vert shaders:

http://inferno.codebrainshideout.net/Public%20Files/modelShader.frag

http://inferno.codebrainshideout.net/Public%20Files/modelShader.vert

And what my shaders look like.

http://inferno.codebrainshideout.net/Public%20Files/metal%20plate%20floor.shader

"Renormalize" means you take the new value and normalize it (i.e. give it a length of 1). Essentially:


distance = sqrt(x*x + y*y + z*z);
x /= distance;
y /= distance;
z /= distance; 

Well, you get the idea. Or you could just call normalize on the value within the pixel shader and let it do the job for you (though it burns up some more cycles in the GPU code).

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

I note from your fragment shader code that you're already doing this, so nothing to worry about here.


vec3 tnormal = 2.0 * getTex(1, gl_TexCoord[0].st).rgb - 1.0;
tnormal = normalize (tnormal);

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

I ended up solving my own problem with the "triangles turning completely black" problem. I had sunLocation set as a vec4 but was accidentally doing glUniform3f to send the coords to GLSL. Changed it and it fixed the problem.

Thanks for the help. :)

This topic is closed to new replies.

Advertisement