Blitz Lighting Equation

Blitz3D Forums/Blitz3D Programming/Blitz Lighting Equation

sswift(Posted 2003) [#1]
This is the equation Blitz uses for lighting. It might come in handy if you want to mimic it's lights with your own vertex lighting.

This is the DX lighting equation:
a = 1 / (c0 + c1*d + c2*d*d)

In Blitz c0 and c2 are 0, and c1 is 1.

This gives a falloff like this:
http://mathworld.wolfram.com/GabrielsHorn.html

Where at a radius of 1, a = 1, beyond that radius it falls off quickly, expoentially I beleive it's called, and inside that radius it increases until it reaches infinity where d = 0.

Since c0 and c2 = 0 the ligthing equation can be simplified to:

a = 1 / d

And then we add the light radius like so:

a = r / d

And then once you calculate that for a particular light, you just multiply the light RGB by a.

(All of those should be floats btw.)


So:

Light_Falloff# = Light_Min_Radius# / Vertex_Distance#
Vertex_R# = Light_R# * Light_Falloff#


Also note that the help file is mistaken on the light radius when it says that is approximately where the light falls off to 0. In actuality, the light falls off to 1 at 255*Light_Radius.

It falls off to 0 at infinity, but because colors are clamped to integers, the oint where it goes below 1 is where it gets clamped to 0.

So for a light radius of 20, the light falls off to 0 at a distance of 5100! Ouch. :-)

It falls off to less than that much closer though.


Beaker(Posted 2003) [#2]
sswift - do you mind if I add this to the light help or the FAQ?