Skip to main content
GameDev.net gamedev.net
🔒 Locked

Specular problem solved

Started by SaTANO Feb 7, 2010 at 2:53 PM 2 replies 1.4k views
Original Post
SaTANO
SaTANO
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]
Ashaman73
Ashaman73
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.

Dinsdale
Dinsdale
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.
SaTANO
SaTANO
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.