Is there a 3rd party lighting system for Blitz?

Blitz3D Forums/Blitz3D Programming/Is there a 3rd party lighting system for Blitz?

puki(Posted 2006) [#1]
Considering all the systems that have been made - is there a 3rd party lighting system?

I am doing dungeon sections of my RPG and I don't want to use lightmapping too much as I am a fan of unlit tombs/caverns/dungeons, etc - not like in commercial games whereby every place that is uninhabited always seems to, amazingly, have torches burning along the walls.

I am having completely black/unlit areas where I want the player to carry light with them - which is more realistic.

The best success I have had so far actually works quite well - I parent a flickering 'Directional' light to the camera. This sucker works as I have restricted the camera view distance inside the unlit areas - backed up with a bit of black fogging - it works really nicely and reasonably realistically.

What is good about using the 'Directional' light is it evenly (realistically) lights surfaces as you turn - unlike using point and spotlights that do not always do this.

The key to my system is the fact that I am restricting the 'CameraRange' which stops the player seeing the fact that the lighting is going on far, far into the distance. It works very well.

However, I may want NPCs to have their own light in the same way as the player - this presents a problem - I cannot restrict the light given off by an NPC - considering the lighting within Blitz passes through walls, regardless of the type of light, and has a habit of reaching further ahead than what you want it to, etc.

It's not a major problem - considering the main thing is getting the player's light to work and look okay.

Anyway, anyone have any lighting tips for me?


Danny(Posted 2006) [#2]
Hi Puki,

I've got a similar problem and demands like you..
I agree that the NPC's (or items) should be able to affect the local lighting - just like the player, else it wouldn't make any sense.

I've done some tests using Sprites to create fake light sources (and not be limited by the 4 or 8 directX lamps). Basically by creating a large soft glow-type additive sprite at the source. Doing this very subtle can create a nice illusion of a light source.

Another good thing is that you can control the radius, density, even add a bit of texture very accurately. You can animate it's transparency, intensity and color very simply giving a nice optical effect.
So for the cliche torch with some particle-flame for example you can have the sprite use the same colors/flicker as the particles giving a really nice effect.
Instead of a torch you can use this for a dynamic moving object as well like a candle being held by the player or an NPC.

But in tight spaces the sprite will start clipping with the walls, unless you hide / fadeout sprites hidden from the camera, the sideeffect of this will be that 'an area around the corner will go dark again' even though it should remain softly lit.
Another limitation is that you can't really control it's shape or direction in 3D, it works only as a radial source.
So it has it's downsides as well.

I haven't had time to really test a system like this, but I think it's got some use/potential for sure..

my 2 cents,
Danny


sswift(Posted 2006) [#3]
Well first off, the problem you are having with things not being evenly lit with point lights is probably due to the fact that vertex lighting needs a lot of vertices to get the light to look proper, and you probably only have vertcies at the corner of each wall. The more you subdivide each wall, the smoother and more correct your vertex lighting would be.

Second, and this problem is in direct conflict with the first, the way you "restrict" light cast by NPC's is to have the lights cast shadows. Now, you can't use a system like my shadow system for this. We're talking proper shadows here. And to cast proper shadows what you need to do is light every vertex individually and manually. But before you calculate how much light is hitting an individual vertex, first you need to dtermine if said vertex can see the light source. And you can do that by using linepick. If a linepick from a vertex to a light source picks a polygon, then the light is blocked.

But that is bound to be really slow. For one, you've got thousands of vertices you need to do linepicks for. And for another, you've got thousands of polygons which each of those linepicks must check to determine if a collision has occured.

Now there are ways to optimize this. I for one would divide the world into a 3d grid where in each cell I place a list of all polygons that pass through that cell, and then I would dtermine which cells my line passed through which is really fast, and check only those polygons contained in those cells.

Now if you do that, you're still checking thousands of vertices, just against maybe 10 polygons each instead of thousands. But this might be fast enough for realtime.

HOWEVER, even if you solve that problem, there's another problem, and that is that when you adjust a mesh, the mesh has to be uploaded to the 3D card again. And that's slow. Very slow. Especially if the mesh has thousands of polygons. Updating a single 64x64 grid containing a mere 8192 polygons is too slow if you intend to do it every frame, and you can't do just part of it one frame and part of it the next, so at best you'll have spikes in your framerate. That is, unless you divide the mesh up into smaller meshes and cen get away with just altering a small mesh each frame as a result. But that might be hard or impossible to accomplish depending on how your levels are designed.

So is there any way you can accomplish this? Unless your levels are very simple, probably not by altering vertex colors.

You may however be able to accomplish it with low res lightmaps. You would basically be calculating lightmaps in realtime. But they would have to be low res so you don't have to calcualte too many rays, and you would have to implement the system I described above for quickly determining when rays hit walls.

I think some user did something like this with lightmaps for their dungeon game, but the shadows were so low res it didn't look very convincing. I don't know if they optimized it much though the levels were fairly simple. Anyway, if you kept your lightmap down to say 512x512 for your whole level then that would be a mere 262144 rays that you need to cast each frame to update it. :-)


Scherererer(Posted 2006) [#4]
hmm, I tried to do this some time ago... There is a vertex lighting command that I tried to use, however the only way I could think to use it and be able to make walls repel the light was through line picks, which isn't very practical in a large environment. I think you could get away with the DX lighting system (using point lighting), if you made the light ranges a bit shorter and always had a decent amount of space between parallel hallways, atleast enough so that if the torch was near the wall it wouldn't bleed onto another room/hall.


OJay(Posted 2006) [#5]
stencil shadows are your friend! a guy over at codersworkshop has released a system, that will do fine here.