DX灯光笔记

平行光:和光源方向有关,和位置无关

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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值