Shadow techniques

Stainless 151 May 18, 2013 at 08:57 shadows

I’m struggling at the moment with getting shadows working on OpenGLES 2

At the moment I’m using a depth buffer based technique, but my scene is so big that the shadows end up big and clumpy.

I’m thinking about stencil shadows, but I’m not sure it will work with a huge scene.

Any ideas people?

I started this project two weeks ago and have two weeks left, so I’m very tight for time and can’t afford another failed attempt.

9 Replies

Please log in or register to post a reply.

Vilem_Otte 117 May 18, 2013 at 15:01

How big is the scene? What is target platform?

I implemented Z-fail shadow volumes through geometry shader some months ago (and had a thread about it here), and it performed very well for complex scenes on Radeon 6770 (also on GTX 580 - but what doesnt perform well on this category of GPU), and for moderate scenes even on notebook graphics (Mobility Radeon 5470). Though if youre targeting mobile devices, I doubt they will perform that good.

There are also other possibilities of computing shadows. Ray tracing on GPU (it IS realtime, but most probably will need a bit more work than 2 weeks)? Plannar shadows (assuming you dont have too much geometry you cast shadows on)? Shadow blobs + light maps (works well, light maps do awesome work in static scenes)? Light maps + shadow map for N dynamic actors/objects in specific range (you can create shadow map atlas pretty well, smaller objects get smaller shadow map, larger objects get larger shadow map)? etc.

If you describe a bit more details, I might give you few suggestions on how to implement it quickly, because 2 weeks arent that much time.

TheNut 179 May 18, 2013 at 15:15

Stencil shadows will give you pixel accurate resolution, but it’s not without its problems. z-near is faster than z-fail and would be more suitable for mobile devices, but you have to deal with in-shadow problems. Your shadows will also be tact sharp, something shadow maps can alleviate almost for free. I would suggest investigating cascaded shadow maps if you have some spare cycles to support it. An alternate solution would be to limit your shadow casters so that you can focus your shadow map only on the most important area in the scene rather than everything. Not that awesome, but I’ve played a few games that do that. If however you’re not bluring your shadow maps, then switching over to stencil shadows might not be all that bad since both will look the same.

Albertone 101 May 18, 2013 at 15:37

What about Dual-Paraboloid Shadow Mapping and its improvement, Improved Paraboloid Mapping?


Vilem_Otte 117 May 18, 2013 at 15:58

#TheNut - first a note, i think you mis-written z-near for z-pass :)

Blurring the shadow volumes is another thing. You can perform accurate penumbra shadows by penumbra wedges (this comes at high cost though), or just simple screen-space bilateral blur - both are although suited for PCs rather than mobile devices.

EDIT: Oh… and also an important note! The actual Z-fail algorithm seems still patented by someone. Although you are fine by using two-sided stencil instead of multi-pass version.

Stainless 151 May 19, 2013 at 09:03

I can’t give details of what I am doing (NDA’s), but think of a car racing game with a track in excess of 3.5 miles long and you’ve got the basic idea.

I already have the track and cars in with phong shading, sky cube, reflective and refractive glass, simple physics (I do mean simple, 2 weeks isn’t long) , simple AI etc.

Shadows are the last major problem to solve.

The target platform is performing well (now I am using VBO’s) I’m getting 370fps so far, plenty of spare grunt to do the shadows.

(Interestingly I get 172 fps on my laptop and over 200fps on my galaxy s3.)

I’m waiting for the GA to supply final assets and have no control over what he supplies me ( It’s a well known game company that’s doing me a favour), so I don’t know if they have baked the textures and light map.

I’m now hoping they have, so I just have to create shadows for the visible cars.

TheNut 179 May 19, 2013 at 14:06


#TheNut - first a note, i think you mis-written z-near for z-pass

Heh, yes. It’s been awhile :) I didn’t know the z-fail was patented. I always thought it was Carmack that coined the idea, but I see now he came late to the game (albeit he developed his algorithm independently). Interesting tidbit.

Reedbeta 167 May 19, 2013 at 16:58

For general shadows in outdoor areas, I think cascaded shadow maps are the way to go. It’s a proven technique that’s been used in quite a lot of games and it allows you to easily tweak the trade-off between quality and performance by adjusting the number and size of cascades.

Additionally, if you resolve all the shadow maps into a single screen-space mask, then apply the mask in the lighting shaders, you can have a lot of freedom about how many shadow maps you use and how you combine them together without adding a lot of expense to your shaders. It’s “deferred shadows”, sort of (doesn’t require deferred shading, although having the depth buffer available to sample as a texture is very helpful). For instance you could decide to have a shadow map per car when the cars are close enough to the camera, and you could blend the shadows from the per-car maps smoothly with the shadows from the overall cascade.

There’s some more details about this in Ben Diamand’s GDC 2010 talk on shadows in God Of War III. The screen-space mask I referred to is called a “white buffer” in his talk.

JarkkoL 102 May 19, 2013 at 21:25

+1 for cascaded shadow maps. There is an alternative called parallel split shadow maps (PSSM), but while they utilize the shadow map more efficiently, they lack couple of interesting properties of CSM - if you cache shadow maps in CSM, you can update them progressively, i.e. only update them every few frames to improve performance, or only render static objects to the map and update slices as the camera moves. Also unlike PSSM, you can snap them to shadow texels in world space to avoid shimmering artifacts. CSM has been used for quite long time in many shipped titles to cover large shadow range, so it’s quite a safe way to go.

Stainless 151 May 20, 2013 at 10:55

I think I’ll give CSM a go.

It’s a lot of work to get working on Opengles 2, a lot of the opengl stuff they use isn’t supported and I’ll have to find work arounds, but it looks the most likely to succeed.

Looks like sleep will be optional this week :(