Soft volumetric stencil shadows - how?

Can soft shadows be rendering using volumetric stencil shadows? How could that be done? If yes, please explain details. If a shader program is required, please outline it - I am a shader programming noob knowing barely the most things about this.

There are some algorithms, yes, but they require a lot more work and should be slower than plain shadowmap bilinear (or even PCF) filtering in most cases, because the CPU is used for additional wedge computations etc. I doubt this will even change with geomtetry shaders.

Anyways, here is a link for you.

I had googled but not found anything - probably chose inappropriate keywords.

Someone has proposed to render the shadowed parts into a texture, blur it and then render the texture as quad over the entire scene. I wonder whether I should render into an FBO, and if I can use the stencil buffer I created w/o the FBO for rendering into it? I don’t know how to write a blur shader (though I will probably/hopefully find one with google …)

i’m working on an simple approach atm, this is my first result:

still have to make it work with multiple light sources, though. the idea is quite simple: render your volumes to a texture (you can’t use fbo, as these do not support stencil yet, at least on ati) and blur this texture in a shader & blend it using a full screen quad (or use the result in another shader)… this way you can also vary the shadows’ quality, sth that’s not possible with hard edged shadows.

How do I render the volumes to a texture so that I get kind of a shadow map I can subsequently blur? I don’t have that inc/dec operations like in the stencil, so wherever I render the volume, that texture just gets black (or whatever color I use).

How do I blur the result? I have no clue how such a shader would have to look like. I have seen an example, but don’t how to use it in my program. The sample code contains two blur functions (horz and vert), but I don’t know how to call them (do I have to add some code to that sample code?)

simply render your shadow volumes as usual, but your geometry with a shader which renders it all white. copy this to a texture which you can then blur… there’s an example of a blur filter in the ati sdk, e.g. you’ll have to apply it twice, once in vertical direction and then in horizontal direction on the result.

still have to see how i can get rid of the bleeding edges :stuck_out_tongue: btw, if i want to use my shadow texture in ashader instead on a screen-aligned quad, how can i get the correct texture coords for each fragment?


look at this picture:


If I render the volume black and the rest white, the red and purple volume will hide geometry it shouldn’t hide. How do I avoid that?

I could render just the geometrie’s depth values to the texture, turn depth test off, render a white quad over it, then depth test on, render shadows, right? Or I could render the geometry, then copy the depth buffer to a texture … I have read about this, but don’t know how to do that … I tried it, following a tutorial, but that didn’t seem to work …

I also don’t know how to use several shaders. The shaders are executed when I render the quad. Do I have to render it twice?

you have working stencil shadows, don’t you? now render your scene as usual, but instead of textures and lighting applied to your geometry, render it all white. copy this to a texture. this results in an image like this:

yes you’ll have to render it twice:

  1. render it once with the texture applied and the first blur filter
  2. render the resulting image to a quad again and apply the second blur filter.

Oh I see: I have to render the final, shadowed scene.

Do you have a blur filter for me, together with a description how to insert it into rendering code?

If I render the shadow mask to a texture, blurring it, and blur the resulting image again, won’t I blur everything in it and not just the shadow?

Can I render an FBO used as a texture to itself, or do I need two FBOs? Oh crap, you said ATI doesn’t yet support FBO+stencil …

Originally posted by HellKnight:
shadowmap bilinear (or even PCF) filtering
That’s blurred shadows, not soft shadows :wink:

Methods of rendering soft shadows are :[ul][li]several shadow volumes : render several time the stencil shadows while moving a bit the light source. Quite slow[]render a shadow volume in a texture, and blur it according to the distance from the occluder. So while you render the shadowed scene you’ll also render the distance from occluders in another texture or in one of the color channel of the destination buffer.[]render shadowmap and blur them in the same way as in the previous point.[/ul][/li]In every case, you have to take care not to add shadows that should be hidden during the blurring process.


sorry, but I haven’t asked for general guidelines, of those I have enough. I have some detailled questions (see above) and hope someone with good knowledge of this stuff will give me some detailled steps (maybe together with required OpenGL calls in complicated cases) for the procedure.

Originally posted by tfpsly:
That’s blurred shadows, not soft shadows :wink:
Percentage closer filtering changes the blur kernel size depending on the distance to the occluder, effectively varying the umbra/penumbra region areas. I’d call that soft shadows.

We’re talking about an approximation I assume, otherwise radiosity would be the only “accurate” solution.