1

由于我使用的纹理颜色深沉(这些伪影不可见),我以前从未见过的硬阴影有一种奇怪的行为。这是我使用 3 种不同阴影贴图分辨率的问题的一些屏幕截图:

1) 阴影贴图 160 * 120

在此处输入图像描述

如您所见,立方体表面有一种牙齿。

这是从灯光位置看的场景:

在此处输入图像描述

这是阴影贴图:

在此处输入图像描述

2) 阴影贴图 640 * 480

在此处输入图像描述

分辨率越高,伪影就越不明显,因为阴影贴图带来了更高的精度。

这是从灯光位置看的场景:

在此处输入图像描述

这是阴影贴图:

在此处输入图像描述

我尝试了更高的其他分辨率。当然,伪影越来越小,但如果你放大表面,它们仍然可见。

这是我在第二次传递期间在片段着色器中使用的代码:

[...]

uniform sampler2DShadow ShadowSampler[MAX_LIGHT_COUNT];

[...]

float GetDynamicShadowBias(vec3 normalDir_cs, vec3 lightDir_cs)
{
    float cosTheta = clamp(dot(normalDir_cs, lightDir_cs), 0.0f, 1.0f);
    float bias = 0.005f * tan(acos(cosTheta));

    return (clamp(bias, 0.0f, 0.01f));
}

float GetBiased_Hard_ShadowFactor(vec3 normalDir, vec3 lightDir, int idx)
{    
    if (ShadowCoords[idx].w > 0.0f)
    {
        float bias = GetDynamicShadowBias(normalDir, lightDir);

        float LightToOccluderClipDist = texture(
            ShadowSampler[idx], ShadowCoords[idx].xyz/ShadowCoords[idx].w);

        float LightToVertexClipDist = (ShadowCoords[idx].z - bias)/ShadowCoords[idx].w;

        if (LightToOccluderClipDist < LightToVertexClipDist)
            return (0.0f);
    }
    return (1.0f);
}

所以我想知道是否有可能去除立方体边缘的这些伪影。我试图在没有真正成功的情况下使用阴影偏差(有关信息,我在第一遍(填充深度纹理)期间使用 FRONT_FACE 剔除)。

4

1 回答 1

3

There are 2 things going on here. One is that this is a limitation of standard shadow maps. Because the shadow of any given object will take up some potentially smaller number of pixels in the map, when you then cast that map onto the scene, those parts can get re-enlarged and you'll get aliasing.

The second thing that appears to be happening is that your shadows are essentially 1 bit, it appears. They're either black or white. If you were to in some way antialias the map while creating it (say supersampling or some other technique), it would be less noticeable (though it wouldn't go away completely in my experience).

There are some techniques that build on classic shadow maps. One is Subpixel Shadow Mapping from SIGGRAPH 2013. (There were some other shadow papers that year, too.) I've also seen ray-casted shadows implemented in realtime via GLSL recently. (Sorry, can't find the link! I'll post later if I can dig it up.)

于 2014-10-03T03:26:51.983 回答