Dynamic lightsystem with shadows!

Blitz3D Forums/Blitz3D Programming/Dynamic lightsystem with shadows!

ChrML(Posted 2004) [#1]
About a week ago I played Splinter Cell for first time (yeh, late, I know), and I got really amazed about the lighting effects, and started wondering what they did to make a system like that that fast.





As you can see, it obviously uses a dynamic lightsystem, because when you turn a light off for example, then all shadows are adjusted perfect, and all humans have PERFECT shadows, and interacts perfect with the light around.


Not weird that I wonder how this is done. How are those shadows generated that fast? The complex scenes have tousands of polies, and still the shadows are adjusted perfect to moving lights, and the shadows are just perfect.

I was thinking about some ways to do it:
1. Create a mesh, and modify it realtime with pivots, and alpha it with the strength of the light.

2. Somehow find where on the lightmap picture a specific area in the 3d world is, and write directly to it (would be slow, very slow...or?)


Any comments, suggestions, or problem-formulations?


Rob(Posted 2004) [#2]
A few people have done this effect including myself. Two ways:

1) duplicate the triangles where the shadow will fall, and then render just the character from the viewpoint of the light, and use the result to texture the duplicated triangles. Been done in blitz with various degrees of sucesss...

2) stencil buffer or hardware shadows support. Stencil buffer is good because you don't need the latest hardware. Most cards have some form of support for this - apart from old, dead, voodoos.

But splinter cell probably calls upon the hardware to do stencil buffered shadows and/or shader shadows.


napole0n(Posted 2004) [#3]
I'm also looking into this. The best thing I've seen in Blitz so far is Swift's shadow system. Unfortunately it's not the fastest system in the world (it doesn't run too hot on older cards), but the results look pretty good. Check the link in his signature to see it in action.


ChrML(Posted 2004) [#4]
Rob:
What exactly are stencil buffers, and how do they work? That method 1, is that a fast method?

How would writing directly to the lightmap work?, and is there a way to find the UVW coordinates on a texture out of the world coordinates?


Gabriel(Posted 2004) [#5]
The best thing I've seen in Blitz so far is Swift's shadow system. Unfortunately it's not the fastest system in the world


Most of that is caused by Blitz's limitations though. If it were possible to render to a texture, a lot of that overhead would vanish.


napole0n(Posted 2004) [#6]
Yes, it would be great if it could be more optimized. The good thing about Swift's system is that it looks pretty easy to implement.

@Rob: is the first method you describe the FLEX thing?


sswift(Posted 2004) [#7]
"Unfortunately it's not the fastest system in the world (it doesn't run too hot on older cards)"

I beg to differ. :-) My shadow systme is the fastest "real" shaodw system available for Blitz. It's not fair to compare the speed of my system to one in C, or to the speed of towel shadows which won't allow you to do the effects of Splinter Cell.

A major reason it's slow is that you can't render stuff to a texture in Blitz. Not only is it expensive to rneder those textures, but copying them from the screen buffer is slow as well.

About Splinter Cell's shadows...

They look very much like the shadows I cast. Notice how no objects that cast shadows cast shadows onto themselves. Like the pipe for example.

Also note how not all objects cast shadows. They very carefully chose which objects they wanted to cast shadows.

Oh and what makes you think that shadows can run well on older cards? There was a reason Quake didn't have any shadows. :-)


napole0n(Posted 2004) [#8]
@sswift: no offence mate, I find your system very impressive and I'm even considering purchasing it. What I mean with 'not the fastest system in the world' is that I don't think it'll be possible to get the same amount of shadows as Splinter Cell and still have it running smoothly. That doesn't mean your system sucks, but just that the kind of shadows/lighting effects as described in the topic is still a bit science-fiction for us Blitzers...

-EDIT- With older cards I meant the card in my sig, which is based on the GeForce2 chipset. While hardly cutting edge technologies now, there are plenty of games with shadowing that work fine with it. But they probably use another method, like you said with rendering to textures or something.


ChrML(Posted 2004) [#9]
sswift: Do you have any screenshots of your lighting system? How much does it cost? I will experiment a bit with this, and see if I can make anything similar. If I can't, you will get a customer :).


ChrML(Posted 2004) [#10]
Ok, just tried your shadow system. It seems nice, but can the shadows be casted up walls, and some sort of land on "not flat" surfaces?


sswift(Posted 2004) [#11]
The shadows can be cast on the ceiling if you want them to be. Watch the pillars. The shadow of beethoven will fall on them at times.


Craig H. Nisbet(Posted 2004) [#12]
Actually, I'm considering purchasing that system to, but the example that is given is far to complex. I like it as a feature demo, but I have a hard time understanding what I'm seeing when I look at the code. May not be a bad idea to include some dirt simple code examples of just the basic procedures in the system, like 1 box casting shadows onto a floor, a charactor casting on the room, etc. Actually, this is ecaxtly how Blitz's docs are set up. Just a thought.


Spy(Posted 2004) [#13]
is it possible to wirte a c++ .dll for shadow calculation and "paste" it to blitz3d ?


Ruz(Posted 2004) [#14]
yes. I thinkl I will purchase the shareware license see how I get on. I am only doing my demo so i can send off some work to get a job, so its worth doing. if I get further and my demo turns in to a proper game in the future i will purchase the full system.
does it do shadows on top of existing light maps.? i like my static light map for the level geometry but would like the system mainly for the charatcer shadows


Spy(Posted 2004) [#15]
@Ruz.. shareware license for what ?

and how does this .dll "render - paste" works ?


sswift(Posted 2004) [#16]
Craig:

Using the systme is really simple.

You have one function to cast a regular shadow,
one to cast a static shadow,
one to receive a shadow,
and one to set up a light source.

Then all you do is call updateshadows each frame.

That's all there is to it. All the other stuff in my code is just there to allow you to turn on additional lights and such. And there's some global variables which you can modify if you desire soft shadows, or need to change the amount the shadows are offset from a surface.



"does it do shadows on top of existing light maps?"

Yes. The system generates new geometry seperate from your level geometry for the shadows each frame, and these are blended on top of whatever was already there.


Ruz(Posted 2004) [#17]
ok i will prolly buy it in the next few days, seems pretty cool anyhow.


ChrML(Posted 2004) [#18]
I am making a new system based on what you people just have told me :P. It works fine so far (currently it does render a 2D image of the shadow to a texture). Now one little problem will be letting the game know which geometry polies to copy, lol. It gotta have to figure out using pivots and collisions where the shadow will land. Then the problem letting it know which of the vertexes around that area it have to copy.


sswift(Posted 2004) [#19]
Good luck. :-)


ChrML(Posted 2004) [#20]
How did you get the white area masked, and the black are visible on the texture? Texture mode 4 only works with 0,0,0 as transparent... Just asking :).


ChrML(Posted 2004) [#21]
Forget my question, it's solved :D. With EntityBlend-ing :P.


boomboommax(Posted 2006) [#22]
sorry this is a way old post but, in splintercell they dont draw the shadows, they draw the light


big10p(Posted 2006) [#23]
in splintercell they dont draw the shadows, they draw the light
Weird, I was just thinking about this concept last night. I didn't know that's how Splintercell does it.


Braincell(Posted 2006) [#24]
Yea it's allllll in shaders. Shaders are god. The more i learn about them, the more i see that at least 50% of quality from programming comes from good shaders in allllll modern games.


OJay(Posted 2006) [#25]
in splintercell they dont draw the shadows, they draw the light


sorry, thats not 100% true. they use so called "projectors" to projects a static or animated texture to the ground. can be everything from lights and shadows, to selection-markers or spray-logos...

take a look at this: http://udn.epicgames.com/Two/ProjectorsTableOfContents


Stevie G(Posted 2006) [#26]
@ Lenn

How's the shadow system coming along? Any closer to a demo?

Cheers
Stevie


Braincell(Posted 2006) [#27]
@Stevie, yea i think so... If someone told me i would be so piled up with real work i wouldn't beleive him. But I am. The system is gaining in priority as time goes by (esp since last week) because i myself am impatient to see it. So no clear estimates on that sorry, but thanks for asking keeps me aware. I'm going to be spending quality time on it this evening in fact.


Stevie G(Posted 2006) [#28]
Great. I'm pretty desperate for a fast simple system which can handle mutiple entities and receivers. Will you be able to handle self shadowing as per an early demo by fredborg ( I think )?

Take your time but do it fast ;)


Braincell(Posted 2006) [#29]
Yes, self shadowing is no problem, and further more we'll have animated boned b3ds included as well, if everything works out like it should. It's very long overdue.


boomboommax(Posted 2006) [#30]
project the light even


Uncle Ho(Posted 2006) [#31]
@Braincell

Great news. i hope you can come up with a demo soon. Your work is more than appreciated :)
The boned b3d casters are exactly what i am looking for :))


Steven Noyce(Posted 2006) [#32]
Braincell (fka Lenn),
It says in your signature that your shadow system is open source, is the source available yet?


Steven Noyce(Posted 2006) [#33]
What is a stencil shadow?
How do they work?

If anyone could explain these to me it would be very usefull.


jfk EO-11110(Posted 2006) [#34]
http://en.wikipedia.org/wiki/Stencil_shadow_volume


Braincell(Posted 2006) [#35]
Hi

I could post the source to what i have now but its absolutely no use because it isnt commented fully and a lot of things are still changeing. For example I recently added an improvement that will automatically "virtually weld" any vertices that are too close to eachother so the system doesnt transform both of them. Virtually i mean because the verts are stored in a bank, only accessed when a 3d object loads. And so on and so forth.

I'm still working on it so dont worry. Today i spent a few hours in fact, but i still have a lot of other "real" work to do so it's slow. However, there is still hope for a demo by the end of February.


Uncle Ho(Posted 2006) [#36]
@Braincell

Glad to hear you are still working on it :)
Count me in for testing whenever you have something.


Stevie G(Posted 2006) [#37]
Yeah, count me in if you need someone to test this. I'd quite like to use this in my verlet racing game :)