more then 8 lights

Blitz3D Forums/Blitz3D Programming/more then 8 lights

MSW(Posted 2003) [#1]
thanks to Gile[s]!

I think I found a way to give the illusion of multiple lights in a level while useing only one hardware light...it's a trick basied on what id software did for the first Quake game...

You would need a level that uses lightmaps for "lighting" a level (second set of U,V cords for the lightmap, etc..)

I discovered this while playing around with Gile[s] trying to get surfaces to act as light sources (great program, BTW)...dunno if others have figured it out yet...but I'll post this anyway to give you all some ideas...

You need a game level with lightmaps, and one hardware light (just a directional one to shine light down onto your entities)...

basicly for each entity in the level you do a linepick strait down to the level mesh, get the triangle and calculate the pixel cords for the lightmap texture (use second set of U,V cords)...then find the color of the lightmap pixel at those cords...then entitycolor the entity with that color!

This will seemingly change the light color and intensity of the entity...a dark lightmap value will make the entity seem in shadow...a bright red lightmap value would make it look like it was in light with a red light...a full on white entitycolor value would make it look "normal"...this works because by default entities are full white and textures are rendered with the multiply flag by default (meaning that the texture acts sorta like a lightmap on the entity by default)...I don't own Blitz3D yet (come on X-Mas money!), but playing around with the demo and a "find texture cords" routine here, shows that it could work out nicely I think...not truely accurite, but should work for most things...

to speed things up when loading the game level, copy the lightmap to a bank or array, this way you can get the lightmap values without locking the texture and readpixel fast...which would be slower then a simple look up in an array or bank...

Hope this helps, and sorry if this was pointed out earlyer.


Caff(Posted 2003) [#2]
Yes, this is in fact a good idea.

In fact, see this implementation on Blitzcoder for an example.


DarkEagle(Posted 2003) [#3]
i replied to this, i know i did.


Rob(Posted 2003) [#4]
It's a good idea. However it is likely to make mistakes where there is a huge drop - the linepick will return the colours at the bottom of the level, while the character is at the top.

I had been investigating this only very recently and came up with an idea which will involve cubemapping at very low resolution to give my character a radiosity style lighting. It's fairly expensive though.

Another solution I have is virtual lights - you can simply re-use the lights based on a grid or tree to see what lights go where fast.

Any other solutions will be welcome too...


CyBeRGoth(Posted 2003) [#5]
Hey MSW do you have some code that can do this?

I tried with some success, but its not quite right


MSW(Posted 2003) [#6]
CyBeRGoth - sorry don't own Blitz3D yet, so no code...just do a linepick strait down and get the level polygon, from there get that polygons cords and interpolate the linepick location within them, which will give you a approximation of the lightmap pixel to get...not hard at all.

Rob - Yeah it wouldn't be to accurite unless the characters were always on the "ground" (even then there could be mistakes...the ground is dark, but the right type of light exists that should illuminate the characters torso, etc..) plus useing the one directional hardware lightsource to provide shadows on all entities when some would be light from different angles in different locations of the level)...but for a fast sort of action game, or one that isn't trying to be "realistic" this should work fine...

Another idea I had that could work for those situations where the character is flying or falling (where the lighting exibits some mistakes from the great distance between the ground and player)...this wouldn't use cubemapping exactly, and should be even faster then the linepick with lightmap method...but this would use a lot of memory (and to do it properly would mean that you might have to create your own level modeler and/or file formats)....you create a pivot that defines the "World Origin"...and then when a character isn't in a posistion to use the linepick lighting...subtract this pivot location from the character location and divide by the "light sample size"...which should give you a set of values to retrieve a light value from an 3D array...sort of like a 2D tile map but 3D...course you would want a large "light sample size" (sort of like a tile size but a cube or rectangle in shape) so the array doesn't grow too large...and to help improve this you could interpolate the light values as the character moves around and such....could even use this array as a sort of global lighting...set the entity color to it when off the ground...then when on the ground calculate the light value (maybe 20% of the light array value for the location and 80% of the linepick lightmap value, etc...

to save space the level could be broken down into seperate light array sectors...each with their own "world origin pivot" and "box" describeing the 3D area the light array covers...then just checking the character location with these boxes tells you which light array to use...would save some empty array space for areas outside the level and such, pluss allow you to pack in higher "light array resolutions" in certain areas of the level for different effects...

I'm definetely picking up Blitz3D, just got to wait until I get some X-Mas money...this lighting thing was one of the reasons I held off for so long...but I think that this linepick and light array thing would work perfectly for the games I have in mind :D