Shadow volumes optimization

Discuss programming topics for the various GPL'd game engine sources.
Post Reply
Barnes
Posts: 232
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow
Contact:

Shadow volumes optimization

Post by Barnes »

Some time ago i add "doom3 style" lighting in to my engine. First version was very slow, like 30-40fps.With some optimizations i'm get big speedup. Now i use
1 - frustrum, pvs and occlusion query lights culling
2- two side stencil
3- draw shadow volumes with precompiled static vbo
4- light scissors
5- light depth bounds
That make the new? Use z-pass volumes? Q2 geometry very simple, I'm not sure that this is an advantage in comparison with Carmack reverse...
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Re: Shadow volumes optimization

Post by Spike »

z-pass means that you can skip caps. it can be an effective optimisation as it means you only draw edges and don't have quite so much fill rate (stencil shadows are quite expensive in fillrate, of course). z-pass will not work if the view is in shadow, but will be faster in the cases where it does work. The trick is writing the code to decide whether its safe to use z-pass for each individual light.

one potential optimisation is to optimise your shadow volumes to avoid excessive overdraw which can greatly help in when given complex geometry.
the main issue imho with complex geometry is not the extra fillrate that results from it, but rather the cpu costs from working out whether each triangle surface is facing the light or not. With the world, this can be precompiled and with the extra filling clipped away, but moving models will need to be animated and rechecked every single frame.

Most people seem to prefer shadowmapping nowadays. Softer shadows are generally nicer and much less harsh. The real advantage though is that you don't have to generate lots of shadow edges based upon surface normals, meaning you can just push the entire mesh to the gpu in one... or 6 rather... goes. As a result, it can scale much better at higher detail levels. Especially if you can ensure that they're spot/sun lights.
Is the theoroy, anyway.
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Shadow volumes optimization

Post by revelator »

soft shadows are also doable with stencil volumes, albeit a bit hacky in doom3 since Theres no depth texture access sikkmod uses a small hack to emulate one.
Speedwise its even worse than sheer stencil volumes though and because of the hack it suffers from a bit of the same problem that SSAO does in sikkmod.
Productivity is a state of mind.
Barnes
Posts: 232
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow
Contact:

Re: Shadow volumes optimization

Post by Barnes »

reckless wrote:soft shadows are also doable with stencil volumes, albeit a bit hacky in doom3 since Theres no depth texture access sikkmod uses a small hack to emulate one.
Speedwise its even worse than sheer stencil volumes though and because of the hack it suffers from a bit of the same problem that SSAO does in sikkmod.
Yes, I know how it was done. I is not hard to do, but I do not see the need (only speed falls)
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Shadow volumes optimization

Post by revelator »

Just an option :) doom3 actually has an experimental renderer in Draw_exp.cpp that utilized shadowmapping but the shaders were missing in the final release.
It was rather nasty though using the wgl extentions instead of newer ARB ones but it gave an idea on how to get it.
Productivity is a state of mind.
Barnes
Posts: 232
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow
Contact:

Re: Shadow volumes optimization

Post by Barnes »

reckless wrote:Just an option :) doom3 actually has an experimental renderer in Draw_exp.cpp that utilized shadowmapping but the shaders were missing in the final release.
It was rather nasty though using the wgl extentions instead of newer ARB ones but it gave an idea on how to get it.
Yes i saw it. http://www.uraldev.ru/articles/files/45 ... 04_eng.txt Carmak about doom3 and experemental render path with shadow buffers
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Shadow volumes optimization

Post by revelator »

Biggest issue if fixing the exp renderer would be that the shadowmaps only Work on entities not on the World, so the World shadows would still be stencil volumes.
Someone WHO knows more about it than me could probably fix that oversight though :)
Productivity is a state of mind.
Barnes
Posts: 232
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow
Contact:

Re: Shadow volumes optimization

Post by Barnes »

I decided to use only the z-fail vulumes. Geometry as I said simple and large overload will not be
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Shadow volumes optimization

Post by revelator »

Your latest svn build seems to have reasonably nice shadows :) quite a bit better than doom3's even.
Nice Work :D i love your parallax shader also, would be damn nice to get that one working in Doom3 but as far as i know the problem is material based (well not really cause it applies the effect on every damn surface :S) id rather have a material based version that way i could apply the effect on select surfaces only. Hmm i hope someone can lend a hand with that part someday as it seems i have taken over maintainance off sikkmod heh :lol:
Productivity is a state of mind.
Barnes
Posts: 232
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow
Contact:

Re: Shadow volumes optimization

Post by Barnes »

Thanks for the tip, but you overestimate my contribution in to parallax shader. I just optimized for speed is what you can see in qfusion or in dark places. The idea is simple as a couple of cents :)
Spiney
Posts: 63
Joined: Mon Feb 13, 2012 1:35 pm

Re: Shadow volumes optimization

Post by Spiney »

I think D3 BFG added some optimizations found in this talk to reduce overdraw, at least I noticed some console variable...
http://www.terathon.com/gdc05_lengyel.pdf
revelator
Posts: 2621
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Re: Shadow volumes optimization

Post by revelator »

Still quite nice Work :) only recently started looking into C++ seriously and learning a new language like ARB assembly / GLSL is pretty hard at my age :S C++ was doable because it shares some parts with C but still yikes!!!. You do not want to know how long it took for me to get the ARB watershader working in my realm engine :oops:
Productivity is a state of mind.
Barnes
Posts: 232
Joined: Thu Dec 24, 2009 2:26 pm
Location: Russia, Moscow
Contact:

Re: Shadow volumes optimization

Post by Barnes »

Spiney wrote:I think D3 BFG added some optimizations found in this talk to reduce overdraw, at least I noticed some console variable...
http://www.terathon.com/gdc05_lengyel.pdf
Original d3 use light scissors and depth bounds, but depth bounds test work only on gf anf lastest ati cars
Post Reply