Another Shadow routine...

Blitz3D Forums/Blitz3D Programming/Another Shadow routine...

Hautvent(Posted 2005) [#1]
Here's my little Shadow routine, it's not finished yet but you can already make some pretty shadow in your prod.

It's based on Norc system, optimised with the idea of philipe C, still working on it.

As you'll see there is some limitation....

http:\www.planb.free.fr\AFO_Shadow.zip

Some thing to know : To cast a shadow on thing, those thing must have an EntityPickMode specified. IE: the ground....
If you find the shadow too aliased, just change the AFO_FLEXshadowTextureSize%. It's the resolution of the shadow. Carefull, this will affect frame rate.

to preserve this frame rate, a shadow is calculate once per call of UpdateShadow. So multiple shadows (like 3 or 4 shadows per actor) will refresh one after the other, the result will be slow moving shadows.

check the example file, you'll find answers.

Still working on improvment...

Hautvent.


John Blackledge(Posted 2005) [#2]
Nice work!

Some questions:

a) AFO_create_ShadowSun() seems to create a nicer shadow than AFO_create_ShadowLight() - why is that?

b) Is AFO_create_ShadowLight() just for static lights?

c) Can you comment your work in English for those of us who don't speak French.

d) How much work do you think you have left to do?
Looks pretty much finished to me.


jfk EO-11110(Posted 2005) [#3]
Thanks for sharing.


IPete2(Posted 2005) [#4]
thanks, dloading now...

IPete2.


puki(Posted 2005) [#5]
Good stuff.

Not had chance to play around with it too much - first thing I will do is stop the lights moving - want to see how it works with static lighting.

Nice to see someone having a go at doing shadow stuff. Maybe "sswifty" can give you some input on it.


Hautvent(Posted 2005) [#6]
sorry I didn't answer earlier, but the ocean in Espania was too good )))

So, AFO_Create_ShadowSun() creates a directionnal light ( createlight(1) ) like a sun, the shadow will ever been displayed.
AFO_Create_ShadowLight() creates a point light ( createlight(2) ) like a torche. This type of light has a range : the shadow will disapear after 80% of this lightrange.

I haven't created a function for spot light yet.

For every type of light, the shadow will be darker when the actor is closer to the lightsource, and also the shadow will wanish the farther away the actor is from the lightsource.

In my example code, you can see that lights or sun can be moved or anything else related to light.
My functions returned the light entity so every blitz command will work, like lightcolor, lightrange, positionentity.....


WORKLOG :

while I was burning on the beach, I though of multiple things to do for improvment : I found a way for shadows to be much much more flexible so it will better fit the ground. I've tought on a way to calculate a lot more shadow at a time with the same framerate as for now, just let me try it out.... The result will prevent the actual problem in my example file : shadows refreshs slowly when they're too many /
I'm working on improving realism when there is two or more lightsources, the weaker shadow may disapear if a lightsource is too close and too strong kinda things...

Also working for compatibility with biltzKlan! Smart Light System.

And the last but not the least : make shadow with spotlight.

When everything done, I'll do a HTML file in english explaining every function and parameters... It's not much complicated thou


John Blackledge(Posted 2005) [#7]
Brilliant work Hautvent. Looking forward to seeing it.

BTW, are we coders allowed time off?
No-one told me!


Hautvent(Posted 2005) [#8]
A big update to the system, but not yet the last.
Still posting it for feedback, check the example file, some function calls have changed... And some english comments )

V5 :
http://www.planb.free.fr/AFO_Shadow.zip

Working on a big improvment of frame rate now, with V6 comming.


John Blackledge(Posted 2005) [#9]
Hauvent,

A few comments (and I hate it when people comment on my work!):

1)
I moved your static 'sun' from: PositionEntity Luz3, 0, 500, 0
to: PositionEntity Luz3, 50, 50, 5
to more clearly see which light was which.

Then I REM'd out luz1 and p1 entirely to simplify the scene, leaving just light 2.

I've asked this before, but why is there such a big difference between the shdows created by AFO_create_ShadowLight and AFO_create_ShadowSun?
AFO_create_ShadowSun seems to create a much subtler shadow, more 'real-world'.

2)
I also moved the cube nearer to the character
from: PositionEntity c, 20, PickedY()+20, 75
to: PositionEntity c, 20, PickedY()+20, 70
to see the effect of the shadows against an object.

In your previous version your shadows 'draped' up vertical objects (a bit strange actually - they draped at 45 degrees).
Have you taken out this effect altogether? Do all shadows now only lie on horizontal surfaces?


Please understand that these questions are from a person who wouldn't have a cat-in-hell's chance of even starting this code.
Full respect!


Hautvent(Posted 2005) [#10]
the process is the same for sun or light. The only differnce lies in the color : a light is supposably closer to the actor than a sun. So the shadow's color is calculated dynamicly for a light and is static for a Sun.
You might notice a smoother shadow for the sun when there is only it's shadow (when you are too far away from other lightsources), it's only because it is the only shadow calculated so it refreshs quickly.

point 2 embarassed me : before it showed how to cast shadow on object, but there is two side of the story : a simple cube has not enought vertices to have a nice projection on it ! So the result is crappy form of the shadow. So I rather remove the entitypickmod for the cube, the purpose of the cube is just to show shadow of big object. Furthermore, aligning shadowmesh to vertices picked is a real FPS killer, more than anything else in the system.

I'm working on a revolution for this system to avoid the "noise" in shadow, meaning by that when the shadow lack vertices to cast on, and just fall underground or have just some spike...

By the tests I've made, I'm pretty sure the solution I tend to is the one sswift found. I've only see the demo of his shadow system and it's really amazing. Now All I want is not just do some bad copy of it.


Doggie(Posted 2005) [#11]
it doesn't work if you have a flat screen monitor.
The 60hz refresh rate flickers like all hell.
Too bad.


John Blackledge(Posted 2005) [#12]
point 1) Understood.

point 2) I can see that it's a nightmare.
I change the cube for a sphere in your old version to see the shadow map 'upwards' on the sphere, and I can see that this is an almost impossible task for you - potentially one good detailed shadow could take up all of the cpu.
As you say, sswift seems to have got closest to that.

Looking forward to your next version.


jfk EO-11110(Posted 2005) [#13]
A few thoughts. Once upon a time I wrote this little shadow demo (formerly knows as norc). My biggest mistake was to think a shadow towel needs to be object oriented. Today I think, it would be much more clever when the towel acts camera oriented. In other words, lay down the towel on the ground that is right in front of the camera. Make sure it will cover the whole field of view and problaby use EntityAutofade to smoothly fade out the shadow towel mesh in the distance.

The second problem is: aligning the towel to the ground. Linepicks are very slow, indeed. But how about to pre-compile the static ground, using some kind of raster? It may eat some megs of ram to hold the data. Not a big problem IMO.

I think this would be very fast.


gosse(Posted 2005) [#14]
I don't want to fill up my address bar history :)
http://www.planb.free.fr/AFO_Shadow.zip
[edit]
Nice stuff!


Hautvent(Posted 2005) [#15]
Doggie wrote : " it doesn't work if you have a flat screen monitor.
The 60hz refresh rate flickers like all hell.
Too bad."

What the hell are you talking about ? I'm working on dual screen LCD monitor one with 60Hz the other with 75Hz and I don't have any flicker ! I tested it too on another PC with a Flat screen CRT monitor, no problem either... Can you tell more ?

I think the next release will be the last, that remember me that I need to add spot lights... Maybe I'll release a V5.1 with spotlight included first, this was not my priority so far.


John Blackledge(Posted 2005) [#16]
"this was not my priority so far."
- It's very much appreciated though.

I noticed recently in the Spiderman game (not that I play that sort of thing) that all the 'extras' had simple round sprite-shadows under their feet (which was fine), while spiderman himself had a detailed shadow like yours (which was appropriate).

For anyone considering that sort of scenario, your shadow system is ideal.

As I said before, I wouldn't even know where to begin to write code like this; we all have our different talents.
For you to do this, then give it away, is very much appreciated.


Hautvent(Posted 2005) [#17]
There you go, a small (for some people big ;o) ) update with spotlights for your pleasure )
I'd like to thank Mr. Mikkel Fredborg who inspired me in some way for a little (but hard) part of the code.

V5.1
http://www.planb.free.fr/AFO_Shadow.zip


Now going back to V6...


John Blackledge(Posted 2005) [#18]
Nice!

V6? You feel there's more to do?


Hautvent(Posted 2005) [#19]
mm yes with the actual version there is another optimisation that can be done (see JFK's post) but due to limitation of the system, I'll try another aproach of shadows.
So V6 will be using totally different shadow system, thus transparent for the user of the lib. My goal is to have the same possibility as V5.1 and add more, that's why I'd rather call it V6 than doing a brand new one.


Hautvent(Posted 2005) [#20]
I just saw that I forgot a small but vital lign of code that preserve a lot a frame rate in hudge scene...
Did the small update, I change the main actor too for one that is more animated (I actually did it), hope you'll like it.

V5.1 revesited
http://www.planb.free.fr/AFO_Shadow.zip


John Blackledge(Posted 2005) [#21]
CHerrs. Works well. Thanks.


BlitzSupport(Posted 2005) [#22]
Yeah, nice job, thanks.


jfk EO-11110(Posted 2005) [#23]
I have to say it again. using an object oriented shadow system is such a waste of performance. Hit space in your demo and watch the tris in wireframe mode. There is more than enough triangles to cover the whole near range scene in front of the camera. So you'll have one single mesh for all shadows that are near the camera. To save perfomrmance you may even try to use a Terrain (LOD!) for this shadow mesh.

EDIT:
Uh, this just gave me a kick, I hope you don't mind, I wrote a little demo that is using one terrain as a shadow towel around the camera. It's pretty fast. Not a real system, currently it has only one light source, the sun (outdoors scene thing):
http://www.melog.ch/dl/csp_bb_terrainshadow_05_1.zip
It is btw using an orthographic camera for the shadowmap.
A very simple thing, but it may give you some ideas.

Of course, I think your system is great, especially since it's a real system, with multiple lights etc.


Hautvent(Posted 2005) [#24]
I think you're right JKF, there is too much polys. On my system there is no problem with glow, blur, particles and stuff plus shadows, but my 6800GT helps )

The V6 I'm working on will be towel-less, it will be only texture bakery (real nightmare I'm telling ya). Tests I've made works well, but there is a lot of problem with multiple lights and my 'algos' are not working in every cases...

That's why I think I won't work on V5 anymore, the V6 will break actual limitation.