2023-02-12 | 2023-02-13 |
2023-02-18
2023-02-13
The Four Cubes
To demonstate the difference between shared and unshared vertices in meshes and the importance of the vertex normals. For this I have used our mesh json format. I have create four varients of a cube:
CubeTest_Shared_With_Normals.json
CubeTest_Shared_Without_Normals.json
CubeTest_Unshared_With_Normals.json
CubeTest_Unshared_Without_Normals.json
Example of the JSON and how command to create the mesh.
- CubeTest_Shared_Without_Normals.json
{
"CubeTest_Shared_Without_Normals": {
"Sections": [
{
"Material": "MI_RAL_9010_Matt",
"Triangles":
[
[0, 1, 5],
[5, 4, 0],
[1, 2, 6],
[6, 5, 1],
[2, 3, 7],
[7, 6, 2],
[3, 0, 4],
[4, 7, 3],
[4, 5, 7],
[7, 5, 6],
[0, 3, 1],
[1, 3, 2]
],
"VertexNormals": [],
"Vertices":
[
[0.0 , 0.0 , 0.0],
[10.0, 0.0 , 0.0],
[10.0, 10.0, 0.0],
[0.0 , 10.0, 0.0],
[0.0 , 0.0 , 10.0],
[10.0, 0.0 , 10.0],
[10.0, 10.0, 10.0],
[0.0 , 10.0, 10.0]
]
}
],
"Xo": 0.0,
"Yo": 0.0,
"Zo": 0.0
}
}
To create this mesh using Oasis I created a command file:
[
{
"Command" : "CreateMeshFromJson",
"JsonTag" : "CubeTest_Shared_Without_Normals",
"JsonPath" : "D:/CubeTest/CubeTest_Shared_Without_Normals.json",
"UE4Dir" : "/Game/Developers/dg",
"UE4Materials" : "/Game/dhp11/Oasis/Materials",
"UE4Asset" : "CubeTest_Shared_Without_Normals"
}
]
I then execute this command file using the EUB_Cmd editor utility in Oasis by calling it from the command line like this:
C:\> "C:\Program Files\Epic Games\UE_4.25\Engine\Binaries\Win64\UE4Editor.exe" D:/source/UE4_096_4.25/UE4_096.uproject EUB_Cmd D:\CubeTest\CubeTest_Shared_Without_Normals.cmd 1 1
In the command file I specified the UE4Dir as /Game/Developers/dg which equates to this real path D:\source\UE4_096_4.25_Core\Content\Developers\dg which is where the meshes are created as uassets.
The reults of four cube tests.
Other Issues
When processin the meshes where I don't provide normals and it has to recompute, I get the following warnings:
[2023.02.13-09.44.37:135][ 37]LogStaticMesh: Warning: CubeTest_Unshared_Without_Normals has some nearly zero tangents which can create some issues. (Tolerance of 1E-4)
[2023.02.13-09.44.37:135][ 37]LogStaticMesh: Warning: CubeTest_Unshared_Without_Normals has some nearly zero bi-normals which can create some issues. (Tolerance of 1E-4)
How do tangets and bi-normals effect the shading? In the code for the mesh creation, these vectors are defaulted to
EmptyVectors which probably explains the warning.
https://gamedev.stackexchange.com/questions/51399/what-are-normal-tangent-and-binormal-vectors-and-how-are-they-used
It looks like the tangent and binormal are used to create the normal by taking the cross-product of the two. The tangent and binormal should probably follow the edges of the triangle they are for. The order seems important as it's used in triangle winding, so I think if you swap the tangent and binormal around the winding would be reversed.
Mesh editor showing the vertext normals at a corner. Each of them are perpendicular to the face it's on.
The unset vertex tangent vector
The unset vertex bi-normal vector
How I think it should be set. I think if the Tangent (red) and Bi-normal (blue) vectors are swapped it might have effect on the winding order but I'm not sure.
https://www.researchgate.net/figure/Normal-blue-tangent-red-and-binormal-green-are-computed-per-vertex-Thus-every_fig8_47861427
When Normals go wrong.
Here are examples when normals have been specified but are infact wrong....
Shared With Normals: Here I have specified normals for each vertex but the normals have not been averaged for each face and are pointing away for a face
Shared With Normals: Here you can see the normal pointing 90degrees from the side face.
- NOTE: I will double check this. Even thought I expect it to look wrong/weird, my normals might actually be wrong
Shared With Normals: I had put the normals in wrong. Here it is again with normals for each vertex.
Shared With Normals
Diagram