Questions to Yann: cache for shadow maps

Started by
22 comments, last by Yann L 19 years, 9 months ago
Where do you get such awesome source art?
-jonnii=========jon@voodooextreme.comwww.voodooextreme.com
Advertisement
Quote:Original post by Ysaneya
That does sound interesting but i'm not sure to see how you can do that in a pixel shader.

Here's some pseudo-code:
// Offset the texcoords by half a texelofstex = fragment.texcoord[0] - (0.5 / mapsize)// Texel sizetsize = 1.0 / mapsize// Get four shadowmap samples at the cornerss1 = ShadowSample(ofstex.x, ofstex.y)s2 = ShadowSample(ofstex.x+tsize.x, ofstex.y)s3 = ShadowSample(ofstex.x, ofstex.y+tsize.y)s4 = ShadowSample(ofstex.x+tsize.x, ofstex.y+tsize.y)// Get the fractional xy position of the fragment within the texelfpos = fraction(ofstex * mapsize)// Interpolate the texel shadow factorr1 = lerp(s1, s2, fpos.x)r2 = lerp(s3, s4, fpos.x)shadowfactor = lerp(r1, r2, fpos.y)


Quote:Original post by Ysaneya
Speaking of TSMs, i've read the papers about it, but how well does it handle frustums with an infinite (or at least very far) far clipping plane ?

Depends on what you consider very far. For lights such as the sun, you can still combine it with some other technique (for example subdividing the frustum along the depth axis). But it depends on how you redistribute the map resolution. You can should experiment with different range mappings, it's mostly trial and error.
Quote:Original post by Yann L
Here's some pseudo-code:
// Offset the texcoords by half a texelofstex = fragment.texcoord[0] - (0.5 / mapsize)// Texel sizetsize = 1.0 / mapsize// Get four shadowmap samples at the cornerss1 = ShadowSample(ofstex.x, ofstex.y)s2 = ShadowSample(ofstex.x+tsize.x, ofstex.y)s3 = ShadowSample(ofstex.x, ofstex.y+tsize.y)s4 = ShadowSample(ofstex.x+tsize.x, ofstex.y+tsize.y)// Get the fractional xy position of the fragment within the texelfpos = fraction(ofstex * mapsize)// Interpolate the texel shadow factorr1 = lerp(s1, s2, fpos.x)r2 = lerp(s3, s4, fpos.x)shadowfactor = lerp(r1, r2, fpos.y)



Ok, it works, that's really nice, i now have a "decent" quality.
For posterity, there are some minor bugs in your shader:

fpos = fraction(ofstex * mapsize)


should be:

fpos = fraction(fragment.texcoord[0] * mapsize)


Or you won't effectively be sampling at the correct texel position.

In addition, since textures are vertically inverted (ie. origin is bottom-left, not top-left), this:

shadowfactor = lerp(r1, r2, fpos.y)


should become:

shadowfactor = lerp(r2, r1, fpos.y)


Other than that it works flawlessly. I need to test my performance now but i'm pretty sure it's faster than 16 or even 8 samples :) I'm actually surprized that i have never heard of this "bilinear interpolation for shadow map filtering" trick before, since i generally try to stay aware of all the graphics techniques.

Quote:Original post by Yann L
Depends on what you consider very far. For lights such as the sun, you can still combine it with some other technique (for example subdividing the frustum along the depth axis). But it depends on how you redistribute the map resolution. You can should experiment with different range mappings, it's mostly trial and error.


I was indeed thinking to the sun. I plan on using it for terrain shadows, and i have an infinite far clipping plane in that case (ie. that's for a planet renderer where the horizon is only defined by the curvature of Earth). But i can still subdivide it along the depth. I wonder if you could see the joints between the multiple depths shadow maps, but i guess not if the correct distances are chosen. Yet another thing to test..

Anyway, many thanks for your help, i think i now know enough details of shadow mapping to apply it to a "real world" scene.

Y.
Quote:Original post by Ysaneya
Ok, it works, that's really nice, i now have a "decent" quality.
For posterity, there are some minor bugs in your shader:

Oh yes, thanks for the corrections. I just typed this up from the top of my head, while watching a political debate on TV, so I probably wasn't really that focused :P

Quote:Original post by Ysaneya
Other than that it works flawlessly. I need to test my performance now but i'm pretty sure it's faster than 16 or even 8 samples :)

Considering that the shadow comparisons return a scalar rather than a full colour, the shader can be pretty well optimized.

Quote:Original post by Ysaneya
I'm actually surprized that i have never heard of this "bilinear interpolation for shadow map filtering" trick before, since i generally try to stay aware of all the graphics techniques.

Well, nvidia knew about it :) Its hardware implementation is patented, so that might be a reason. The software implementation is just a 1 to 1 copy of the hardware behaviour. I needed to create such a shader in order to ensure visual continuity when mixing shader and hardware fake-PCF on nvidia hardware.

Quote:Original post by Ysaneya
I was indeed thinking to the sun. I plan on using it for terrain shadows, and i have an infinite far clipping plane in that case (ie. that's for a planet renderer where the horizon is only defined by the curvature of Earth). But i can still subdivide it along the depth. I wonder if you could see the joints between the multiple depths shadow maps, but i guess not if the correct distances are chosen. Yet another thing to test..

Yep, depends a lot on how you adjust the relative distances of the separate tiles. You could actually remove most of the discontinuities between the maps, but from my experience, its not worth the effort. Under optimal adjustment, the 2nd map will already be pretty far from the camera, and a 1 texel wide discontinuity won't be visible in the distance.

This topic is closed to new replies.

Advertisement