🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Calculating precise depth bias for shadow maps

Started by
13 comments, last by Josh Klint 1 year, 8 months ago

I'm getting really clean beautiful results simply using vkCmdSetDepthBias(), rather than trying to add an offset to the shadow map coordinate. This problem is solved.

10x Faster Performance for VR: www.ultraengine.com

Advertisement

I am seeing some small artifacts on the edges of cube shadow maps. The cubemap is using texture clamp on the UVW axes. The w component of the shadow coordinate uses the largest value of the vector:

shadowCoord.w = max( abs(shadowCoord.x), abs(shadowCoord.y) );
shadowCoord.w = max(shadowCoord.w, abs(shadowCoord.z) );

I think the problem is the PCF filtering. But this shouldn't really be happening if texture clamping is enabled, should it?

I can get rid of it by multiplying the major axis of the vector by 1.01, but that shouldn't really be necessary. It's like there is a mismatch between what I think the largest axis is and what the GPU thinks it is.

10x Faster Performance for VR: www.ultraengine.com

Josh Klint said:
I think the problem is the PCF filtering. But this shouldn't really be happening if texture clamping is enabled, should it?

Sorry to resurrect this thread, but did you figure out how to solve this problem? I have the same artifact with cube map shadows. It's caused by PCF but I can't explain why. The texture is clamped, and this doesn't make a difference with the artifact.

Aressera said:

Josh Klint said:
I think the problem is the PCF filtering. But this shouldn't really be happening if texture clamping is enabled, should it?

Sorry to resurrect this thread, but did you figure out how to solve this problem? I have the same artifact with cube map shadows. It's caused by PCF but I can't explain why. The texture is clamped, and this doesn't make a difference with the artifact.

Yes, I used an array sampler instead of a cubemap sampler. I did not have to change any of the shadowmap rendering code to do this. The math for precise offsets for taking multiple samples of a cubemap is very slow, but if you use the same texture with a 2D array sampler (with 6 layers) you can treat each face as a 2D texture. The shader math for these offsets is very simple, and the edge issues go away forever.

There's also an extension that is supposed to make non-seamless cubemaps but when I tried it I did not see any difference: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_non_seamless_cube_map.html

10x Faster Performance for VR: www.ultraengine.com

This topic is closed to new replies.

Advertisement