Render objects to buffer stencilled by objects in front

Dear fellow Panda users,

I’m making a game with a scene with aircraft on an airport seen from above (45 degrees view). What I’ve been trying to accomplish is apply cg shaders to the airport lights to give them a bit of a glow and maybe a subtile star. Applying a shader to the airport lights node is very easy and works, but applies the effect in the ground plain, the plain on which the lights are. I want the effect to show in view plain. This led me to rendering the lights to a buffer. However rendering them to a buffer causes the lights to be shown in front of the rest of the scene, including the objects which should be in front of the lights.

I’ve tried so far to the share the depth buffer with the scene buffer and the light buffer as discussed here [[resolved] Share Depth Buffer) . I got this to work, the share depth buffer returned True but it didn’t give the expected result, the lights were still over the objects.

I’ve also tried stencilling, but not succesful and I don’t know if this is the right approach.

Any push in the right direction would be highly appreciated, maybe there’s an easier way to do this, or a more efficient way? Hope somebody can help!

It sounds like what you really want is a postprocessing effect, perhaps writing some special information in your main scene shader to the alpha buffer or some auxiliary render target and then using that to selectively apply a blur effect in a postprocessing shader.

Panda already supports this. You can configure the shader generator to write glow maps into the (unused) alpha channel of the main scene. You can also use the CommonFilters bloom filter by setting it to weight only the alpha channel of the main scene, or you can set it to bloom particularly bright spots (which is interesting if you want to go for HDR rendering), or you can use FilterManager and apply your own custom bloom shader.

Is this what you mean?

Yes this is what I mean. After some struggle I got it all to work. Thank you for your advise!