Red colored point light not projecting correctly [D3D11]

86 Views Asked by At

In my d3d11 scene, I have a point light projecting onto this planet. To help identify the fact that it is the point light, I colored it red in the code below.

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

The issue is that although the attenuation of the light is colored correctly, the rest of the light is not.

As displayed here

I am quite unsure of what causes this. I figured something within my calculation for the light in my pixel shader was causing the output color to be set as the full color of the texture, but I don't have anything that backs up that theory.

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;
    }
}

The following is the code for my point light, what could be wrong with it to cause this issue?

1

There are 1 best solutions below

0
Gunchap Red On

Just letting you guys know, I already had long since fixed this. I believe there was a mistake in the attenuation formula.