Shadows 101

Blitz3D Forums/Blitz3D Programming/Shadows 101

YellBellzDotCom(Posted 2006) [#1]
Ok, its been days and I still have no idea on how to create shadows (except a simple blob shadow, see link below). So I have to get to ground zero and start from there. I need to find out alot of info since I couldnt understand alot of the custom functions and methods in the demos and code archives relating to shadows. I figured I would ask the kind Blitzmasters a few questions and maybe post some very simple examples...

what is a stencil shadow?

If there is a thing called stencil shadows what are the not-stencil-shadows called?

Shadowing Techniques...

Lightmapping = creating an image of a scene that darkens faces that are blocked by an entity that sits between that face and a lightsource. This image has an alpha value so that a colormap can show through it. Both images are applied to a mesh to create a realistic looking terrain.

blob shadows = creating a seperate mesh, making it flat and applying a dark color to it that sits below an entity for static entities or is parented to a moving entity so that it follows it around. Quickest method of creating shadow look for a scene. May or may not be adjusted according to light sources. Is not an accurate method of representing shadows of entities. Basically its just a dark circle mesh that sits below an object. If you use uneven terrains, the lines of code required to blanket the shadow across the terrain appropriately will outnumber the lines of code to actually make your game, lol.
Blob Shadow Xample using a mesh = http://www.hilbily-works.com/Downloads1/BlobShadow.bb
Blob Shadow Xample using a textured Quad = http://www.hilbily-works.com/Downloads1/BlobShadow_wQuad.zip
Blob Shadow Xample using a Max created Quad mesh and TED Terrain = http://www.hilbily-works.com/Downloads1/BlobShadow_wMaxQuad_wTEDMeshTerrain.zip

Shadow Mapping = The process of comparing wether a pixel is visible from the light source by comparing it to a depth image of the lightsource view stored in the form of a texture.
Steps in creating and applying a shadow map
1 - Render the scene in shadow and store the image as a texture.
2 - Do a depth test to see if pixels are visible or not.
3 - Render the scene lit, areas that failed the depth test will not be re-rendered.

Shadow Volumes = A typical method of creating shadows for a scene. Involves raycasting from a lightsource to the furthest point of a scene and finding which faces are occluded by objects. Still have a way to go in understanding this.


Stencil Shadow = Ok, thanks to MarkCW's link, a stencil shadow system incorporates using a stencil buffer, (which limits the rendered area to work with) and a Zbuffer (Processes depth information), to determine per pixel coloring. According to Wikipedia, it is a three step process.
1 - Render the scene as if it were completely in shadow
2 - Using the depth information from that scene, construct a mask in the stencil buffer that has holes only where the visible surface is not in shadow.
3 - Render the scene again as if it were completely lit, using the stencil buffer to mask the shadowed areas.

There are currently 3 variations in applying this technique. DepthPass, DepthFail, and Exclusive-Or. These 3 variations use different methods on step 2 above.

Still have a way to go in understanding this.


LinePicking = Popular method of finding out if a face is behind an object and as such, should recieve the shadow of that object. Projects a line from the face to the lightsource, if there is a collision with any objects other than the the lightsource, than that face should be shadowed. Slow method since checking thousands of faces with every render is processor intensive.

Mixing Methods = Applying multiple methods of shadowing to represent the best looking scene without sacrificing processing power.

Lightmapping + Blob Shadows = Looks good until a moving entity enters the shadow area of a static object. The mixing of the blob shadow with lightmapped shadow doesn't work. You can create code to alter the coloring of the blob shadow mesh to look more like the lightmapped shadow, but this just doesnt seem to be efficient to me.

Shadow Volumes and Stencil Shadows = Using the stencil buffer (Area of ram on video card?) to accelerate the method of finding which faces are occluded according to a lightsource by raycasting or linepicking those faces.

If anyone is kind enough to help me, I will update this post to show accurate information so I can have a compilation of methods and techniques with a little understanding of how to apply them otherwise I will just go and play with my little 3d model dolls and dream.

Also, I realize that Swifts Shadow system is the most recommended one. But I am tapped out for purchasing addons, plugins, libraries, dlls and all that, So I am attempting to understand what Blitz3d can and cannot do in regards to shadows.

lol, thanks!!


markcw(Posted 2006) [#2]
see these for info.
http://en.wikipedia.org/wiki/Stencil_buffer
http://en.wikipedia.org/wiki/Stencil_shadow_volume

i don't think blitz3d supports stencil shadows, but here is the most recommended shadow system, by sswift.
http://www.blitzbasic.com/logs/userlog.php?user=963&log=269


bytecode77(Posted 2006) [#3]
blitz3d supports stencil shadows as well!
my system: http://www.blitzbasic.com/Community/posts.php?topic=62809


markcw(Posted 2006) [#4]
i just tried to buy the "swift shadow system" on shareit and couldn't, i kept getting "The page cannot be displayed" message when i click on the buy button. strange, thought i should mention it.


YellBellzDotCom(Posted 2006) [#5]
Devils Child,

What exactly does that mean?

Are you saying that you can use Blitz3d code to read and write directly to a hardware enabled stencil buffer? (accelerated)

or

You can do some grand coding in Blitz3d to read and write to a virtual ram buffer for storing Stencil information? (Slower)

Thanks for the replies and help.


bytecode77(Posted 2006) [#6]
no, i am using just a dll for direct X.
check out the previous stencil shadow thread.
there are two shadow threads(both my me ;))
there is no need for grand coding. but it is very tricky at all.

please post all questions about stencil shadows in the stencil shadow thread!
cya


sswift(Posted 2006) [#7]
mark:
Is this the page you went to?

http://www.shareit.com/product.html?cart=1&productid=208046&languageid=1&currencies=USD

Seems to be working just fine for me.


markcw(Posted 2006) [#8]
yes. must be just me then. strange, i've bought of shareit before and never had any problems.


YellBellzDotCom(Posted 2006) [#9]
Devils Child,

I believe that is what MarkCW was saying, which was also reaffirmed by BlackD, Stencil Shadowing is not possible with Blitz3d WITHOUT the use of external pluggins, dlls or 3rd party solutions.

Thanks for the help though.


markcw(Posted 2006) [#10]
well IE (5.0) seems to have been the problem. i downloaded the latest firefox (1.5) installed, and it worked.


sswift(Posted 2006) [#11]
Maybe you just needed to clear your IE cache and cookies. My bank's website will sometmes refuse to let me log in until I do that.


YellBellzDotCom(Posted 2006) [#12]
Maybe this thread shouldve been started in the beginners area. I apologize for that.


markcw(Posted 2006) [#13]
> Maybe you just needed to clear your IE cache and cookies.

yes, something like that i guess.

xyle, no need to apologize man. :/

technically, this board is for code, but users post non-code stuff here all the time and nobody complains usually.


YellBellzDotCom(Posted 2006) [#14]
Ok, added a new download for a Blob Shadow example using a textured quad to the first post.

Thanks MarkCW.


YellBellzDotCom(Posted 2006) [#15]
Added a new download for a Blob Shadow Xample using a Max created Quad Mesh and TED Created terrain. This Xample keeps the shadow aligned with an uneven Terrain.

I had a heckuva time trying to properly align a Blitz3d created quad mesh with the terrain and to stay centered around the Sphere. I finally gave up on it and just made the quad externally with max.

The new problem with this was texturing the mesh with a transparent shadow texture. No matter what I did I couldnt get the mesh to load properly with the transparent texture. I finally just tried loading the texture manually and applying it to the Max Created mesh and that worked.


Leto(Posted 2006) [#16]
Thanks for this, Xyle. I was investigating shadowing options recently too (but couldn't even get blobs to work, actually, haha...) so this info is useful.


YellBellzDotCom(Posted 2006) [#17]
ah great, glad it helped someone out besides me. Im gonna take a better gander at Shadow Mapping, but I may just use the blob shadow in my own game.

Thanks for the reply.