Original Post
Hi there! Firstly, execuse me if you cannot understand because of my bad English. In shadow mapping, if you use PCF (Percentage-Closer Filtering), you use an epsilon value (bias) to check whether a pixel is lit or shadowed. Like this: float dx = 1/ShadowSize; float2 tc = ProjectedUV.xy; flaot D = ProjectedUV.z/ProjectedUV.w; float s0 = (tex2D (smp, tc).r + epsilon < D ) ? 0.0f : 1.0f; float s1 = (tex2D (smp, tc + float2 (dx, 0)).r + epsilon < D ) ? 0.0f : 1.0f; float s2 = (tex2D (smp, tc + float2 (0, dx)).r + epsilon < D ) ? 0.0f : 1.0f; float s3 = (tex2D (smp, tc + float2 (dx, dx)).r + epsilon < D ) ? 0.0f : 1.0f; And you know, the main problem is to choose the correct epsilon value to avoid artifacts. To use a constant epsilon value is not a good way. Because, if the light goes so closer to the occluder, some artifacts will occur. But for long distances, constant epsilon values can be used; but this time, shadow my go farther from occluder. Now I want to talk about my pretty good (but not absolute), simple solution. As I mentioned, shadow artifacts are related to Light position. For this reason, epsilon values must be calculated using distance of light. d = length (LightPosW - VertexPosW); epsilon = 1 / (d*d - 2*d); Where, LightPosW = World-Space Pos. of Light VertexPosW = World-Space Pos. of Vertex. Now, let'me show some results. Please be patient and look and compare all of'em. (When I press E, epsilon value toggles between 0.00005f and the value I calculated above. The spotlight is mounted on a skull mesh and I use this mesh to move the light. Also, this light projects a flashlight texture. Note: There's no use of Photoshop or another software): STATE 1: Light's so close to occluder epsilon = 0.00005f; ScreenShot1 epsilon = 1 / (d*d - 2*d); ScreenShot2 STATE 2: Light's a bit farther (normal mapping activated) epsilon = 0.00005f; ScreenShot3 epsilon = 1 / (d*d - 2*d); ScreenShot4 STATE 3: Light's so far (normal mapping activated) epsilon = 0.00005f; ScreenShot5 epsilon = 1 / (d*d - 2*d); ScreenShot6 So, what do you think? Thanks. Rohat. [Edited by - programci_84 on June 21, 2009 3:47:07 AM]