Sign in to follow this  
newObjekt

Texture filtering on normal and specular maps

Recommended Posts

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 : )

Edited by newObjekt

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Edited by newObjekt

Share this post


Link to post
Share on other sites

"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).

Share this post


Link to post
Share on other sites

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. :)

Edited by newObjekt

Share this post


Link to post
Share on other sites

So I've gotten some pretty good results by making changes to how normals and stuff are calculated.

http://inferno.codebrainshideout.net/Images/specular%20n%20stuff.png

Does this look alright to you guys?

 

I also would really like to make the specular light change based on the angle the player is looking at things from.

I was thinking

 

vec3 vertexNormal;

vec3 lightDirection;

vec3 cameraDirection;

 

vec3 a = reflect(lightDirection, vertexNormal);

float shininess = pow(max(dot(a, cameraDirection), 2);

 

But I don't know how to get the camera direction and I don't know if the GLSL reflect works like that.

Edited by newObjekt

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this