Jump to content

  • Log In with Google      Sign In   
  • Create Account


Texture filtering on normal and specular maps


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 newObjekt   Members   -  Reputation: 208

Like
0Likes
Like

Posted 09 April 2013 - 08:15 PM

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, 09 April 2013 - 08:17 PM.


Sponsor:

#2 blueshogun96   Crossbones+   -  Reputation: 880

Like
2Likes
Like

Posted 10 April 2013 - 01:36 AM

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.


Follow Shogun3D on the official website: http://shogun3d.net

 

blogger.png twitter.png tumblr_32.png facebook.png


#3 mhagain   Crossbones+   -  Reputation: 7833

Like
2Likes
Like

Posted 10 April 2013 - 03:15 AM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 Hodgman   Moderators   -  Reputation: 29567

Like
2Likes
Like

Posted 10 April 2013 - 03:16 AM

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.

#5 newObjekt   Members   -  Reputation: 208

Like
0Likes
Like

Posted 10 April 2013 - 11:44 AM

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



#6 newObjekt   Members   -  Reputation: 208

Like
0Likes
Like

Posted 11 April 2013 - 06:06 PM

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, 11 April 2013 - 11:36 PM.


#7 newObjekt   Members   -  Reputation: 208

Like
0Likes
Like

Posted 11 April 2013 - 11:38 PM

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



#8 Sik_the_hedgehog   Crossbones+   -  Reputation: 1608

Like
1Likes
Like

Posted 11 April 2013 - 11:51 PM

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

#9 mhagain   Crossbones+   -  Reputation: 7833

Like
1Likes
Like

Posted 12 April 2013 - 03:13 AM

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

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#10 newObjekt   Members   -  Reputation: 208

Like
0Likes
Like

Posted 12 April 2013 - 07:21 PM

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, 12 April 2013 - 07:21 PM.


#11 newObjekt   Members   -  Reputation: 208

Like
0Likes
Like

Posted 12 April 2013 - 09:30 PM

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, 12 April 2013 - 09:33 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS