I’m trying to draw a set of isometric, sprite-based buildings across a 3D hex terrain. There are various hex cells constructed which can vary In elevation. I would like for the sprite buildings to sit on (some of) the cells ,which are placed during runtime, and for them to be drawn such that the terrain of the cell, in which the sprite sits, to not obscure the building. That is, the sprite intersects the terrain and appears to sit in its centre (hex). However, I would also like for cells, which are closer to the camera and higher elevation, to obscure the building as one might expect.
I’ve tried a number of potential solutions, but I’ve found some issues with my tests and I’m not so hot on HLSL so hoping for a few pointers.
-
I tried to set ZTest to Always. This solves the problem of drawing the parts of the building sprite which cut through the seating hex cell on top. However, of course, this means the sprite is not obscured by higher/ closer cells since it’s always drawn on top with this setting.
-
I tried to assign sorting orders of sprites and terrain hex cells based upon their elevations. As an aside, I have used an implementation of Catlike codings hex map for the cell based terrain. However, I have made some modifications such that cells are meshed together, based upon elevation, and in chunks (for efficiency) so that I can set the sorting order for that mesh.
Solution 2) seemed like it was going to work. However, I ran into some problems using a custom shader which did some strange things on some elevations of sprite, whereby the skybox would show through on parts of the transparent (cutout) at particular areas where there is a large difference between elevtions. There can be a number of varying elevations, ranging from 0 → 6 which are equally spaced in y.
This problem has stumped me and I’m not sure how I can solve it and I wonder if I’m over thinking it, in the meantime, I’ll look over some docs on unity shaders, but would be awesome if I could get some help!
Danke!