I have an Icosahedron subdivided and with LOD. Now i am trying to add a dynamic Material. The Problem is that i need the Normals for that.
I use Unreal Engine 4, when i use the build in Function to calculate Normals i get strange Artifacts in the Area between different LOD Levels.
So i made my own calculation with this Code:
TArray<FVector> normals;
normals.Init(FVector(-1.f, -1.f, -1.f), geoData.GeoData.Num());
int32 triangleCount = geoData.Triangles.Num() / 3;
for (int32 i = 0; i < triangleCount; i++)
{
int32 normalTriangleIndex = i * 3;
int32 triangleIndexA = geoData.Triangles[normalTriangleIndex];
int32 triangleIndexB = geoData.Triangles[normalTriangleIndex + 1];
int32 triangleIndexC = geoData.Triangles[normalTriangleIndex + 2];
FVector pointA = geoData.GeoData[triangleIndexA];
FVector pointB = geoData.GeoData[triangleIndexB];
FVector pointC = geoData.GeoData[triangleIndexC];
FVector sideAB = pointB - pointA;
FVector sideBC = pointC - pointB;
FVector nNormal;
nNormal = FVector::CrossProduct(sideAB, sideBC);
nNormal = nNormal / nNormal.Size();
nNormal = nNormal.GetSafeNormal();
normals[triangleIndexA] = -nNormal;
normals[triangleIndexB] = -nNormal;
normals[triangleIndexC] = -nNormal;
}
Seems the calculation is correct. when i skip the calculation of morphing in my shader those artifacts disappear... Maybe the Triangles are to close to each other while morphing them and this causes this artifacts?
This is how morphing looks like. (Source)