Sign in to follow this  
SaTANO

Specular problem solved

Recommended Posts

SaTANO    507
I finally made GLSL shader for normal mapping and I also want to use specular based on normal texture. My normal mapping works without problem and specular also works but has some bugs. I have glitch in specular in place where UV coordinates of same vertex differs. My friend told me that its well known common problem but he doesn't know how to solve it, so I am asking here. Best thing to do is simply show you what exactly I mean in picture (as reference model I used zombie head from turbosquid, this one was for free :) ) Specular problem for calculating specular I am using well known formula vec4 spec = pow( max(dot(halfVector,normal),0.0) , specularPower ); I am sending tangent array to shader for every vertex based on crossproduct of triangle vertexes and UVs vectors. Am I missing something? Is there any way to solve this? Do I need to recalculate tangent in some other way for these vertexes? Thanks for answers [Edited by - SaTANO on February 17, 2010 1:34:19 PM]

Share this post


Link to post
Share on other sites
Ashaman73    13715
Normalmapping is prone to artifacts. In your case it seems that your tangentspace is flipped( normal is pointing inside). I don't think, that you can handle such artifacts in the shader. You have to do a proper preprocessing of the mesh and eventually tell your artist to update his model.

Best to hide seams as much as possible and avoid using mirrored UV coords at seams.

From a technical aspect take a look at messing with tangent space, there're some tips about proper preprocessing.

Share this post


Link to post
Share on other sites
Dinsdale    255
Clearly this is problem of the mesh, not the shader, as Ashaman73 pointed out. The surface normal continuity is broken where the specular seam appears. When dealing with smooth surfaces, one way to avoid such artifacts is to share vertices (and thus share normals and texcoords) between adjacent triangles. I.e. store each vertex of the mesh just once and use indexes to form triangles.

Share this post


Link to post
Share on other sites
SaTANO    507
Thanks
As you said it is problem with continuity of surface...

From your post I first thought it could be problem with my normals so I draw them but they were absolutely clear.
normals


Second thing I tried were my tangents and yes here is the problem.
Dinsdale wrote that good way to avoid these artifacts is to share verticles using indexes and I am creating array using this method. The problem is that vertex has different UV coordinates so they are stored like new vertex.

On tangent picture you can see really sharp edge of tangent caused by different UV.
tangents



Ashaman73 thanks for link. I read it and discovered that I cant handle some meshes as shown on cylindrical and ball model.
Well now I am trying to soft these edges using average tangent from every tanget shareing same vertex (but different UV). The edges are a bit smoother but I think this is not right method to handle this.
smooth tangents


[Edited by - SaTANO on February 8, 2010 6:43:55 AM]

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