I'm working on a shadertoy "snake" game, using the new multi pass rendering abilities to save game state between frames.
I'm using raytracing to render the board (an AABB), and am planning on using spheres to render sections of the snake's body.
The game board is a 16x16 grid and each grid can either have a sphere there (a segment of the snake's body) or not. Snake body segments don't move, they are just either there on the grid or not. When the snake moves, a new sphere appears in the front and an old sphere disappears from the back.
The problem I'm trying to solve is how to render the snake body spheres.
For instance, a naive approach would be to store a 16x16 grid in pixels specifying whether there was a snake body in that grid cell or not.
I would then do a ray vs sphere check for up to 256 different spheres within my pixel shader, which seems like a no go.
Another method might be to figure out where the ray begins and ends on the game board (when it's between the high and low height values of where the spheres are) and then use something like bressenham line algorithm to go from the start to the end of the line the ray takes on the board, and check only the grid cells that the ray hits.
The problem there is that it requires a dynamic loop.
Maybe a more practical solution would be to make the camera have a nearly top down view and where the ray enters the playable game world, test any sphere in the cell it hits as well as the 8 neighboring cells.
I'm betting there are some much better solutions that I'm not thinking of.
Does anyone know of any interesting techniques or creative solutions?
Edit: here is an older version of this game i made, which was CPU / software rendered, to give an idea of what I'm planning.