Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Best handling of texture data that changes very often?

Discussion in 'General Graphics' started by xSNOWM4Nx, Sep 13, 2023.

  1. xSNOWM4Nx


    Jan 9, 2017
    I'm working on a FallingSand-like game as a hobby.
    The behavior of the squares(pixel, fragment) is calculated using various jobs, then the information is filled into a NativeArray<byte>.

    The screen is divided into chunks. Each chunk holds one Texture2D object. As soon as a chunk needs to be updated, the NativeArray<byte> from the jobs is loaded into the corresponding Texture2D object.
    Code (CSharp):
    1. ChunkCanvas.Texture.LoadRawTextureData(_chunkColorData);
    2. ChunkCanvas.Texture.Apply();
    In various experiments I have found that a chunk size of 32x32 gives good performance. Divided across the screen, there are around 200 chunks. With this implementation, the more chunks that have to be updated, the greater the performance drop.

    Now I'm wondering if there is a more efficient way to transfer the data to the GPU?

    I've already thought about doing the calculation for the squares in a shader. Since the information also has to be available outside the GPU, the data would have to be moved back to the CPU each time. I'm not sure if that's really more efficient.

    Does anyone here have experience with a similar setup?