View Full Version : Light radius

Catman

02-11-2003, 02:42 AM

Hello! I'm trying to make a light source which has a light radius. This means that the light should be attenuated according to the distance from the center and should completely fade away at distance = radius. I found an equation on the forum, but with it the brightness is only halved at distande = radius... I need this because I only want to enable those lights that really affct the lighting of the model. I'd appreciate any suggestions on how I should do this...

JustHanging

02-11-2003, 03:11 AM

Hi,

According to the physical model the light doesn't get totally attenuated at any distance, but you can turn it off when it's contribution gets smaller than a certain tolerance.

Another option is to calculate the attenuation by hand, making it for example linear. If you're lighting objects relatively small compared to the light's radius, you can disable opengl attenuation and adjust the light intensity for each object according to your own function. One possible formula to calculate the attenuation factor could be

a=1-distance/lightRadius, clamped at 0

That's very wrong physically speaking, but might give you the result you want. Taking a square root of the dist/radius term might give a more realistic intensity curve.

-Ilkka

Try this out:

intensity = cos (90° / maxradius * distance)

where "maxradius" is the maximal radius and

distance is the real radius at a position (so 0 <= distance <= radius).

Intensity is a value between 0 and 1 and is used to scale the light.

At a distance of zero, intensity will be 1 and at distance = maxradius it will be 0. However because it is a cosine function, the fall-off should look quite realistic.

Note: The distance is not allowed to get bigger than "maxradius" or the intensity will grow again.

I didnīt test it, itīs just an idea.

Jan.

bakery2k

02-11-2003, 05:28 AM

I use 1-(distance/radius)^2 for my lights. This however only gives an attenuation factor of 3/4 at 1/2 distance.

V-man

02-11-2003, 06:01 AM

Originally posted by Jan2000:

intensity = cos (90° / maxradius * distance)

As distance, gets larger, the part in the parenthesis gets closer to 0 and cos(0)=1

so the intensity will be at maximimum far off.

Now if you try sin instead of cos, you get something that looks more reasonable. But why use trig functions for something so simple?

If Catman wants to manage the lighting himself, he could just use 1/radius^2. Do a quick test to see if the object is farther than your limit radius.

DFrey

02-11-2003, 07:30 AM

Look at that example again V-Man, cos as he has it written does make sense. It does satisfy the constraints the original poster specified.

Originally posted by V-man:

As distance, gets larger, the part in the parenthesis gets closer to 0 and cos(0)=1

Wrong.

Say maxradius = 150

Say distance = 150

This yields to:

90 / 150 = 0,6

0,6 * 150 = 90

cos 90 = 0

However if i had written this:

intensity = cos (90° / (maxradius * distance))

you would be right.

Next time look more carefully, i donīt want to have to explain everything in detail everytime.

Jan.

Catman

02-11-2003, 10:29 AM

Thanks for the replies, but I just want to use the standard opengl functions... I don't want realistic lighting, I only need what I wrote in my previous post. Another option would be using a vertex program and make a simple linear fade off (I haven't used vertex programs yet, so I don't know if it would work...) But I don't know if it would be as fast as standard opengl lighting...

V-man

02-11-2003, 07:52 PM

Originally posted by Jan2000:

However if i had written this:

intensity = cos (90° / (maxradius * distance))

you would be right.

Yes, it was a mistake on my part. For some reason I looked at as

intensity = cos (90° / (maxradius * distance))

Disregard.

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.