Game Design, Programming and running a one-man games business…

Yay depth sorting (kinda!)

So after a lot of mucking about with render states and blend modes and shaders and reading, and z buffers and other tedious things i think i now have the previously unattainable mixture of proper smoky effects, happening in 3D with my shadow casting and bright ‘burn’ laser and flame effects all working together. This means a ship exploding can look like this (click to enlarge)


Which I’m pretty happy with. Those particle effects are all a mess, placeholder stuff that I can fix easily once I’ve rebuilt my editor for them. Plus I need to add a lot more stuff, and also those ships are obviously just modified GSB 1 ships not designed to take new lighting capabilities into account fully. I also need to fix some boxy depth-of-field artifacts for the distant asteroids. Next on today’s agenda is likely to be getting ship hulks to cast shadows (easy!) and then work on letting hulks drift in pseudo 3D (towards or away from the camera, but always planar, as they are sprites after all :D).

So what was the solution? Well it was as I suspected (amazingly). I just needed to take the key scene objects, the hulks, the ships, the turrets (which are separate items) and the asteroids and draw them to my own depth buffer. I then set that depth buffer to be texture layer 2 when rendering the smoke & flames (so that I can reference it in a shader) and just set alpha to 0 for any pixels where the depth buffer is closer than the particles I’m drawing. Right now I’m using a manually created and rendered-to depth buffer, so it’s actually a render target. You can’t in Directx9 have a z buffer that is a render-target, so I might experiment later with toggling the z enable on and off and using a standard directx zbuffer. I’m guessing that internally the card drivers can simultaneously render to a dedicated Z buffer AND the current RT, whereas if you use a manually created RT it’s a separate call. It’s no big deal because I build up a ‘deferred’ list of depth buffer render objects in the engine anyway, but it would let me reduce my video memory usage.

To recap, I’m doing all this because I want the smoke effects to be rendered last, so I can do some clever-ass light compositing that excludes them, such as laser beams lighting up the ships they pass over.

Non-Programmer version: “Blah blah geeky geeky…Explosions!” :D


2 thoughts on Yay depth sorting (kinda!)

  1. The screenshot is looking great, I can’t wait to see one with ships that can properly take advantage of all your new lighting code.

    Also, as a programmer, I can still get behind the idea of “Blah blah geeky geeky… Explosions!” :)

Comments are currently closed.