Category Hierarchy

在我的d3d11场景中,我有一个投射到这个星球上的点光源。为了帮助识别它是点光源的事实,我在下面的代码中将其着色为红色。

pointLight.light = /*DirectionalLight*/{ { 0.9f,0.2f,0.1f,0.5f }, { 0,1,0,1 } };

问题是,尽管灯光的衰减是正确着色的,但其余灯光却不是。

As displayed here

我不太确定是什么导致了这一点。我认为我的像素着色器中的灯光计算中的一些东西导致输出颜色被设置为纹理的全色,但我没有任何支持这一理论的东西。

float3 calculatePointLight(
    float4 pointColor,
    float4 pointPos,
    float4 pointRad,
    float3 surfaceNormal,
    float3 surfacePosition,
    float3 cameraPos,
    float specularPower,
    float specularIntensity)
{
    float3 lightDir = normalize(pointPos.xyz - surfacePosition);
    float lightRatio = saturate(dot(lightDir, surfaceNormal));
    float4 outColor = saturate(lightRatio * pointColor);

    float Attenuation = 2.0f - saturate(length(pointPos - surfacePosition) / pointRad.x);

    outColor *= Attenuation;

    if (outColor.x == zero.x && outColor.y == zero.y && outColor.z == zero.z)
    {
        return outColor;
    }
    else
    {
        float3 ViewDirection = normalize(cameraPos - surfacePosition);
        float3 HalfVector = normalize((-pointPos) + ViewDirection);
        float Intensity = max(saturate(dot(surfaceNormal, normalize(HalfVector))) * specularPower, 0);

        return outColor + specularIntensity * Intensity;
    }
}

以下是我的点光源的代码,它可能是什么错误导致这个问题?

转载请注明出处:http://www.ydsst.com/article/20230304/1902346.html