PDA

View Full Version : Lighting



bobtedbob
11-12-2011, 01:49 AM
Hi

I've had a search on the forum for this but I can't find the answer. I would like to create a light source that only lights items near by so it fades out really quickly. I thought this was possible. I have read this

http://glprogramming.com/red/chapter05.html

My plan was to have a 180 degree spot light, set it to be at a specific position then use attenuation.

The attenuation has a formula

1/ (GL_CONSTANT_ATTENUATION + (distance*GL_LINEAR_ATTENUATION) + (distance^2*GL_QUADRATIC_ATTENUATION))

Does anyone have any good values for these 3 such that you have a bright center and then a rapid tail off brightness (like what a candle would do in real life)

ZbuffeR
11-12-2011, 02:34 AM
Using legacy GL vertex lights like that is not ideal because it is much more constrained compared to GLSL per fragment lighting.

Make sure you use a highly tesselated "ground" to check the attenuation, to avoid pitfal 2. Poor Tessellation Hurts Lighting (http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/).

Then the idea about attenuation is to forget about quadratic and constant, and just play with linear. Less realistic in theory, but much easier to control and in practice more realistic as it will simulate some gamma correction.

bobtedbob
11-12-2011, 03:30 PM
Thanks, I've played around but there isn't really a good setting that I can find, the room I have have has so little variation in light its not distinguishable. Can you recommend any good places to find out GLSL information on how to get some good lighting effects?

Alfonse Reinheart
11-12-2011, 03:58 PM
Can you recommend any good places to find out GLSL information on how to get some good lighting effects?

Well yes (http://www.arcsynthesis.org/gltut/), but you're not going to be able to just drop it into your existing code. It's intended as an in-depth tutorial, not a copy-and-paste annex.