Files
UnrealEngineUWP/Engine/Shaders/Private/Strata/StrataDeferredLighting.ush
Charles deRousiers b4f08f38c7 Fix indirect lighting accumuation with Strata is enabled.
This CL changes Strata_For macro to ensure that BSDFs are not processed if there are invalid. It also temporarly disable cluster shading on FXC as the compiler has issue with the current code layout.

#rb none
#jira none
#fyi sebastien.hillaire
#preflight shaders

[CL 20437092 by Charles deRousiers in ue5-main branch]
2022-05-31 10:55:09 -04:00

96 lines
3.5 KiB
Plaintext

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "../AreaLightCommon.ush"
// Sanity guard.
#ifndef STRATA_ENABLED
#define STRATA_ENABLED 1
#error STRATA_ENABLED needs to be defined
#endif
#if STRATA_ENABLED
float4 StrataReadPrecomputedShadowFactors(FStrataPixelHeader StrataPixelHeader, int2 PixelPos, Texture2D PrecomputedShadowTexture)
{
if (HasPrecShadowMask(StrataPixelHeader))
{
#if ALLOW_STATIC_LIGHTING
float4 GBufferE = PrecomputedShadowTexture.Load(int3(PixelPos, 0));
#else
float4 GBufferE = 1;
#endif
return GBufferE;
}
return HasZeroPrecShadowMask(StrataPixelHeader) ? 0.0f : 1.0f;
}
// Analytical lighting evaluation for strata material.
// Unpack BSDF on-the-fly
FStrataDeferredLighting StrataDeferredLighting(
FDeferredLightData LightData,
float3 V,
float3 L,
float3 ToLight,
float LightMask,
FShadowTerms ShadowTerms,
FStrataMaterialContainer MaterialBuffer,
FStrataAddressing StrataAddressing,
FStrataPixelHeader StrataPixelHeader)
{
FStrataDeferredLighting StrataLighting = GetInitialisedStrataDeferredLighting();
#if STRATA_USES_RESOURCE_MATERIALCONTAINER
const FStrataIntegrationSettings Settings = InitStrataIntegrationSettings(false /*bForceFullyRough*/, Strata.bRoughDiffuse, Strata.PeelLayersAboveDepth);
#else
const FStrataIntegrationSettings Settings = InitStrataIntegrationSettings();
#endif
FRectTexture RectTexture = InitRectTexture(LightData);
Strata_for (uint BSDFIndex = 0, BSDFIndex < StrataPixelHeader.BSDFCount, ++BSDFIndex)
{
// Unpack BSDF data
FStrataBSDF BSDF = UnpackStrataBSDF(MaterialBuffer, StrataAddressing, StrataPixelHeader);
FStrataBSDFContext BSDFContext = StrataCreateBSDFContext(StrataPixelHeader, BSDF, StrataAddressing, V, L);
float Roughness = StrataGetBSDFRoughness(BSDFContext.BSDF);
FAreaLightIntegrateContext AreaLightContext = InitAreaLightIntegrateContext();
FStrataEvaluateResult BSDFEvaluate = (FStrataEvaluateResult)0;
if (LightData.bRectLight)
{
FRect Rect = GetRect(ToLight, LightData);
if (!IsRectVisible(Rect))
{
return GetInitialisedStrataDeferredLighting(); // Rect light can be non visible due to barn door occlusion
}
AreaLightContext = CreateRectIntegrateContext(Roughness, BSDFContext.N, BSDFContext.V, Rect, RectTexture);
// We must have the StrataIntegrateBSDF inside the if due to the rectlight texture: it must be non ambiguous which texture is going to be used.
// After the compilation, a local resource must map to a unique global resource (the default or the actual rect light texture).
BSDFEvaluate = StrataIntegrateBSDF(BSDFContext, ShadowTerms, AreaLightContext, Settings);
}
else
{
FCapsuleLight Capsule = GetCapsule(ToLight, LightData);
AreaLightContext = CreateCapsuleIntegrateContext(Roughness, BSDFContext.N, BSDFContext.V, Capsule, LightData.bInverseSquared);
BSDFEvaluate = StrataIntegrateBSDF(BSDFContext, ShadowTerms, AreaLightContext, Settings);
}
float3 DiffuseLuminance = BSDFEvaluate.IntegratedDiffuseValue;
float3 SpecularLuminance = BSDFEvaluate.IntegratedSpecularValue;
const float3 CommonMultiplier = LightData.Color * LightMask * LuminanceWeight(BSDFContext, BSDF);
FLightAccumulator Out = (FLightAccumulator)0;
LightAccumulator_AddSplit(Out, DiffuseLuminance, SpecularLuminance, DiffuseLuminance, CommonMultiplier, BSDFEvaluate.bSubsurface);
AccumulateStrataDeferredLighting(StrataLighting, Out, BSDFEvaluate.bSubsurface, BSDF_GETISTOPLAYER(BSDF));
}
return StrataLighting;
}
#endif // STRATA_ENABLED