Jump to content


Multipass lighting approaches (GLSL)


3 replies to this topic

#1 kulik

    Member

  • Members
  • PipPip
  • 41 posts

Posted 10 March 2006 - 08:40 PM

Hello,
I am currently researching and improving my engine's multipass lighting.

My current aproach:
1) render ambient w/o texture
2) add directional light w/o texture
3) add point light w/o texture
4) add spot light w/o texture
5) modulate using "decal" pass w/ texture

However this one is very limited. Especially for specular highlights.
For example if my texture is all the way black, the result will be black too. If the texture will be gray, result will always have colors equal or darker than gray.
You know what I mean ...

While just shooting in the dark I discovered that if I modulate (in the last decal pass) source color with destination color and destination color with source color (glBlend( GL_DEST_COLOR, GL_SRC_COLOR ) ), the result seems much better (I can see the highlights). However I know that this is very unrealistic and limited.

I though about rendering diffuse first (additive like the approach up there). then modulate using decal and then render only the specular highlights (additively again).

I think this would do the trick. However that means each object will be rendered using 2 + num_lights * 2 passes, which is very high and will probably be very slow.

Are any of you aware of some better approaches? I am using GLSL. I tried to google but it brought no usable results. Thanks for your help.

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 10 March 2006 - 10:17 PM

I would go ahead and multiply the texture in each stage, and render a light in each pass. E.g. (1) ambient * texture, (2) light1_diffuse * texture + light1_specular, (3) light2_diffuse * texture + light3_specular, etc... If you're using GLSL there is no reason to split things up so much, as you can do pretty much arbitrary lighting calculations within each pass. You could even have two lights per pass which could help speed things up in the case you are vertex-limited (also check out deferred shading in that case).
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 juhnu

    Valued Member

  • Members
  • PipPipPip
  • 292 posts

Posted 11 March 2006 - 02:51 AM

What if you rendered all the lights to an offscreen render target and blended it with the "decal scene" in a post processing step. This way you could use alpha channel of the light render target for specular strength.

DestBlend = SrcColor
SrcBlend = SrcAlpha

#4 kulik

    Member

  • Members
  • PipPip
  • 41 posts

Posted 11 March 2006 - 09:35 AM

I just tried method pointed by Reedbeta and it seems to work very good. Speculars show up how they should and so on. It has even cut off number of passes to 1 + num_lights :) Speed appears to be equal to my crappy 3 pass method.

@Reedbeta:
Thanks ;)

@juhnu:
I will definitely try deferred shading in the future, thanks for pointing this one
The Eleventh - completely open source RPG game
Tenuity3D - cross-platform OpenGL game engine





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users