I am doing some procedural terrain. The output of the algorithm (Dual Contouring) is a vertex list(position, normal), and a list of indices.
The output is also in Quads not triangles. I know I will have to triangulate these quads, but how do I create the tangent vectors? This terrain is smooth and the quads share verts (so I cannot create the tangents like the wiki does) it will just end up with a normal that favors the last triangle that uses that vert).
Do I create the tangents for every triangle that uses that vert then average them? It just feels like if I already have the normal I shouldn’t have to go through all that (I could be wrong, it would not be the first time).
When I left out tangent generation, very funny things happened to my meshes, especially when assigning textures (even though normals were defined). SiggiG has some example code in the forum for calculating the tangents of procedural meshes: Generate Procedural Mesh - C++ - Epic Developer Community Forums
If using the new UProceduralMeshComponent from >= 4.8p3, you then only have to supply these tangents to the UProceduralMeshComponent::CreateMeshSection(…) function.
Otherwise you may check the implementation of this and how the tangents are directly assigned there: Plugins\Runtime\Source\ProceduralMeshComponent
I just spent a day forum crawling trying to figure out why the tangents I was generating were causing weirdness with bump maps on materials. What I finally discovered is that the tangents need to be pointing in the same direction as the x direction on your UV coordinates.
Hopefully, the following code snippet is enough to help out anyone who is running into the same problem later on.