I'm trying to render a grid similar to Starcraft 2's build grid. I want each tile to change its color as efficiently as possible using a single shader for the whole grid.
On the CPU side, I have a byte[] (C#) which contain the state of each tile (free, occupied, conflict, etc.). These states change each time the player moves a building over the grid or builds it. My idea right now is to send this data to the GPU through a StructuredBuffer, submit a procedural drawcall, and somehow change the color of the tiles based on the data and the vertexID.
I have two potential problems with this:
- There is no 8 bit scalar type in HLSL (like byte). Should I convert my byte[] to a uint[] and pass that to the buffer instead? I don't like the idea of having a duplicate of my data array. Is there a way to "fake" an 8 bit scalar in HLSL?
- I'm using Unity, and the only way to update a buffer on the CPU side is to set the entire array of data. This could be done frequently (each time the player moves the building to another position). I wonder if there is a more GPU-centric approach to fetch the state of each tile in my grid.
I know this all sounds like premature optimization, but my main goal here is to learn new ways to think about these kinds of problems.
Thanks for any ideas.