I’m creating a randomly generated maze game. So far I have it working when I spawn each individual mesh as a static mesh actor in c++. To improve performance I’m trying to use instanced static meshes since there will probably be thousands of the same mesh in the scene. But when I did that, the meshes looked very wrong. From one angle it looks fine (although it seems to be a bit darker than it was), but from the opposite angle everything is very dark with terrible artifacting. I have static lighting disabled in the project because the entire level is procedurally spawned in. The game also uses bloom, ambient occlusion, and auto exposure effects. I have no clue why this is happening. Do any of you know?
There is a lot of code I wrote that spawns everything, but this is the code I have for the Instanced Static Mesh Actor:
const FVector AMazeStaticPiecesActor::zAxis = FVector(0.0f, 0.0f, 1.0f);
AMazeStaticPiecesActor::AMazeStaticPiecesActor(const FObjectInitializer& oi)
{
PrimaryActorTick.bCanEverTick = false;
instStaticMesh = CreateDefaultSubobject<UInstancedStaticMeshComponent>(TEXT("m"));
instStaticMesh->BodyInstance.SetObjectType(ECC_WorldStatic);
instStaticMesh->BodyInstance.SetCollisionEnabled(ECollisionEnabled::NoCollision);
instStaticMesh->BodyInstance.SetResponseToAllChannels(ECR_Ignore);
RootComponent = instStaticMesh;
}
void AMazeStaticPiecesActor::setMesh(const TCHAR* mName)
{
instStaticMesh->SetStaticMesh(Cast<UStaticMesh>(StaticLoadObject(UStaticMesh::StaticClass(), nullptr, *(FString(TEXT("/Game/Meshes/")) + mName))));
}
void AMazeStaticPiecesActor::spawnPiece(int x, int y, int z, short rot)
{
transform.SetIdentity();
transform.SetRotation(FQuat(zAxis, FMath::DegreesToRadians(rot)));
transform.SetLocation(FVector(x, y, z));
instStaticMesh->AddInstanceWorldSpace(transform);
}
void AMazeStaticPiecesActor::removePiece(int index)
{
instStaticMesh->RemoveInstance(index);
}
The first image is the angle which looked fine but seems darker than it was.
The second image is the angle that looked very wrong.
The third image has 3 static meshes spawned in with the editor, and is what the meshes are supposed to look like.