Files
mrieggeramzn 8c6900eb06 Atom/mriegger/normaloffsetbias (#4841)
* Adding directional light shadow bias

Signed-off-by: mrieggeramzn <mriegger@amazon.com>

* Adding normal offset bias to the directional shadow maps

Signed-off-by: mrieggeramzn <mriegger@amazon.com>

* not time yet for this

Signed-off-by: mrieggeramzn <mriegger@amazon.com>

* small comment fix

Signed-off-by: mrieggeramzn <mriegger@amazon.com>

* fixing tabs

Signed-off-by: mrieggeramzn <mriegger@amazon.com>
2021-10-22 11:48:04 -05:00

100 lines
2.6 KiB
Plaintext

/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <viewsrg.srgi>
struct VSInput
{
float3 m_position : POSITION;
float3 m_normal : NORMAL; // Needed for some shadow filtering algorithms
};
struct VSOutput
{
float4 m_position : SV_Position;
float3 m_worldPosition : TEXCOORD0;
float3 m_worldNormal : NORMAL;
float3 m_shadowCoords[ViewSrg::MaxCascadeCount] : TEXCOORD1;
};
struct PSOutput
{
float4 m_color : SV_Target;
};
ShaderResourceGroup MaterialSrg : SRG_PerMaterial
{
float m_opacity;
}
#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
#include <Atom/Features/PBR/ForwardPassSrg.azsli>
#include <Atom/Features/Shadow/DirectionalLightShadow.azsli>
#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
//! Shades the entire geometry with the shadow color, not just what's in shadow. For debugging.
option bool o_shadeAll = false;
VSOutput ShadowCatcherVS(VSInput IN)
{
VSOutput OUT;
float3 worldPosition = mul(ObjectSrg::GetWorldMatrix(), float4(IN.m_position, 1.0)).xyz;
OUT.m_worldPosition = worldPosition;
OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(OUT.m_worldPosition, 1.0));
OUT.m_worldNormal = normalize(mul(ObjectSrg::GetWorldMatrixInverseTranspose(), IN.m_normal));
// [GFX TODO][ATOM-2012] Add support for multiple directional light shadows
DirectionalLightShadow::GetShadowCoords(
ViewSrg::m_shadowIndexDirectionalLight,
worldPosition,
OUT.m_worldNormal,
OUT.m_shadowCoords);
return OUT;
}
PSOutput ShadowCatcherPS(VSOutput IN)
{
PSOutput OUT;
DirectionalLightShadow::DebugInfo debugInfo;
float litRatio = DirectionalLightShadow::GetVisibility(
ViewSrg::m_shadowIndexDirectionalLight,
IN.m_shadowCoords,
IN.m_worldNormal,
debugInfo);
if (o_shadeAll)
{
litRatio = 0.0f;
}
if (ViewSrg::m_directionalLightShadows[ViewSrg::m_shadowIndexDirectionalLight].m_debugFlags &
ViewSrg::DirectionalLightShadowDebugColoringBitMask)
{
float3 debugColor = float3(1,1,1) * litRatio * 0.5f;
debugColor = DirectionalLightShadow::AddDebugColoring(
debugColor,
ViewSrg::m_shadowIndexDirectionalLight,
debugInfo);
OUT.m_color.rgb = debugColor;
OUT.m_color.a = 1;
}
else
{
OUT.m_color = float4(0, 0, 0, 1 - litRatio) * MaterialSrg::m_opacity;
}
return OUT;
}