You are here: Foswiki>Oasis Web>Diary>2023>2023-02-13 (20 Feb 2023, dwh)Edit Attach
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.

  Without Normals With Normals
Shared shared without normals.jpg
Shared Without Normals: UE4 recomputes the normals for each shared vertex, averaging the face normals of each shared vertex.
shared with normals3.jpg
Shared With Normals: Here I have specified normals for each vertex. This is the same effect as Shared without Normals.
Unshared unshared without normals.jpg
Unshared Without Normals: All the vertices are unshared, but UE4 is recomputing the normals by averaging the face normals as it did for the shared without normals
unshared with normals.jpg
Unshared With Normals: Here I have specified the normals so each vertex is pointing in the direction of its face. This gives very sharp edges.

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.

unshared with normals corner nv.jpg
Mesh editor showing the vertext normals at a corner. Each of them are perpendicular to the face it's on.
unshared with normals corner tan.jpg
The unset vertex tangent vector
unshared with normals corner bno.jpg
The unset vertex bi-normal vector
unshared with normals corner expected.jpg
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.
shared with normals.jpg
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 nv.jpg
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 normals2.jpg
Shared With Normals: I had put the normals in wrong. Here it is again with normals for each vertex.
shared with normals2 nv.jpg
Shared With Normals

diagram1.jpg
Diagram
I Attachment Action Size Date Who Comment
CubeTest_Shared_With_Normals.cmdcmd CubeTest_Shared_With_Normals.cmd manage 329 bytes 13 Feb 2023 - 19:45 Main.dg  
CubeTest_Shared_With_Normals.jsonjson CubeTest_Shared_With_Normals.json manage 1020 bytes 13 Feb 2023 - 19:45 Main.dg  
CubeTest_Shared_Without_Normals.cmdcmd CubeTest_Shared_Without_Normals.cmd manage 338 bytes 13 Feb 2023 - 19:46 Main.dg  
CubeTest_Shared_Without_Normals.jsonjson CubeTest_Shared_Without_Normals.json manage 778 bytes 13 Feb 2023 - 19:46 Main.dg  
CubeTest_Unshared_With_Normals.cmdcmd CubeTest_Unshared_With_Normals.cmd manage 335 bytes 13 Feb 2023 - 19:46 Main.dg  
CubeTest_Unshared_With_Normals.jsonjson CubeTest_Unshared_With_Normals.json manage 2 K 13 Feb 2023 - 19:47 Main.dg  
CubeTest_Unshared_Without_Normals.cmdcmd CubeTest_Unshared_Without_Normals.cmd manage 344 bytes 13 Feb 2023 - 19:47 Main.dg  
CubeTest_Unshared_Without_Normals.jsonjson CubeTest_Unshared_Without_Normals.json manage 1 K 13 Feb 2023 - 19:47 Main.dg  
diagram1.jpgjpg diagram1.jpg manage 156 K 13 Feb 2023 - 15:58 Main.dg  
shared_with_normals.jpgjpg shared_with_normals.jpg manage 78 K 13 Feb 2023 - 10:20 Main.dg  
shared_with_normals2.jpgjpg shared_with_normals2.jpg manage 92 K 13 Feb 2023 - 11:31 Main.dg  
shared_with_normals2_nv.jpgjpg shared_with_normals2_nv.jpg manage 76 K 13 Feb 2023 - 11:31 Main.dg  
shared_with_normals3.jpgjpg shared_with_normals3.jpg manage 42 K 14 Feb 2023 - 10:07 Main.dg  
shared_with_normals_nv.jpgjpg shared_with_normals_nv.jpg manage 84 K 13 Feb 2023 - 10:20 Main.dg  
shared_without_normals.jpgjpg shared_without_normals.jpg manage 47 K 14 Feb 2023 - 10:07 Main.dg  
shared_without_normals_nv.jpgjpg shared_without_normals_nv.jpg manage 86 K 13 Feb 2023 - 10:21 Main.dg  
unshared_with_normals.jpgjpg unshared_with_normals.jpg manage 48 K 14 Feb 2023 - 10:07 Main.dg  
unshared_with_normals_corner_bno.jpgjpg unshared_with_normals_corner_bno.jpg manage 78 K 13 Feb 2023 - 11:14 Main.dg  
unshared_with_normals_corner_expected.jpgjpg unshared_with_normals_corner_expected.jpg manage 97 K 13 Feb 2023 - 11:22 Main.dg  
unshared_with_normals_corner_nv.jpgjpg unshared_with_normals_corner_nv.jpg manage 79 K 13 Feb 2023 - 11:15 Main.dg  
unshared_with_normals_corner_tan.jpgjpg unshared_with_normals_corner_tan.jpg manage 75 K 13 Feb 2023 - 11:15 Main.dg  
unshared_with_normals_nv.jpgjpg unshared_with_normals_nv.jpg manage 73 K 13 Feb 2023 - 10:21 Main.dg  
unshared_without_normals.jpgjpg unshared_without_normals.jpg manage 46 K 14 Feb 2023 - 10:07 Main.dg  
unshared_without_normals_nv.jpgjpg unshared_without_normals_nv.jpg manage 75 K 13 Feb 2023 - 10:21 Main.dg  
Topic revision: r7 - 20 Feb 2023, dwh
Warning: Can't find topic Oasis.WebLeftBarExample

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback