平行光:和光源方向有关,和位置无关
Lambert余弦=dot(n,l)
点光源:和光源方向无关,和位置有关
简单的线性算法:Lambert余弦(d:强度 E:EndAttenuation 点到光源的距离 s:StartAttenuation 衰减半径,超过这个距离开始衰减)
影响因子算法:
c:常数衰减因子
i:线性衰减因子
q:平分衰减因子
d:受点与光源之前距离影响
聚光灯:
内外角
float3 LightVector = L.Position - InObjectWorldLocation;;
float Distance = length(LightVector);
if (Distance < L.EndAttenuation)
{
float DotValue = max(dot(NormalizeLightDirection, L.LightDirection), 0.f);
//float4 LightStrength = float4(1.f, 1.f, 1.f, 1.f) * pow(DotValue,1.f);
float4 LightStrength = float4(1.f, 1.f, 1.f, 1.f) * float4(L.LightIntensity, 1.f);
float Theta1 = acos(DotValue);
if (Theta1 == 0.f)
{
return LightStrength;
}
else if (Theta1 <= L.ConicalInnerCorner)
{
return LightStrength;
}
else if (Theta1 <= L.ConicalOuterCorner)
{
float OuterInnerDistance = L.ConicalOuterCorner - L.ConicalInnerCorner;
float CurrentDistance = OuterInnerDistance - (Theta1 - L.ConicalInnerCorner);
return (CurrentDistance / OuterInnerDistance) * LightStrength;
////return AttenuationPointLights1(L, Distance) * LightStrength;
//return AttenuationPointLights2(
// L,
// Distance,
// 0.f,//c
// 0.4f,//i
// 0.3f) * LightStrength;//q
}
}