问题描述
在我的 d3d11 场景中,我有一个点光源投射到这个星球上。为了帮助识别它是点光源这一事实,我在下面的代码中将其涂成红色。
pointLight.light = /*DirectionalLight*/{ { 0.9f,0.2f,0.1f,0.5f },{ 0,1,1 } };
问题是,虽然光的衰减是正确着色的,但其余的光却没有。
我不确定是什么原因造成的。我认为在我对像素着色器中的光的计算中,某些东西导致输出颜色被设置为纹理的全色,但我没有任何支持该理论的东西。
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;
}
}
以下是我的点光源的代码,它可能有什么问题导致这个问题?
解决方法
只是让你们知道,我早就解决了这个问题。我认为衰减公式有误。