Files
UnrealEngineUWP/Engine/Shaders/Private/LightFunctionPixelShader.usf
Charles deRousiers 1d847cee2e Change light function pixel shader to bind hair strands depth texture rather than hair strands uniform buffer.
This solves the hair strands uniform buffer is not created when hair strands plugin is not enabled.

#rb yuriy.odonnell
#jira none
#preflight 62cd9f7f254b7ba6dbcd472c

[CL 21059573 by Charles deRousiers in ue5-main branch]
2022-07-12 14:13:34 -04:00

75 lines
2.6 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, hair strands in w */
float4 LightFunctionParameters2;
Texture2D HairOnlyDepthTexture;
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);
#if HAIR_STRANDS_SUPPORTED
BRANCH
if (LightFunctionParameters2.w > 0)
{
SvPosition.z = Texture2DSampleLevel(HairOnlyDepthTexture, SceneTexturesStruct_SceneDepthTextureSampler, ScreenUV, 0).r;
}
#endif
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
}