Hi, making a retro game but using DX11 on Windows 11 using C++ and my own game engine. Currently looking at rendering the ground.
In game it's just 40M horizontal and 5M depth.
I break it up into a grid so each meter has 4 by 4 blocks.
Basically the entire lot is a 1D array and just has height and tile number. Trying to keep the CPU → GPU traffic to a minimum.
struct strPixelTerrain
{
BYTE m_height;
BYTE m_tile;
};
The array is (will be) unpacked in the vertex shader.
At the moment… for debugging sake I just iterate all and use my standard graphics rendering pipeline using instanced geometry. However since each instance is 32 bytes and there's like 400 * 50 terrain 3d tiles to Render it chokes. Mainly because after inserting it sorts everything so it can batch calls.
I have a vehicle that reads the terrain on the CPU side to get the height of the terrain under each wheel, the main aim is I would like to deform the terrain a bit when bombs hit, drive over it, etc. mainly for effect and so the suspension on the vehicle gets some work.
I do have the ability to call a HLSL shader and build the geometry for each tile from just using the above mentioned instance array.
From the instance index I can get the height and tile, calculate the position and render the correct tile.
However, if possible I'd rather just send an array of indexes with the ones that changed since the last frame.
Would be ~20 tiles each frame. Not 40K+ instances with all the setup and sorting.
Just trying to think of the best way to keep a CPU array in sync on the GPU without resending all of it every frame..
So in summary.
- Simple ground terrain array with just height and tile number.
- On CPU side need ability to read a X,Z coordinate and get the interpolated height (easy)
- On GPU side need to be able to render all in a single batch… (easy)
- Hard bit… getting array on CPU → GPU using as little bandwidth as possible.
It's a “space invaders” flavor game.
Each tile index will eventually have things like mesh number, friction and anything else that will make the game a bit more immersive.