Page 1 of 2

Dirty hack:: depth pass shadow volumes

Posted: Thu Feb 24, 2005 5:15 pm
by $NulL
Stop me if this has been done before, but I've never seen it.

Test Map [240Kb]

Sample video [xvid 800Kb]

Screenshots
Image

Image

Now the interesting bit, how it works:

The outward facing polygons of the shadow volume darken whats already in the framebuffer.
The inward facing ones brighten it up again.

So when you can see both inward and outward facing polys they cancel each other out, but when only the outward facing poly is visiable the area is shadowed.
(You should never directly see an inward facing polygon)

There are some major limitations though. Being depth pass shadows you dont ever want a player's view to pass into a shadow volume.
There will be a maximum number of shadow polys rendered on top of each other before it fails and the shadow volumes become visable.

That'll do me for now
-- $NulL

Posted: Thu Feb 24, 2005 5:41 pm
by Lukin
Wow, moving shadows in Quake 3.
Great idea.

Posted: Thu Feb 24, 2005 6:40 pm
by bork[e]
Awsome, I'll check it out later.

Posted: Thu Feb 24, 2005 6:40 pm
by Fjoggs
Dizzy.. :p
Does it hit bad on performance it it works smoothly, like light-styles?

Posted: Thu Feb 24, 2005 8:20 pm
by rgoer
very cool!

Posted: Thu Feb 24, 2005 9:03 pm
by Meridanox
Great work! Looks almost like D3 stencil shadows.

I suppose you could reverse the effect and make fake light as well - like a swinging lantern.

Posted: Thu Feb 24, 2005 9:54 pm
by $NulL
Fjoggs wrote:Does it hit bad on performance it it works smoothly, like light-styles?
It shouldnt, its only two simple single pass shaders.

Posted: Thu Feb 24, 2005 10:17 pm
by ydnar
This gets my vote for coolest Q3 hack in years.

Posted: Thu Feb 24, 2005 10:20 pm
by ydnar
Okay, I thought up an extension of your idea. Use q3map_alphaMod volume brushes on the shadow volume's vertexes to fade the shadow out. You could fake "soft" shadows this way too.

Make the lighten/darken shadows use alphaGen vertex and a blendFunc that uses the alpha channel and voila...smooth/fading "stencil" shadows.

Posted: Thu Feb 24, 2005 10:26 pm
by Kat
I might have this totally wrong here but are we looking at 'projected shadow volumes' a la what Doom 3 does? What happens with multiple light sources?

Posted: Thu Feb 24, 2005 10:56 pm
by $NulL
Kat wrote:I might have this totally wrong here but are we looking at 'projected shadow volumes' a la what Doom 3 does? What happens with multiple light sources?
The shadow volumes are brushes placed behind the shadow caster's brushes. There could be a 2nd set of shadow brushes for a second light source that go off in a different direction. I included the .map with the test map, it might help explain.

Ydnar :: I'll give it a shot, but im not sure it'll work out. Because when you look through a shadow volume thats been alpha moded the brightness of the light/shadow textures wont be the correct values to cancel each other out, so the volumes will beome visiable.

Posted: Thu Feb 24, 2005 11:30 pm
by rgoer
you can make sure you get the correct values to cancel each other out still if you give the out-facing shader alphaGen vertex and the in-facing shader alphaGen inverseVertex. They should still add up to 1.

Posted: Fri Feb 25, 2005 12:01 am
by blood.angel
Exactly how was this done without access to the full code? The SDK doesnt allow access to the rendering code.

Posted: Fri Feb 25, 2005 12:21 am
by Timbo
blood.angel wrote:Exactly how was this done without access to the full code? The SDK doesnt allow access to the rendering code.
Sorcery. Alternatively.. read the post? :icon23:

Posted: Fri Feb 25, 2005 12:25 am
by $NulL
rgoer wrote:you can make sure you get the correct values to cancel each other out still if you give the out-facing shader alphaGen vertex and the in-facing shader alphaGen inverseVertex. They should still add up to 1.
That would only be true if your facing strait through the volume, any other angle would give different alpha values on front and back faces.

Posted: Fri Feb 25, 2005 1:02 am
by ydnar
I will test at home later... :)

Posted: Fri Feb 25, 2005 1:20 am
by rgoer
good call $NulL I wasn't thinking fully

Posted: Fri Feb 25, 2005 2:07 am
by Lenard
Cool but all the tex's in your map seem to be missing. Also, on low quality the shadows have purple trails. The polygons become barely visible I suppose, I'm still not 100% on how it works.

It must be that there pyramid like poly's jutting out from the object that draw a shadow on the wall wherever the object intersects it... if this is the case then the polys are becomming visible and turning purple on low quality settings.

Would this work with models?

Posted: Fri Feb 25, 2005 4:35 am
by Meridanox
Lenard wrote:Would this work with models?
Should... they're just shaders assigned to a surface.

Good seeing all the old faces around again... ydnar, rgoer, kat, etc.

Hey, kat... maybe we should start a Quake3 Can Do It Too project! Hahaha!

Posted: Fri Feb 25, 2005 7:13 am
by rep
This would work well with a moving spotlight.

Edit: The only problem would be matching the proper shadow scale in a scene. The closer an object is to the surface it casts a shadow on, the closer the size of the shadow to 1:1 scale it shall be. The problem here of course is in a room lit with multiple sources, one must painstakingly measure the proper trajectory of each object's shadow.

Working in radiant, this would probably be impossible... However, you can convert your map to ASE, load it in 3D Studio Max and give the whole thing a generic texture, and then use render to texture to create the lightmaps.

Once this is achieved, you can use the lightmaps as a source to trace onto, and then model the shadow volumes into the proper scale.

Soft shadows can be achieved using this same method. Simply duplicate the shadow volume twice and enlarge each ever so slightly, and apply a lighter shader onto each as you move out. The levels of shadow fidelity are endless, only limited by the capabilities of our video cards. For an object such as the cross in the example scene it wouldn't be too taxing to duplicate the shadow volume in this manner to produce said effect.

edit: True gradient shadows can be achieved as well by segmenting the shadow volume model into partitions corresponding with the direction of the light. For example, if you have a flashlight on a plane projecting on a shape, you can do one of two things for an accurate shadow; Create a simple shadow texture on a plane that includes the degradation of the shadow after distance, which would be slapped on a single plane close to the surface like a decal, or for a dynamic shadow you would slice it into pieces and animate each accordingly.

Image

The distance of a light source dictates the character of the shadow. The closer the light is to the object, the smaller and more solid the shadow will appear. As the light source moves away from the object, the shadow not only enlarges opposite the direction of the light, but it diffuses due to the loss of intensity. This effect can be achieved with these methods, using a stepped procedural model/shader combination. The more steps, the more realistic it will look. The less steps, the more banded it will appear.

Sweeet stuff man..

Posted: Fri Feb 25, 2005 7:57 am
by Vexar
I am with Big Y, Zaaaazome!

Posted: Fri Feb 25, 2005 10:06 am
by Pext
is it possible to automate this via q3map2 and a boolean, saved at the brushes you want to cast the shadow?

Posted: Fri Feb 25, 2005 1:44 pm
by $NulL
Right, I got a fading one kinda working. I used a gradiant texture instead of alpha blending it. But I carnt get around the values not being able to cancel each other out, so it looks ok from the side or top but from anywhere else the volumes become too visible.

Image

Posted: Fri Feb 25, 2005 4:53 pm
by Myth
Wow, nice progress!

Posted: Sat Feb 26, 2005 11:35 am
by dAde
Sounds great :). Will check it at home...