Stencil shadows

BlitzMax Forums/OpenGL Module/Stencil shadows

JoshK(Posted 2006) [#1]
From what I gather from the NeHe tutorial, to draw a stencil shadow, you basically just project every edge of the mesh in one direction. If you had a triangle between A, B, and C, you would create a quad out of A and B, and two other vertices offset by the vector of the shadow.

I'm rather surprised that you actually have to adjust the vertex array in real time. Isn't there a way to do it so that this is automated somehow? Is that really how it is done in Doom 3?


sswift(Posted 2006) [#2]
I think they use vertex shaders. But I'm not even remotely certain of that.


JoshK(Posted 2006) [#3]
It doesn't require vertex shaders, since it runs on my GEForce 4.

That will be kind of fun to program.


sswift(Posted 2006) [#4]
Well, if they do do it in software, that might explain why the characters have so few polygons, and why there are so few of them on screen at once.


JoshK(Posted 2006) [#5]
What about a more conservative use of them, like in HL2? Is that all calculated in real time? Do they extend and draw all the edges or just the silhouette edges?


sswift(Posted 2006) [#6]
I think even in Doom they only draw the silhouette edges. I seem to recall reading that.

I'm pretty sure you'd find an article about it on Gamasutra.com

Also, I wouldn't be surprised to learn that they use vertex shaders for calculating them, and only fall back to software if need be.


boomboommax(Posted 2006) [#7]
HL2 does not use stencil shadows afair (as far as i remember) its just "render to texture/projected" stuff


Drey(Posted 2006) [#8]
Yeah, HL2 uses shaders to help create the shadow, but in the end it's a projected texture.


Robert Cummings(Posted 2006) [#9]
What about torque and unreal tournament 2004? they don't require any shaders at all and have fast soft character shadows.


Gabriel(Posted 2006) [#10]
There's an addon for Torque which permits use of stencil shadows, but I'm not sure if that's what you mean. Probably not since you say soft, and stencil shadows are not soft unless they are processed somehow.

Unreal Tournament 2004 definitely uses projected shadows for characters.


JoshK(Posted 2006) [#11]
You know, I could use a super low-poly stencil mesh to cast shadows with. It would cut the processing time down a lot, and would look about the same when projected as a shadow.


sswift(Posted 2006) [#12]
Halo:
Not if you want objects to self shadow. And I'm not sure that you can use stencil shadows without automatically having self shadowing.

If you try to, I think you will find you get all sorts of shadow artifacts as a result. Portions of the model in shadow which should not be, and vice versa.


JoshK(Posted 2006) [#13]
I'm getting good results with projected textures. I'll stick with those for now. Having the gl clip planes sure is a help, because you can cut off the sections of a surface that would just be empty fill anyways.


JoshK(Posted 2006) [#14]
I got projected shadows working super-fast. This is pretty fun:



Defoc8(Posted 2006) [#15]
looks good :]


Vertex(Posted 2006) [#16]
Halo: I'am a long time interested on projective shadows. There is no problem to render the shadow to the texture, but how to project this depthtexture. I have code any testversions, but if I project the texture not from the camera, they looks not ok.

So can you post a little example? The most importend thing for me is, how the texture matrix have to build(just like using the inverted matrix of the lightentity etc.).

cu olli


JoshK(Posted 2006) [#17]
Just set up automatic texture mapping with OBJECT_LINEAR, calculate the texture mapping planes, clamp the texture, add clipping planes to trim off the unwanted portions, and re-draw the object.