Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question How to pass chunks of StructedBuffers into a compute shader

Discussion in 'Shaders' started by NighrixUnity, May 10, 2024.

  1. NighrixUnity

    NighrixUnity

    Joined:
    Jun 7, 2023
    Posts:
    3
    I have a sparse voxel octree that is flatten for the gpu now I have the problem that this only allows one octree at a time and not multiple chunks, I thought about combining the octrees but that would mean I have to store the old octree per chunk and the combined octrees (which would double the memory) maybe there is a better solution I am not aware of yet.
    Code (CSharp):
    1. StructuredBuffer<GPUOctreeNode> _SVOBuffer;
    2. StructuredBuffer <float4> _SVOData;
     
  2. NighrixUnity

    NighrixUnity

    Joined:
    Jun 7, 2023
    Posts:
    3
    The GPUOctreeNode looks like this, it points to the _SVOData with the dataIndex
    Code (CSharp):
    1. struct GPUOctreeNode {
    2.     float3 position;
    3.     float halfSize;
    4.     int childIndex;
    5.     int dataIndex;
    6. };
     
  3. NighrixUnity

    NighrixUnity

    Joined:
    Jun 7, 2023
    Posts:
    3
    or I would store the octree chunks in a combined structuredBuffer only and use compute shaders to add and remove chunks during runtime, this way I dont need to keep the old per chunk octree in memory