How to implement point lights?

I’m wanting to draw a point light. Or, in other words, I’m moving a little light source around and I want it to emmit light around it but not infinitely so. I just want it to cast light on objects that are nearby only. How can this be done in OpenGL?

Main thing is to set the light’s w value to 1.0 (other values are possible but for simplicity choose 1.0). When w is 0, OpenGL makes the light a directional light. When w is not 0 then it makes the light either a point light (if GL_SPOT_CUTOFF is 180) or a spotlight (if GL_SPOT_CUTOFF is in [0,90]).

Great! Thanks! So, real quickly, what’s the syntax to set those SPOT_CUTOFF params?
Is it glLightf(GL_LIGHTx,GL_SPOT_CUTOFF,num)?

BTW, it looks like you’re becoming my own personal OpenGL tutor. :slight_smile: Anyway, thanks!

[This message has been edited by Punchey (edited 02-09-2001).]

[This message has been edited by Punchey (edited 02-09-2001).]

If I wanted light 0 to be a spotlight with a 20 degree field I use:
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 20);

If I wanted light 0 to be a point light, I would use:
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 180);

180 is the default angle so you normally don’t need to set GL_SPOT_CUTOFF for point lights.

And of course the above code works as indicated only when w is not 0.

Okay, I tried all of this and found that while doing what you said will make it a positional light, it does not cause the amplitude of the light effect on more distant objects to diminish. The only way I figured out how to accomplish this is to set the GL_QUADRATIC_ATTENUATION to something like 0.001f. Anywhere far from this value lead to undesireable results either too much light or way to little. I suppose this depends on the scaling of your world. But is this the one and only method by which you can achieve lighting dependant upon the distance from the lightsource? Or is there a better way?

No, attenuation is the way to go.

Why should I preffer no attenuation? I need a light, the effects of which grow more weak as the distance from the light to the object increases. I don’t want a light that stretches on infinitely. I’m doing an outer space thing and I have a missile that casts light but I don’t want the missile to be as bright as a freakin’ star so I need the light intensity to fall off as distance grows. What is the reason I would preffer no attenuation and is there a better way to achieve this effect perhaps without GL_LIGHTs?

Humus said that attenuation is the way to go.

If quadratic attenuation isn’t working very well, you can also factor in linear attenuation.

j

Originally posted by Punchey:
Why should I preffer no attenuation?

Humus wrote: “No, attenuation is the way to go” and not “No attenuation is the way to go”.

He answered your question: “Is there a best way ?”.

The answer is: “No.”. And the comment is: “Attenuation is the way to go.”.

Regards.

Eric

P.S.: Humus, was it you that asked all those questions to nVidia at SharkyExtreme ???

Oh, I see now… sorry, I feel like an idiot. As it was once said on this board, show me the opening in the ground so I may get into it. :slight_smile: In that case, thanks! I guess that answered my questions… except, what’s this about linear attenuation? I couldn’t get that to work right when I was trying it. But then again, I probably didn’t try a parameter that would work for my case. Also, probably due to poor drivers, I tried my attenuated version and it didn’t seem to attenuate AT ALL on my Voodoo3. You think this is yet another example of HORRIBLE OpenGL support by 3DFX?

The attentuation model is quadratic in nature meaning it has a quadratic term, a linear term and a constant term. You can set the coefficient for each term.
Oh and here is a method I found handy for determining the terms with little need for fine tuning. Using Paint Shop Pro, (and I would assume Photoshop would work too), I can create the type of gradient I want and save it as a 256 x 1 raw grayscale picture. Then feed that raw data into your favorite statistics package to calculate the quadratic regression and then give the coefficients so calculated to OpenGL (after rescaling them).

[This message has been edited by DFrey (edited 02-12-2001).]

Originally posted by Eric:
P.S.: Humus, was it you that asked all those questions to nVidia at SharkyExtreme ???

Yes, it was me.
I like their forums, and their “Ask the industry” topics are really nice.

DFrey, What sort of statistics packages are there that are good/cheap/free? I don’t have one. I suppose I should get one eh?

Originally posted by Punchey:
Oh, I see now… sorry, I feel like an idiot. As it was once said on this board, show me the opening in the ground so I may get into it. :slight_smile: In that case, thanks! I guess that answered my questions… except, what’s this about linear attenuation? I couldn’t get that to work right when I was trying it. But then again, I probably didn’t try a parameter that would work for my case. Also, probably due to poor drivers, I tried my attenuated version and it didn’t seem to attenuate AT ALL on my Voodoo3. You think this is yet another example of HORRIBLE OpenGL support by 3DFX?

It could very well be that. I had the same problem with my Matrox G400, and when I mailed them about the problem they did almost not seem to want to fix it. Probably it’s because it reduces the performance a lot without a T&L unit, and isn’t used by any games AFAIK.

I’m not aware of any freeware packages though I’m sure it does exist. I know there is a free 30 day trial of MatLab at http://www.mathworks.com/products/matlab/
However I do not know if the trial is crippled in anyway other than time. I myself would buy an older release of Maple or Mathematica. You can find those for very little money (if you can find them at all). I was lucky and was able to use my student discount for the full version of Maple IV a few years ago. Some cheap scientific calculators could also solve for the quadratic fit, though you’d have to enter all those data points by hand .

I wondered if it slows things down… perhaps I’m better off not using it. So if no games use that technique, what technique IS commonly used for things like missiles flying past objects and illuminating them? I havn’t been able to figure out lightmapping of complex-shaped objects yet. As for the G400, I’m testing with a G450 right now and it works (albiet I had to get the latest drivers).

Oh, they finally got it in there? Cool … it did never work for me, and that was even up to PD6, 6.10 was the last driver I tested before I upgraded to a Radeon.

The common tecnique used is lightmapping, even for the dynamic stuff.

Can someone point me in the direction of some good lightmapping info? All I’ve been able to find is info on how to do lightmapping on flat surfaces such as walls/ceilings/floors. But it seems to me that it would be VERY CPU intensive to properly use a lightmap on a more complex object. i.e. an object with alot of polys that make up a very curved surface. Or do modern game developers only use lightmaps on objects that are relatively flat such as floors?

Most modern games only use lightmaps on static geometry. On dynamic models, procedural lighting is typically used, either OpenGL’s (or D3D’s) lighting model, or a custom solution.

[This message has been edited by DFrey (edited 02-12-2001).]

Okay, so that raises the question: is there a way to use more than 8 lights? Is there any sort of trick that can be used to exceed this limit?