LightComponent.h文件里增加shaft里shader参数的设置:

	UFUNCTION(BlueprintCallable, Category = \"Rendering|Components|Light\")
	void SetLightShaftAlphaRadius(float NewValue);

	UFUNCTION(BlueprintCallable, Category = \"Rendering|Components|Light\")
	void SetLightShaftBlurRadius(float NewValue);

跟BloomTint逻辑一样:

  UFUNCTION(BlueprintCallable, Category=\"Rendering|Components|Light\")
    	void SetBloomThreshold(float NewValue);
    
    	UFUNCTION(BlueprintCallable, Category=\"Rendering|Components|Light\")
    	void SetBloomTint(FColor NewValue);

另外,这两个属性需要在属性窗口里可见,属性定义跟bloomTInt一样,在LightProxy里也有相同名字的属性,update函数也会实时更新这俩属性,FViewInfo里也有这俩属性。

设置lightShaft位置的接口:

在SceneVisibility文件,PostVisibility Setup函数中,worldSpaceBlurOrigin是通过LightSceneInfo->Proxy->GetPosition()获取的,那么这个Position是啥?GetPosition返回的是position,Position又是通过Light->GetLightPosition赋值的(),如下所示:

void FScene::UpdateLightTransform(ULightComponent* Light)
{
   if(Light->SceneProxy)
   {
   	FUpdateLightTransformParameters Parameters;
   	Parameters.LightToWorld = Light->GetComponentTransform().ToMatrixNoScale();
   	Parameters.Position = Light->GetLightPosition();
   	ENQUEUE_UNIQUE_RENDER_COMMAND_THREEPARAMETER(
   		UpdateLightTransform,
   		FScene*,Scene,this,
   		FLightSceneInfo*,LightSceneInfo,Light->SceneProxy->GetLightSceneInfo(),
   		FUpdateLightTransformParameters,Parameters,Parameters,
   		{
   			FScopeCycleCounter Context(LightSceneInfo->Proxy->GetStatId());
   			Scene->UpdateLightTransform_RenderThread(LightSceneInfo, Parameters);
   		});
   }
}

而GetLightPosition又是啥?在DirectionalLightComponent.cpp文件中,该函数的重载实现为:

FVector4 UDirectionalLightComponent::GetLightPosition() const
{
	return FVector4(-GetDirection() * WORLD_MAX, 0 );
}

GetDirection又是啥?在LightComponent.cpp文件中,GetDirection函数:

FVector ULightComponent::GetDirection() const 
{ 
	return GetComponentTransform().GetUnitAxis( EAxis::X );
}

我们用我们自己的接口代替LightSceneInfo->Proxy->GetPosition(),为了light位置能用代码控制变化,我们用GetLightShaftOverridePositionForLightShafts()和void UDirectionalLightComponent::SetLightShaftOverridePosition(const FVector4& InPosition)来get和set这个值。
另外,set时,参数就要用一个component位置跟太阳位置变化一样,然后用这个component的GetComponentTransform.GetUnitAxis(EAxis::X),这是方向,然后*-1*WORLD_mAX,然后和0组成FVector4,跟前面分析的GetLightPosition的代码一样实现即可。

收藏 打印