I’ve been trying to figure this out for almost a month now and, by this point, I’m out of ideas.
I was hoping someone could point me in the right direction; if not give me the solution entirely.
What I have:
- What’s happening in the images is that water-looking cubes are being clipped (based on a world-space y position)
- then in a post-processing effect the backfaces are being replaced with a texture representing the “top” of the slice
- the texture coordinates of this “top” texture are based on the pixel’s screen position
- a custom lighting function is applied to this “top” texture where the normal is always facing up (0,1,0)
(ignore the transparency difference between the left and right, they’re being rendered in a special way to solve sorting issues; also, there sphere is just there to help display the pixel depths)
Now that you understand what’s going on, my issue:
I also need these backfaces to overwrite the depth as if what you’re seeing is the top of a cube and not the back of a sliced cube.
I know how to write to the depth buffer by returning this from the ‘frag’ function
struct output
{
fixed4 color : SV_Target;
float depth : SV_Depth;
};
But this is were my ideas run dry. I can’t figure out how to calculate the depth values that turn the backface into the “top”.
I’ve looked into ray-marching but I don’t understand it in the slightest so I’m not sure if that’s the way to go.
P.S.
Maybe I’m doing this in an overcomplicated way but this was the cleanest way I could get what I wanted. As a side note, the reason for doing it this way is because each ‘water cube’ needs to be able to have a unique clipped height and that “top” needs to always remain flat (facing up) no matter how the cube is rotated.
P.P.S.
Oh! I Should also mention I do have access the the position of each vertex for each of the cubes… in case I need that for a solution you’re going to suggest.

