Realtime zFail shadows

I have implemented zFail realtime shadows into my engine, also known as “Carmack’s Reverse” made famous by John Carmack for the Doom 3 engine.

Here is a before and after screen shot of the same image (Please exuse the ugly models…I’ll get to the real art at some point. ;))

Before

http://vorax.thebodclan.com/images/no_shadow.jpg

After

http://vorax.thebodclan.com/images/shadow.jpg

I am pretty happy with the FPS, but to use the algorithm properly, all my models vertex counts will have to go up a bit because you can’t have unclosed meshes or you get streak artifacts. This algorithm is really a killer on both CPU and video card - it generally drops FPS by more then 50% (I get about 48% drop) because the entire scene is rendered twice and you have to render the shadows to the stencil buffer. I am using the two_sided stencil extension to save some stencil buffer writing but I am gaining something else for free - The way my engine is designed I don’t have to transform the light into the object coordinates, this is a pretty big saving because it either adds alot of CPU or it adds alot of copmlexity it also opens me up to use display lists for static object shadows, another very big saving. Because the engine does all transformations in the second thread, I can keep everything (lights and objects), in worldspace. There is no need to determine the inverse matrix of the objects transformations.

If you look you can see a streak in the shadow, it’s a part that lit just past the leg and into what should be the bulk of the shadow. That’s not a bug in the implementation, it’s caused by a reversed normal insde the model.

Now I have to go back and patch up just about all the models to remove any more reversed normals and close the meshes…just added another month to the project …DOH! :smiley:

my brain hurts

wow, looks awesome. :o

Superb! That’s really really good & only a 50% drop in framerate! I know how to project shadows onto a flat surface, but this projects onto the various faces as they come. I’m overwhelmed and can’t even think how to implement this with any pretence at maintaining real time.

Where did you get the information on the algorithm? I’m off for a quick Google.

Alan

/Edit I found at article at gamedev (http://www.gamedev.net/columns/hardcore/shadowvolume/default.asp) that looks promising. Ah, so much to learn, so little time.

Nice one Vorax, stunning looking work!

Kev

Very nice. =)

How do you calculate the polygon edges? That was my biggest problem when I tried implementing it.

do note patent issues with using said algorithm.
Creative has a patent on it, and will force you to use EAX 4 :stuck_out_tongue:

Here are the steps:

  • Index planes which compose the geometry
  • Determine which planes share verts with other planes to determine neighbors
  • Determine which planes are facing the light
  • To get the edges: Of the light facing planes, determine which ones have neighbors that aren’t facing the light and/or they don’t have any neighbors at all <<-- these are the edges

Creative (the sound card manufacturer?) has a patent on John Carmack’s (self proclaimed software patent hater) algorithm??

Vorax:

So for each frame, you need to calculate the dot product of the normal of every single triangle in the scene and the view vector? =/

Matzon:

Fortunately for me, american software patents don’t apply in Europe. :smiley:

Yep. Everything with shadow volumes… creative owns it. They shouldn’t have got that patent in first place, because they talked about publically before filing it.

However… they have it and most people won’t have enough cash for fighting against that. That’s “justice” made in the USA. :-/

Well, it does look nice. Good work. :slight_smile:

" Warning - while you were typing 2 new replies have been posted. You may wish to review your post."

Erm… yes, they do have that patent and they blackmailed id software to include eax, which they did (otherwise the release would have been delayed by at least 9-12 months).

Yup…you got it. [edit]err…not of the view vector, the light vector. Which is why in most implementations of this you have to transform the light vector into the object space[/edit]

I am Canadian…

Er, yeah, I meant light vector. I was thinking eye space when rendering the depth map from the light’s pov in shadow mapping.
d’oh

[quote]Creative (the sound card manufacturer?) has a patent on John Carmack’s (self proclaimed software patent hater) algorithm??
[/quote]
I belive that Creative are the owner of the 3D guru company 3DLabs (The driving force behind GL 2.0), I think that might explain why a sound card manufacture is walking 3D land :wink:

// Tomas