Hello, I’m using RenderMeshUtility.AddComponents to create my entities at runtime and I was wondering how I would go about implementing LoD for these entities.
I am using this code as a substitute for a real LoD-System for the moment:
partial struct LoD_Hack : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
LoD_HackJob job = new LoD_HackJob{cam = Camera.main.transform.position};
job.ScheduleParallel();
}
}
[BurstCompile]
public partial struct LoD_HackJob : IJobEntity
{
public float3 cam;
public void Execute(in LocalToWorld local, ref MaterialMeshInfo mmi)
{
if (math.distancesq(cam, local.Position) > 2000) mmi.Mesh = mmi.Material - 1;
else mmi.Mesh = mmi.Material;
}
}
With ~140k entities it takes ~9.5ms on 4-6 threads on my system, which is fine for now. But I would expect there to be far more efficient solutions to this problem. Hints to make my code above more performant would also be greatly appreciated.
What you have is a crude implementation of shared-entity mesh LOD, which is going to vastly outperform Unity’s LOD Group implementation. To be honest, you should probably share a timeline view of the profiler capture if you want to improve performance. Because the job you have should be very cheap.
If you wanted something more feature-rich, I have an advanced version of shared-entity mesh LOD in my framework. I describe how I made the base implementation here: Latios-Framework-Documentation/Optimization Adventures/Part 13 - LODS 1.md at main · Dreaming381/Latios-Framework-Documentation · GitHub
Thank you for looking at my code. I only started using DOTS a few days ago, so it’s great to hear that I’m outperforming, while not outfeaturing LOD groups for now.
Your Framework definitely gives me something to work towards, but to be honest it goes a bit over my head for now, but I’ll keep working towards it.