You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#preflight 61f2e76575432e9e8e5b083e #jira UE-140298 #rb none #ROBOMERGE-AUTHOR: ben.ingram #ROBOMERGE-SOURCE: CL 18757121 in //UE5/Release-5.0/... via CL 18759609 via CL 18760254 #ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v903-18687472) [CL 18760859 by ben ingram in ue5-main branch]
66 lines
2.3 KiB
Plaintext
66 lines
2.3 KiB
Plaintext
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
/*=============================================================================
|
|
LightFunction.usf: Pixel shader for computing a light function.
|
|
=============================================================================*/
|
|
|
|
#include "Common.ush"
|
|
#include "/Engine/Generated/Material.ush"
|
|
#include "LightFunctionCommon.ush"
|
|
#include "DynamicLightingCommon.ush"
|
|
|
|
// used like this: mul(float4(SvPosition.xyz, 1), SvPositionToLight);
|
|
float4x4 SvPositionToLight;
|
|
|
|
/** Fade distance in x, disabled brightness in y, output for preview shadows mask in z. */
|
|
float3 LightFunctionParameters2;
|
|
|
|
void Main(
|
|
// in float4 ScreenPosition : TEXCOORD0, // Not used and not output in VS
|
|
in float4 SvPosition : SV_Position, // after all interpolators
|
|
out float4 OutColor : SV_Target0
|
|
)
|
|
{
|
|
ResolvedView = ResolveView();
|
|
|
|
float2 ScreenUV = SvPositionToBufferUV(SvPosition);
|
|
|
|
// make SvPosition appear to be rasterized with the depth from the depth buffer
|
|
SvPosition.z = LookupDeviceZ(ScreenUV);
|
|
|
|
float3 LightVector;
|
|
{
|
|
float4 Hom = mul(float4(SvPosition.xyz, 1), SvPositionToLight);
|
|
LightVector = Hom.xyz / Hom.w;
|
|
}
|
|
|
|
float3 TranslatedWorldPosition = SvPositionToTranslatedWorld(SvPosition);
|
|
|
|
// Calculate radial view distance for stable fading
|
|
float ViewDistance = length(PrimaryView.TranslatedWorldCameraOrigin - TranslatedWorldPosition);
|
|
|
|
float GreyScale;
|
|
{
|
|
float3 Color = GetLightFunctionColor(LightVector, TranslatedWorldPosition);
|
|
GreyScale = dot(Color, .3333f);
|
|
}
|
|
|
|
float DistanceFadeAlpha = saturate((LightFunctionParameters2.x - ViewDistance) / (LightFunctionParameters2.x * .2f));
|
|
// Fade to disabled based on LightFunctionFadeDistance
|
|
GreyScale = lerp(LightFunctionParameters2.y, GreyScale, DistanceFadeAlpha);
|
|
|
|
// Fade to disabled based on ShadowFadeFraction
|
|
GreyScale = lerp(LightFunctionParameters2.y, GreyScale, LightFunctionParameters.y);
|
|
|
|
#if FORWARD_SHADING
|
|
float LightInfluenceMask = GetLightInfluenceMask(TranslatedWorldPosition);
|
|
GreyScale = lerp(1, GreyScale, LightInfluenceMask);
|
|
OutColor = EncodeLightAttenuation(GreyScale);
|
|
#else
|
|
float EncodedLightAttenuation = EncodeLightAttenuation(GreyScale);
|
|
|
|
// Light function shadows write to the blue channel.
|
|
OutColor = lerp(float4(1, 1, EncodedLightAttenuation.xx), EncodedLightAttenuation.xxxx, LightFunctionParameters2.z);
|
|
#endif
|
|
}
|