透明直接光和间接光生成

直接光:

Scene:Lights:DirectLighting:InjectTranslucencyVolume

TranslucentLightInjectionShaders.usf

void InjectMainPS(
	FWriteToSliceGeometryOutput Input,
	out float4 OutColor0 : SV_Target0,
	out float4 OutColor1 : SV_Target1
	)
{
	OutColor0 = 0;
	OutColor1 = 0;


	float3 TranslatedWorldPosition;
	{
		float ZPosition = View_TranslucencyLightingVolumeMin[VolumeCascadeIndex].z + (Input.LayerIndex + .5f) * View_TranslucencyLightingVolumeInvSize[VolumeCascadeIndex].w;

		TranslatedWorldPosition = float3(View_TranslucencyLightingVolumeMin[VolumeCascadeIndex].xy + Input.Vertex.UV / View_TranslucencyLightingVolumeInvSize[VolumeCascadeIndex].xy - .5f * View_TranslucencyLightingVolumeInvSize[VolumeCascadeIndex].w, ZPosition);
	}
	float3 WorldPosition = TranslatedWorldPosition -  LWCToFloat( GetPrimaryView() .PreViewTranslation) ;


	float3 VolumeUVs = float3(Input.Vertex.UV, (Input.LayerIndex + .5f) * View_TranslucencyLightingVolumeMin[VolumeCascadeIndex].w);

	float Masking = 1.0f;

	{

		float3 LightVector = DeferredLightUniforms_TranslatedWorldPosition - TranslatedWorldPosition;
		clip(1.0f / (DeferredLightUniforms_InvRadius * DeferredLightUniforms_InvRadius) - dot(LightVector, LightVector));
	}


	float3 NormalizedLightVector = GetNormalizedLightVector(TranslatedWorldPosition);

	float3 TranslatedWorldPositionForLighting;
	float3 WorldPositionForLighting;
	{
		float VoxelSize = View_TranslucencyLightingVolumeInvSize[VolumeCascadeIndex].w;
		float3 LightingOffset = 1 * GetBoxPushout(NormalizedLightVector, .5f * VoxelSize);

		WorldPositionForLighting = WorldPosition + LightingOffset;
		TranslatedWorldPositionForLighting = TranslatedWorldPosition + LightingOffset;
	}

	{
		float3 WorldLightVector;


		float Attenuation = CalcLightAttenuation(TranslatedWorldPositionForLighting, WorldLightVector);

		bool bPointLight = false;
		bool bSpotLight = false;


			bPointLight = SpotlightMask < 1;
			bSpotLight = SpotlightMask >= 1;


		bool bUnused = false;
		float ShadowFactor = ComputeVolumeShadowing(TranslatedWorldPositionForLighting, bPointLight, bSpotLight, bUnused);

		ShadowFactor *= GetLightFunctionShadowFactor(TranslatedWorldPositionForLighting);

		if (VolumeCascadeIndex == 1)
		{

			float TransitionScale = 10;

			float3 FadeUVs = VolumeUVs * (1 + 4 * View_TranslucencyLightingVolumeMin[VolumeCascadeIndex].w) - 2 * View_TranslucencyLightingVolumeMin[VolumeCascadeIndex].w;

			float3 LerpFactors = saturate((.5f - abs(FadeUVs - .5f)) * TransitionScale);
			float FinalLerpFactor = LerpFactors.x * LerpFactors.y * LerpFactors.z;

			Attenuation = lerp(0, Attenuation, FinalLerpFactor);
			ShadowFactor = lerp(0.0f, ShadowFactor, FinalLerpFactor);
		}

		float3 Lighting = DeferredLightUniforms_Color / PI * Attenuation * ShadowFactor;

		FTwoBandSHVectorRGB SHLighting = MulSH(SHBasisFunction(NormalizedLightVector), Lighting);

		float DirectionalLightContribution = 0;

		OutColor0 = float4(SHLighting.R.V.x, SHLighting.G.V.x, SHLighting.B.V.x, DirectionalLightContribution);

		float3 LuminanceWeights = float3(.3, .59, .11);
		float3 Coefficient0 = float3(SHLighting.R.V.y, SHLighting.G.V.y, SHLighting.B.V.y);
		float3 Coefficient1 = float3(SHLighting.R.V.z, SHLighting.G.V.z, SHLighting.B.V.z);
		float3 Coefficient2 = float3(SHLighting.R.V.w, SHLighting.G.V.w, SHLighting.B.V.w);
		OutColor1 = float4(dot(Coefficient0, LuminanceWeights), dot(Coefficient1, LuminanceWeights), dot(Coefficient2, LuminanceWeights), 0);
	}

	OutColor0 *= Masking;
	OutColor1 *= Masking;
}

间接光生成:

Scene:DiffuseIndirectAndAO:TranslucencyVolumeLighting

有些复杂,后面需要再看。

你可能感兴趣的:(#,UE之透明,UE)