Taberu
(Taberu)
July 7, 2019, 12:23pm
1
Hi everyone,
quick question! I used UProceduralMeshComponent presented here, in this tutorial:
After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...
Reading time: 1 mins 🕑
Likes: 13 ❤
Everything works fine, except that normals don’t make any difference in triangle facing direction.
Here is a triangle from tutorial:
TArray<FVector> normals;
normals.Add(FVector(1, 0, 0));
normals.Add(FVector(1, 0, 0));
normals.Add(FVector(1, 0, 0));
And here is the same triangle but with opposite normals:
TArray<FVector> normals;
normals.Add(FVector(-1, 0, 0));
normals.Add(FVector(-1, 0, 0));
normals.Add(FVector(-1, 0, 0));
With changing the normals I would assume the triangle would look like this on the expected side, but I had to rotate camera to make this screenshot:
Because normals are not affected by my code, my cube looks like this:
Can anybody tell me what’s going on? Somehow I can’t debug the code which is inside the CreateMeshSection_LinearColor function. I really appreciate any clues!
Taberu
(Taberu)
July 11, 2019, 4:56pm
2
So it turned out this it like in OpenGL for example and triangle winding order is important for culling. Normals are mainly for lighting (which you can see on the screenshots). If you want to invert the triangle mesh, you need to change the triangle IDs from [0, 1, 2], to for example [2, 1, 0], to be counter-clockwise. More info about it from Wikipedia:
In computer graphics, back-face culling determines whether a polygon of a graphical object is visible. It is a step in the graphical pipeline that tests whether the points in the polygon appear in clockwise or counter-clockwise order when projected onto the screen. If the user has specified that front-facing polygons have a clockwise winding, but the polygon projected on the screen has a counter-clockwise winding then it has been rotated to face away from the camera and will not be drawn.
The pr...