UE4 LightComponent GetLightShaderParameters()

本文详细解读了不同光照组件(PointLightComponent, DirectionalLightComponent, SpotLightComponent, RectLightComponent)在渲染时如何获取并设置FLightShaderParameters参数,涉及位置、颜色、衰减、方向、纹理等关键信息。
摘要由CSDN通过智能技术生成

DirectionalLightComponent.cpp

/** Accesses parameters needed for rendering the light. */
	virtual void GetLightShaderParameters(FLightShaderParameters& LightParameters) const override
	{
		LightParameters.Position = FVector::ZeroVector;
		LightParameters.InvRadius = 0.0f;
		LightParameters.FalloffExponent = 0.0f;

		// We only apply transmittance in some cases. For instance if transmittance is evaluated per pixel, no apply it to the light illuminance.
		LightParameters.Color = FVector(GetColor() * (bApplyAtmosphereTransmittanceToLightShaderParam ? AtmosphereTransmittanceFactor : FLinearColor::White));

		LightParameters.Direction = -GetDirection();
		LightParameters.Tangent = -GetDirection();

		LightParameters.SpotAngles = FVector2D(0, 0);
		LightParameters.SpecularScale = SpecularScale;
		LightParameters.SourceRadius = FMath::Sin( 0.5f * FMath::DegreesToRadians( LightSourceAngle ) );
		LightParameters.SoftSourceRadius = FMath::Sin( 0.5f * FMath::DegreesToRadians( LightSourceSoftAngle ) );
		LightParameters.SourceLength = 0.0f;
		LightParameters.SourceTexture = GWhiteTexture->TextureRHI;
	}

SpotLightComponent.cpp

/** Accesses parameters needed for rendering the light. */
	virtual void GetLightShaderParameters(FLightShaderParameters& LightParameters) const override
	{
		LightParameters.Position = GetOrigin();
		LightParameters.InvRadius = InvRadius;
		LightParameters.Color = FVector(GetColor());
		LightParameters.FalloffExponent = FalloffExponent;
		LightParameters.Direction = -GetDirection();
		LightParameters.Tangent = FVector(WorldToLight.M[0][2], WorldToLight.M[1][2], WorldToLight.M[2][2]);
		LightParameters.SpotAngles = FVector2D(CosOuterCone, InvCosConeDifference);
		LightParameters.SpecularScale = SpecularScale;
		LightParameters.SourceRadius = SourceRadius;
		LightParameters.SoftSourceRadius = SoftSourceRadius;
		LightParameters.SourceLength = SourceLength;
		LightParameters.SourceTexture = GWhiteTexture->TextureRHI;
		LightParameters.RectLightBarnCosAngle = 0.0f;
		LightParameters.RectLightBarnLength = -2.0f;
	}

PointLightComponent.cpp

/** Accesses parameters needed for rendering the light. */
void FPointLightSceneProxy::GetLightShaderParameters(FLightShaderParameters& LightParameters) const
{
	LightParameters.Position = GetOrigin();
	LightParameters.InvRadius = InvRadius;
	LightParameters.Color = FVector(GetColor());
	LightParameters.FalloffExponent = FalloffExponent;

	LightParameters.Direction = -GetDirection();
	LightParameters.Tangent = FVector(WorldToLight.M[0][2], WorldToLight.M[1][2], WorldToLight.M[2][2]);
	LightParameters.SpotAngles = FVector2D( -2.0f, 1.0f );
	LightParameters.SpecularScale = SpecularScale;
	LightParameters.SourceRadius = SourceRadius;
	LightParameters.SoftSourceRadius = SoftSourceRadius;
	LightParameters.SourceLength = SourceLength;
	LightParameters.SourceTexture = GWhiteTexture->TextureRHI;
	LightParameters.RectLightBarnCosAngle = 0.0f;
	LightParameters.RectLightBarnLength = -2.0f;
}

RectLightComponent.cpp

/** Accesses parameters needed for rendering the light. */
void FRectLightSceneProxy::GetLightShaderParameters(FLightShaderParameters& LightParameters) const
{
	FLinearColor LightColor = GetColor();
	LightColor /= 0.5f * SourceWidth * SourceHeight;

	LightParameters.Position = GetOrigin();
	LightParameters.InvRadius = InvRadius;
	LightParameters.Color = FVector(LightColor.R, LightColor.G, LightColor.B);
	LightParameters.FalloffExponent = 0.0f;

	LightParameters.Direction = -GetDirection();
	LightParameters.Tangent = FVector(WorldToLight.M[0][2], WorldToLight.M[1][2], WorldToLight.M[2][2]);
	LightParameters.SpotAngles = FVector2D(-2.0f, 1.0f);
	LightParameters.SpecularScale = SpecularScale;
	LightParameters.SourceRadius = SourceWidth * 0.5f;
	LightParameters.SoftSourceRadius = 0.0f;
	LightParameters.SourceLength = SourceHeight * 0.5f;
	LightParameters.SourceTexture = SourceTexture ? SourceTexture->Resource->TextureRHI : GWhiteTexture->TextureRHI;
	LightParameters.RectLightBarnCosAngle = FMath::Cos(FMath::DegreesToRadians(BarnDoorAngle));
	LightParameters.RectLightBarnLength = BarnDoorLength;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值