Multipass rendering question.


So I’m having a problem that I’m not sure how to get around. Basically, I’m trying to implement dynamic lighting (using the projected texture approach). The problem comes when I start applying extra passes from the (Quake3-style) shaders on top of this. Because the shader layers use a blendfunc of GL_SRC_ALPHA/GL_ONE_MINUS_SRC_ALPHA, they lose the color from the base/lighting pass. Of course, if I use the same blendfunc as regular surfaces (GL_DST_COLOR/GL_ZERO), then it just looks wrong.

The lighting itself looks quite nice, though (I took the algorithm from an old Nate Miller tutorial):

I don’t suppose there’s a simple way around this, is there?

Oh, so the passes look like this:

  • base color pass (GL_ONE/GL_ZERO)
  • pass per light to add light to base color (GL_SRC_ALPHA/GL_ONE)
  • texture modulation pass (regular surfaces and first shader layer) (GL_DST_COLOR/GL_ZERO)
  • n layers (configurable blend func)


You need to figure out either how to get all the Quake 3 shaders into a single pass, or all of the lighting into a single pass.

Perhaps easiest is if you render lighting first, and copy it to a texture, then render the Quake shader with full-bright lighting, then render the copied texture on a full-screen quad using GL_DST_COLOR,GL_ZERO blending.