View Full Version : Need help with Variance Shadow Mapping technique

11-16-2012, 03:43 AM
Hello everyone.

I'm trying to make a small demo of VSM technique to learn it. I'm using OpenGL 2.0 + framebuffer extension, also using SDL and GLEW for utility. I've got some visual problems, looking like that:
(clickable image link to imgbox.com, image host)
http://t.imgbox.com/abxPqrZH.jpg (http://imgbox.com/abxPqrZH)

After searching information on this forum, i've found a trick of clamping minimum value of (M2 - M1*M1) by 0.00002. It makes shadow look much better, except certain angles, which still look like that:
(clickable image link to imgbox.com, image host)
http://t.imgbox.com/acwmcHhC.jpg (http://imgbox.com/acwmcHhC)

If I increase this minimum value, artifacts become less visible, at the same time shadow becomes fainter (probably that's why artifacts less visible too).

I have done blurring after second test. While it helped, some artifacts are still visible:
(clickable image link to imgbox.com, image host)
http://t.imgbox.com/aduU7lMn.jpg (http://imgbox.com/aduU7lMn)

Full source code (tested on Gentoo Linux 64bit) is here: http://pastebin.com/iAkeW85V
I know it's not optimized in any way, and many textures/fbos could be reused and some textures combined, i'll do it later, for now I want to get rid of artifacts. Please help me to get rid of them.

carsten neumann
11-19-2012, 09:46 AM
Hmm, where is the light source in your second and third image (from the shadow I would guess it is a point light somewhere above the box)? Shouldn't the sides of the box then be not lit? In other words can you only do shadow lookups in your shader when the fragment is actually receiving light from the shadow casting source? That should get rid of those artefacts on faces that are not facing the light source.

11-19-2012, 12:01 PM
I have checked your guess. My cube's points are:
top side:
( 1.0f, 2.5f,-1.0f)
(-1.0f, 2.5f,-1.0f);
(-1.0f, 2.5f, 1.0f);
( 1.0f, 2.5f, 1.0f);

bottom side:
( 1.0f, 0.5f, 1.0f);
(-1.0f, 0.5f, 1.0f);
(-1.0f, 0.5f,-1.0f);
( 1.0f, 0.5f,-1.0f);

When light's position is about (1.0f+-0.02f, 6.0f, 1.0f+-0.02f) (it's almost right above vertical edge of cube), I get this artifact on 2 sides. But, when x and z coordinates are from 1.0f to 1.02f it should be lit, and when they're from 0.98f to 1.0f it should give soft shadow.

I'm not too much familiar with lightning and shadows calculations, I was doing VSM basing on information from this site: http://www.punkuser.net/vsm/ (actually, this paper: http://www.punkuser.net/vsm/vsm_paper.pdf).

I've found that floating-point texture usage would produce less artifacts. I'm not sure if GL_DEPTH_COMPONENT32 is floating-point texture. As far as I could find information, it is not (I can be wrong here), so I'll try other texture formats tomorrow and see if this will help me to get rid of artifacts.

11-29-2012, 03:22 AM
Finally I've got a bit of spare time to try floating-point textures. As i've found out, using GL_DEPTH_COMPONENT32F or GL_RGBA32F (floating-point texture formats) doesn't reduce artifacts. Yes, they can contain numbers outside of [0; 1] range, but (as i've found in documentation) they are don't necessary have better precision. Any ideas how to get rid of those artifacts visualized in first post are welcome.