- Home /
Missing tangents on some vertices
I'm calculating tangents for simple polygons using the method described here: http://answers.unity3d.com/questions/7789/calculating-tangents-vector4.html
Most of the tangents are good. However, some are missing.
In the attached diagram tangent vectors are in blue, normals in red. The three vertices on the top have no tangents (actually tangents of length zero) while the remaining vertices are fine. As a result, the bump mapping becomes smooth near the bad vertices.
This occurs on every polygon in the scene, and always only on the vertices on the extreme +x edge of the polygons.
Any ideas?
According to that last entry in the thread, the guy suggests setting the r value to 0 if the dividend is 0, but really dividing 1 by 0 would result in infinity, not 0. Considering you're just going to normalize the result anyway, maybe you should try setting it to 1.0 when the dividend of the r value is 0.
I replaced the calculation of r with:
float div = s1 * t2 - s2 * t1;
float r = div == 0.0f ? 1.0f : 1.0f / div;;
but there is no change to the calculated tangents. I'll try this with a simple mesh rather than a procedural mesh, so it's easier to debug.
Answer by sdevet · Feb 02, 2014 at 03:04 PM
Mission accomplished!
I was using the first code here: http://answers.unity3d.com/questions/7789/calculating-tangents-vector4.html , but the triangles array is too small and data was missing.
But I should have been using the more efficient (and commented) code a little further down the page that does not try to truncate the triangle array.
Your answer
![](https://koobas.hobune.stream/wayback/20220613132316im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Programmatically generated skinned mesh not lit while animating 1 Answer
problem with mesh.normal? 0 Answers
normal issue -2 Answers
Seeing through mesh 1 Answer
Draw a perpendicular line from a vertex of the mesh 1 Answer