Search Unity

Alternative to RenderMesh for displaying procedurally generated meshes?

Discussion in 'Graphics for ECS' started by Deleted User, Aug 14, 2020.

  1. Deleted User

    Deleted User

    Guest

    I've been playing around with ECS to generate voxel terrain. My issue is, what I assume to be, poor chunk utilization. Basically, I create a mesh for each 8x8x8 section of voxels and apply that mesh to a RenderMesh component. Since they're shared components with completely different meshes they're stuck into different chunks.

    Looking for suggestions, thanks.
     
  2. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    Does it need to be ECS for rendering? You can generate the Mesh asynchronously in ECS/jobs, then pop the Mesh onto a regular MeshRenderer GameObject (or directly make draw calls).
     
  3. Deleted User

    Deleted User

    Guest

    It's definitely not a requirement to run purely on ECS. I was curious if there was just something I was missing.
     
  4. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    792
    The question is, which is faster, many GameObjects or many ECS chunks? I experiment with ECS voxel terrain myself every now and then, I use chunks with 16x16x16, with 8 there are too many meshes, with 32 it can lead to problems depending on the data structure. My goal is to pack one voxel chunk (include voxel data) into one ECS chunk.
     
  5. Deleted User

    Deleted User

    Guest

    Indeed, I'd like to experiment with whichever approach is currently more performant. I agree the 8 by 8 voxel chunk size is a little small. I've been using ulongs to encode nearly all the data a voxel needs, (base color, outline color, a few flags for rendering, etc.) which I admit, is a little excessive. Either way, it's a trivial matter to switch voxel chunk sizes (it even works with varying sizes at once so long as they exist in separate 4th dimensions) in my design as well as simply applying meshes to game objects.
     
  6. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    792
    I am currently working on a concept that requires a maximum of 3 bytes per voxel, one byte for voxel index, one byte enum flag in which a face should be created, and one byte reserved for later.
    With 16 voxel chunks one chunk have 4096 voxels, in order to stay below 16 KB the maximum voxel size is 3 bytes.
     
  7. Deleted User

    Deleted User

    Guest

    Interesting. I'll make some adjustments to how much data I allocate for voxels. While I'm at it, I'll compare rendering performance between RenderMeshes and GameObjects at different voxel chunk sizes, keeping the voxel count constant.
     
  8. Deleted User

    Deleted User

    Guest

    So after a bit of playing around I've concluded that the number of voxels within a section (tested cube side lengths 2 through 25) has no noticeable affect, as expected.
    Rendering entities using a RenderMesh and rendering to GameObjects are both just as performant, even in the case of 10,000 sections of 16x16x16 all with different meshes.
     
  9. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845