Best Dynamic Lighting Setup?

Blitz3D Forums/Blitz3D Programming/Best Dynamic Lighting Setup?

ClayPigeon(Posted 2010) [#1]
Hey! I have been using lightmaps in my games for a while now, and I think they look nice. The only problem is that now I need dynamic lighting, but shadows add a great deal of realism. Trashing the shadows is like taking the plate out from under your spaghetti and expecting someone to eat it off the floor!! The only method I've thought of so far is to make the lightmap slightly transparent, so that even the darkest of places will be visible when I light it up. Now, that won't work, because then the parts on the outside of my island will be dark because if I set it to full-bright, then it can't be lit any brighter. I just want to have a point in the game where the player gets into a pitch black cave, and finds a handle which, when pulled, makes a glowing liquid flow into a bowl. As this is happening, I just want to have a greenish point light in the center of the cave slowly increase its intensity so the the cave is dimly visible. Is this possible?


Ross C(Posted 2010) [#2]
Well, the only way i can think, and which i did try (far too slow though!) was to generate a realtime lightmap, and blend it down onto the existing lightmap. That way, it should cancel out the existing black areas. I tried making the lightmap from the light source, very low resolution.... meh. Was too slow and pretty ugly...


ClayPigeon(Posted 2010) [#3]
..feel free to say "It's not possible." or "There's only one way, and it's not practical - try this instead:". I didn't mean to scare you!


_PJ_(Posted 2010) [#4]
It's really not 'correctt', and very much a cheat-kludgey workaround, but perhaps you could kill (hide) the ambient light and any other lights while the player is in the 'dark room'.
As the bowl fills, place the green light (starting off at 0,1,0 and increasing) and raise the ambient light back up too?


ClayPigeon(Posted 2010) [#5]
I don't think that will work, because the player needs to be able to see the handle to turn on the faucet, so I have light streaming in from the entrance cave just far enough for the player to dimly see the handle and nothing else. If I hide the ambient light when I get in, the light in the entrance cave will suddenly go dark.


Sledge(Posted 2010) [#6]
You can switch lightmaps programatically and you can also use EntityColor to 'light' fullbright objects (which is what your lightmapped objects should really be) -- this should be all you need. I'll rustle you up an example if you give us a mo.

If I hide the ambient light when I get in, the light in the entrance cave will suddenly go dark.
The player isn't going to be looking in that direction because you have the handle to misdirect them. You could also start the mixed-light lightmap off with a high enough entity colour that the entrance looks fine. Or you could seal the entrance. Or have the entrance around a corner etc. There are a myriad of options.


Kryzon(Posted 2010) [#7]
Perhaps not putting the cave to fullbright might work, if you balance things well. That way, it will still receive light from the "glow light" you place around the bowl, while retaining the lightmap. That "glow light" being a standard point-light you create.
Also if you think about it, in the real world, when you light something in a place that has shadows from a 'different' light source (like the sun, for instance), these shadows don't go away. They simply become "lighter" (which is what would happen if you don't put the lightmapped cave as Fullbright).

Just make sure to have enough polygons in the cave to actually show the fade-off from that light.

Since B3D uses vertex lighting, the fewer vertices, the less noticeable the lighting is:

Left quad: ~60 triangles. Right quad: 2 triangles.

(both quads had perfectly aligned point lights, but the one with most vertices shows the fade-off)


Sledge(Posted 2010) [#8]
Okay, a very quickly cobbled together example, mostly to show how you switch lightmaps:



Just approach the pedestal to bring up the green lighting. Like I said before, there are a bunch of things you can do to make the transition as seamless as you need. I've uploaded the assets and a pre-compiled exe to this temporary location. Cursor keys to walk about.

EDIT: Removed some peripheral info. One thing at once.


_PJ_(Posted 2010) [#9]
Sorry I didnt realise the entrance to the cave would still be visible.

The ambient light only needs to be dimmed down, then. Really I can see how messing wih the universal-ness of ambient light is a pretty 'bad' thing to do. That's why I thought it may be resetrved for just such a special situation like this.

LightMesh too, which can be used to light an individual mesh without affecting any actual lights or other meshes. Could be done for the tap (faucet)?

Though, Sledge & Kryzon both seem to know a lot more about this kinda stuff :)


Kryzon(Posted 2010) [#10]
Geez, nice sample Sledge.

It must've taken some good-hearted effort to build it. Nice work.


Krischan(Posted 2010) [#11]
Right now I experiment with lightmaps, too. I try to get an effect like in Gothic II, take a look:

Midnight


Dawn


Noon


You always see the same scene - the "trick" is to use this texture order:

Layer0 = Lightmap, Blendmode 2
Layer1 = Brightmap1, Blendmode 3
Layer2 = Texture, Blendmode 2
Layer3 = Brightmap2, Blendmode 5

Brightmap1/2 are two small 2x2 pixel textures updated according to time (night/dawn/noon) using my Blitzsky system and this simple function:

Function UpdateTex(tex%,r%,g%,b%)
	
	Local tb%=TextureBuffer(tex)
	Local rgb%=r*$10000+g*$100+b
	Local x%,y%
	
	LockBuffer tb
	For x=0 To 1
		For y=0 To 1
			WritePixelFast x,y,rgb,tb
		Next
	Next
	UnlockBuffer tb
	
End Function

It makes the lightmap so bright that it "vanishes" below the texture. The disadvantage is that the day scene looks a little bit flat, so I need further tests with it.


ClayPigeon(Posted 2010) [#12]
Wow, nice example. That actually looks like a plausible solution. Of course, it's still kind of "semi-static" as you can't move lights. I have two questions - 1: What if I have multiple places that I want to have lights be able to turn on and off independently? They can't both occupy the same lightmap.. 2: What program did you use to make the lightmaps in that example you made? I make my lightmaps in DeleD which automatically applies the lightmap to the model and sets it to fullbright. It would be a great advantage to be able to apply the lightmaps in B3D as I could modify them though their texture handle.

Also, why is there a need to adjust the ambient light? Why can't you just fade between texture layers?


Krischan(Posted 2010) [#13]
I only used NETRadiant for the level, compiled a BSP with the lightmap using q3map2 (comes with NETRadiant) and converted the BSP to B3D with Ultimate Unwrap (with the BSP plugin). The lamps/flares are seperate models/quads placed using my own BSP parse function to extract the positions. I use linepick to check if the flare crosses the level geometry and show/hide them accordingly.

The B3D mesh is loaded and converted with this function because the lightmap is "above" the texture and so I needed to switch the layers like i described and add my 2x2 pixel brightmaps to the whole mesh:



You can even use EntityFX 2 (my example uses FX 1) and light it with a DX light, but then you need a lot of triangles to get a nice lighting effect. But I'm happy with the static lightmap and even Gothic II doesn't use dynamic lightmaps as far as I see - but the effect is still stunning.

Here is a screenshot with FX2 and a tree mesh lit by the player light:



For multiple places I think you need to use portals/zones with different lightmaps.


_PJ_(Posted 2010) [#14]
Layer0 = Lightmap, Blendmode 2
Layer1 = Brightmap1, Blendmode 3
Layer2 = Texture, Blendmode 2
Layer3 = Brightmap2, Blendmode 5

Brightmap1/2 are two small 2x2 pixel textures updated according to time (night/dawn/noon) using my Blitzsky system and this simple function:


I admit I know virtually nothing about lightmaps and multitexturing etc. but this sounds too good to be true!
Can you explain a bit more about how two tiny textures can have such an effect?


ClayPigeon(Posted 2010) [#15]
Sorry, Krischan. I forgot to refresh before I posted and I didn't see your post. I wanted to know what Sledge used.


Krischan(Posted 2010) [#16]
Malice - it is just the blending order and a proper use of colors which create this effect. Just take a look at this demo (copy the two textures in the same folder) - with LMB and RMB you can increase/decrease the time of day (and so the light intensity). This simulates a full night-day-night cycle.

texture.jpg


lightmap.png





Sledge(Posted 2010) [#17]
What program did you use to make the lightmaps in that example you made? I make my lightmaps in DeleD which automatically applies the lightmap to the model and sets it to fullbright. It would be a great advantage to be able to apply the lightmaps in B3D as I could modify them though their texture handle.
I would normally use DeleD also, but for the example I used Maplet -- it's just a little bit faster for roughs (although you do have the palaver of making texture paths relative). But yeah, DeleD or Maplet, it's just a matter of re-lighting your scene with the various combinations of lights that can occur within, and re-exporting to get each lightmap.

I'm not sure what good being able access the lightmaps will do you -- they're pre-calculated for a reason, unfortunately. :(

What if I have multiple places that I want to have lights be able to turn on and off independently? They can't both occupy the same lightmap.
You would need one lightmap for each combination of lights. So for the example it's either the entrance light alone or the entrance light + green glow, hence two lightmaps. (Obviously this approach entails splitting your scene into discreet sections, but that's helpful for keeping the rendering overhead low so already recommended.)


ClayPigeon(Posted 2010) [#18]
I'm not sure what good being able access the lightmaps will do you -- they're pre-calculated for a reason, unfortunately. :(

Sorry, I should have said that differently - I meant I could apply them more than once, set their layer index, set their blend mode, etc. When they're part of the model, I can't change them at all. I didn't mean perform realtime manipulations, I agree, that would defeat the whole purpose.

You would need one lightmap for each combination of lights.

I'm not so sure about that. If there are many dynamic lights in the scene, that could defeat the whole purpose too - backwards support for older systems. Think about how much space that could potentially take up.
eg:
2 adjustable lights, 2 states for each, 2*2=4 -sure, OK, just 4 lightmaps
but,
8 adjustable lights, 2*2*2*2*2*2*2*2=256 -that means you need to make 256 lightmaps. -woah.

If I exported each section of the level that was affected by each light, each could have their own on/off lightmap. That way, I could change the lightmap for each separate model without ridiculous amounts of lightmaps. Unfortunately, that would not work so well with lights whose range overlap.


BIG BUG(Posted 2010) [#19]
How to combine Blitz Lights with lightmap:

Store your lightmap in the first layer and use TextureBlend 3 so it will be added to the Blitz lighting.
The regular level texture uses the second layer and gets multiplied with the lightmap.
Set ambient light to black.

Here an example which shows the necessary setup(1.4 MB):
http://www.mein-murks.de/software/Donut.zip


ClayPigeon(Posted 2010) [#20]
That's actually a really good idea, and it would work well, except I can't get the model to have fullbright turned off. I think I need to use gile[s] because I've seen choices in it to turn off automatic fullbright. It just doesn't make sense sometimes. Sometimes, I set the model to have lightmap instead of vertex lighting, and I set it to cast shadows and all, but when I render, it doesn't show anything. I need a good tut for gile[s], because I can't seem to find one with Google..


Kryzon(Posted 2010) [#21]
Oh, there aren't any tuts for it - you're not alone, that crushed my heart too (well, there is a simple one, I think it comes with the program or is in the help file or whatever).

You're better off practicing yourself - in the end, it's somewhat simple to use. Only trust the viewports right AFTER you render the lightmap, if you made any changes in your scene.


ClayPigeon(Posted 2010) [#22]
Well, I don't know how its directional lights are set up, but I created a direction light as the sun for my level and rendered it, but everything stayed dark. Then, I moved it closer, rendered again, and got a light streak across my mesh. (??)


Kryzon(Posted 2010) [#23]
Yeah, the preparation of the scene might be the hardest thing with Gile[s].

I think you should start with everything small.

Put the directional light\any light you'll use really close up to the mesh (almost touching it), then go bringing it far away, increasing the far value, adjusting the intensity etc.


ClayPigeon(Posted 2010) [#24]
Well, what I can't figure out is how to make a directional light in Gile[s] that is basically like a sun. Whatever angle I set it to it will shine light indefinitely. I know it's possible, I just can't figure out how to do it.


Oiduts Studios(Posted 2010) [#25]
Same here, there are no tutorials and it seems complicating. When you place a light you can not see it, or is that just me? I have had it for about 2 months and kind of gave up on it but I would love to be able to use it.


ClayPigeon(Posted 2010) [#26]
I don't see a light when I place one -- the only way I can tell it's there is when it's selected, it gets a white box around it, but that's about it. You can select it from the panel to the right.


Sledge(Posted 2010) [#27]
I'm not so sure about that. If there are many dynamic lights in the scene, that could defeat the whole purpose too - backwards support for older systems. Think about how much space that could potentially take up.
eg:
2 adjustable lights, 2 states for each, 2*2=4 -sure, OK, just 4 lightmaps
but,
8 adjustable lights, 2*2*2*2*2*2*2*2=256 -that means you need to make 256 lightmaps. -woah.

If I exported each section of the level that was affected by each light, each could have their own on/off lightmap. That way, I could change the lightmap for each separate model without ridiculous amounts of lightmaps.
Well that's exactly what is meant by "splitting your scene into discreet sections", so award yourself a big fat Fail for English comprehension (I blame the teachers) but also a pat on the back for independently arriving at the same conclusion. :D

Nevertheless, within each discreet section, you'll still need a lightmap for each possible lighting state. Given this, one possible way of keeping the total number of lightmaps minimal (taking it as read that more than a couple of lights per area is MADNESS) would be to construct your levels from prefabs -- hence many sections of your level(s) could share lightmaps while being textured differently for variety.

Unfortunately, that would not work so well with lights whose range overlap.
Then don't have them overlap; Keep them discreet, distinct, separate from one another. :D

Really this is half the battle -- recognising the constraints of the technology at your disposal and working within them. As soon as you aspire to any kind of dynamic lighting it will immediately start to dictate level design, mostly because it's so costly to get them to appear to interact.


ClayPigeon(Posted 2010) [#28]
Well, it appears that the example BIG BUG posted might work well.

award yourself a big fat Fail for English comprehension

I wasn't sure what kind of 'sections' you were talking about. (mesh? lightmap? texture??)


Sledge(Posted 2010) [#29]
I wasn't sure what kind of 'sections' you were talking about.
Yeah I know. It's annoying to have what you said repeated back at you as if you didn't say it, but kinda unavoidable given our multifaceted jargon. No sweat.

the example BIG BUG posted might work well
Depends what you're after as vertex lights won't cast shadows, but that could still be a good fit for your cave scenario. Bear in mind that vertex lights aren't free, though -- you might be able to get the effect you want just by altering the colour of the cave's interior (ie from dark grey to brighter green), no light-map swapping or vertex lights necessary.

Tangentially, there was an example of "shining" a vertex light onto a surface and having it burn through to an underlying texture posted yonks ago. I'll just mention that in case it jogs someone's (the author's?) memory as I can't remember the specifics.


Yasha(Posted 2010) [#30]
there was an example of "shining" a vertex light onto a surface and having it burn through to an underlying texture


Quake II did this, I think? Vertices (or points of some description - Quake II obviously not using the same 3D system as Blitz) attached to the walls at the location of each lightmap pixel, and then the lightmap updated with the lighting of each such vertex...? (i.e. not actually using hardware lighting at all - the vertices are just "lit" using background maths).

EDIT: I remember this got my attention for two reasons: 1) Q2 is astonishingly fast on modern hardware even in software-rendered mode, so dynamic lightmaps can't be that slow; and 2) the only hard/slow part of this is working out the 3D coordinates of a given lightmap UV, which you can pre-calc with the rest of your lightmap (tedious but not actually very difficult).


ClayPigeon(Posted 2010) [#31]
Depends what you're after as vertex lights won't cast shadows, but that could still be a good fit for your cave scenario.

All I'm trying to get is dynamic lighting accompanied by a precalculated lightmap, and so far, vertex lighting seems to be doing the best. If Blitz lights had shadows that would be GREAT! ..but yeah, they don't. Bummer.