Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

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?