I've made a shader for a racing game in Unity that billboards a headlight glow effect (the lights are not actually light sources so I can't use lens flares). The quad with the glow texture is rotated to always face the camera but attenuated by the angle between the original normal and view direction so it only appears when facing the camera. I noticed when viewing from an angle that parts of the billboard were being occluded by the car so I set it to 'ZTest Always' to prevent this.

This all works fine, except there's a part where new cars are delivered by truck, and the lights are glowing through the truck door before it opens :-(

I tried re-enabling Z-testing and manually tweaking depth in the vertex shader after the MVP matrix multiply, but can't find a sweet spot that doesn't cause either one problem or the other at some point.

So I'm wondering if there's some way to have a moving occluder for occlusion culling in Unity. This way I could have the billboard occluded by the door until the point that it opens. The docs mention 'occlusion areas' for dynamic objects but this seems to refer to moving objects being occluded by static geometry, I'm not sure if it works the other way round.

Otherwise I guess it will have to be some kind of animation script that activates the lights at the exact moment the door opens...

EDIT - this sort of thing

enter image description here

  • \$\begingroup\$ Can you show us a case of the car occluding its own headlight glow, so we can visualize the artifact you're trying to correct? There may be a local fix that doesn't rely on occlusion testing. \$\endgroup\$
    – DMGregory
    Apr 13, 2016 at 4:17
  • \$\begingroup\$ there ya go :-) \$\endgroup\$
    – russ
    Apr 13, 2016 at 10:06

1 Answer 1


Have you considered and/or tried using an emissive material for the lights?

I haven't done so before, but it seems like you could just have two materials for the reflectors and/or the light bulbs (sphere primitives). I suspect either of these would produce superior results with much less "magic". This will allow you to rely on standard occlusion/culling to take care of the rest (the car is not rendered through the truck, therefore the emissive material wouldn't either). As a bonus, emissive acts like a real light, even though it's not, and will even apply lighting to non-static objects. I also have not tried this, but the standard lens flares may work very well with it.

Doing the reflectors, the "off" material would be reflective, and the "on" material, emissive.

Doing spheres, don't draw the spheres when "off" (reflective reflector material is visible) and use emissive when "on".


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .