Hey all! I’ve been testing a scene with a lot of asteroids, and discovered a strange issue with all of my entities being culled at the same time at some distances… or positions… I’m not quite sure, but I made a video to show what I mean. This is 300k asteroids made up of 3 varieties and placed randomly in a 30km2 area. Camera culling enabled / disabled makes no difference, neiter does the material GPU instancing setting.
Any idea what might be causing this?
Cheers!
Edit: Another perspective on the issue using a moving asteroid field. As you can see, if I start in reverse in any direction, I can go as far as I like, and come back again, but if I go forwards from the zero point in any direction, I can only get about 8 - 12k meters before they all vanish.
Is this perusing the hybrid renderer?
Yes… here’s my entity creation code…
public unsafe void CreateEntities(float mass, bool isDynamic)
{
// Create an entity manager
EntityManager entityManager = World.Active.EntityManager;
// Create an entity archetype defining the components that are attached to this entity type
EntityArchetype entityArchetype = entityManager.CreateArchetype(
typeof(RenderMesh),
typeof(Translation),
typeof(Rotation),
typeof(Scale),
typeof(PhysicsCollider),
typeof(PhysicsMass),
typeof(PhysicsGravityFactor),
typeof(LocalToWorld),
typeof(AsteroidDistanceComponent)
);
// Create a native array to hold entities
NativeArray<Entity> entityArray = new NativeArray<Entity>(totalRoids, Allocator.Temp);
// Create entities of this archtype, fillig the array
entityManager.CreateEntity(entityArchetype, entityArray);
// Loop through all of the entities in the array...
for (int i=0;i< entityArray.Length;++i)
{
// Create the entity
Entity entity = entityArray[i];
// Disable gravity
entityManager.SetComponentData(entity, new PhysicsGravityFactor { Value = 0.0f });
// Assign a random scale
float scale = UnityEngine.Random.Range(minScale, maxScale);
entityManager.SetComponentData(entity, new Scale{ Value = scale });
// Assign a collider
BlobAssetReference<Unity.Physics.Collider> collider = Unity.Physics.SphereCollider.Create(float3.zero, scale/2f);
entityManager.SetComponentData(entity, new PhysicsCollider { Value = collider });
// Assign a mass
Unity.Physics.Collider * colliderPtr = (Unity.Physics.Collider*)collider.GetUnsafePtr();
entityManager.SetComponentData(entity, PhysicsMass.CreateDynamic(colliderPtr->MassProperties, mass));
// Set a random spawn position within the fieldsize
float3 spawnPos = UnityEngine.Random.insideUnitSphere * fieldSize;
entityManager.SetComponentData(entity, new Translation() { Value = spawnPos });
// Define the max distance for the field
entityManager.SetComponentData(entity, new AsteroidDistanceComponent() { maxDistance = fieldSize });
// Assign a random start rotation
Quaternion rot = Quaternion.EulerRotation(UnityEngine.Random.Range(0, 359), UnityEngine.Random.Range(0, 359), UnityEngine.Random.Range(0, 359));
entityManager.SetComponentData(entity, new Rotation { Value = rot });
// Assign a random mesh from the list
entityManager.SetSharedComponentData(entity, new RenderMesh
{
mesh = meshes[UnityEngine.Random.Range(0, 2)].lods[1],
material = material
});
}
// Dispose of the array
entityArray.Dispose();
}
Hey WarpBubble, were you able to solve this issue? I’m running into it as well. In my case I’ve configured Lods by attaching
MeshLODComponent to the mesh entities and MeshLODGroupComponent to the lod parent entity. This seems to work correctly, to the point I’m attaching FrozenRenderSceneTag to the mesh entities. Then I have a problem similar to yours, stuff seems to be culled when they shouldn’t.
Without FrozenRenderSceneTag performance is really bad as addBatches() is going crazy.
This is caused by the size of the Bounds created inside the render system when adding a new render batch. This can be circumvented, but I don’t have a good proposal for you with this exact usecase. The position and size of the bounds are hardcoded in the system currently, so either use a different rendering approach or add a local copy of the hybrid renderer and modify the bounds setup when adding batches to fit your needs.