【问题标题】:Red colored point light not projecting correctly [D3D11]红色点光源未正确投射 [D3D11]
【发布时间】:2021-05-18 20:13:36
【问题描述】:

在我的 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;
    }
}

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

【问题讨论】:

  • ngl 整个事情很混乱。你能详细描述一下,预期的结果是什么?它和你得到的有什么不同?

标签: directx-11 hlsl pixel-shader


【解决方案1】:

只是让你们知道,我早就解决了这个问题。我认为衰减公式有误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-09
    • 2018-03-23
    • 2021-09-29
    • 1970-01-01
    • 2018-06-14
    • 1970-01-01
    相关资源
    最近更新 更多