I’m trying to workout how I can accomplish this:
I have a top-down perspective. Everything drawn is just 2D sprites. However; one of the sprites color-channels, or maybe it’s in a different sprite image, is that sprites “depth” information. Meaning, each pixel on the sprite, what is the z-value of that sprite, or how high is it from the ground.
I thought it would be cool to cast shadows. But unlike the normal methods I’ve seen where shadows are essentially endless, what I want is to show the sprites shadow as though the sun where “above” it. Because it’s a top-down perspective (this is a 2D game), the shadows being cast can’t be endless; they’d usually be short.
I would also like to be able to show sunrise and sunset, i.e. long shadows, and I’d like to be able progress the “sun” through the sky during the game. And I’d even like dynamic shadows; so an explosion casts the sprites shadows away.
I can render the sprites into a framebuffer and get myself the diffuse information, depth information (the z-component really); but how can I combine this to get the shadows? For each frag, do I just loop through all my lights (or single “sun”), find the direction to it and step towards it until I hit a piece of depth that generates a shadow, or if I’m further than the shadow casting length just discard? I’m a bit lost as to what to do.
EDIT:
For example, all of these are cool https://www.reddit.com/r/gamedev/comments/238z3e/any_good_resources_for_glsl_shader_techniques/ but I want the added ability to raise and lower the lights “vertically”.