From faa65bca1bee49a6ae607d209d391788e668540a Mon Sep 17 00:00:00 2001 From: Jeremy Ong Date: Tue, 8 Feb 2022 11:51:16 -0700 Subject: [PATCH] Refactor shader definitions to be more consistent with other shaders Signed-off-by: Jeremy Ong --- .../Materials/Types/DepthPass_WithPS.azsli | 24 ++++++++++++++----- .../Types/EnhancedPBR_DepthPass_WithPS.azsl | 1 + .../Types/EnhancedPBR_Shadowmap_WithPS.azsl | 3 ++- ...tandardMultilayerPBR_DepthPass_WithPS.azsl | 4 ++-- ...tandardMultilayerPBR_Shadowmap_WithPS.azsl | 6 ++--- .../Types/StandardPBR_DepthPass_WithPS.azsl | 1 + .../Types/StandardPBR_Shadowmap_WithPS.azsl | 3 ++- .../PBR/Surfaces/EnhancedSurface.azsli | 2 +- 8 files changed, 30 insertions(+), 14 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/DepthPass_WithPS.azsli b/Gems/Atom/Feature/Common/Assets/Materials/Types/DepthPass_WithPS.azsli index 3dd3792102..a1318bf383 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/DepthPass_WithPS.azsli +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/DepthPass_WithPS.azsli @@ -10,6 +10,18 @@ #include #endif +#ifndef MULTILAYER +#define MULTILAYER 0 +#endif + +#ifndef ENABLE_ALPHA_CLIP +#define ENABLE_ALPHA_CLIP 0 +#endif + +#ifndef SHADOWS +#define SHADOWS 0 +#endif + struct VSInput { float3 m_position : POSITION; @@ -21,7 +33,7 @@ struct VSInput float4 m_tangent : TANGENT; float3 m_bitangent : BITANGENT; -#ifdef MULTILAYER +#if MULTILAYER // This gets set automatically by the system at runtime only if it's available. // There is a soft naming convention that associates this with o_blendMask_isBound, which will be set to true whenever m_optional_blendMask is available. // (search "m_optional_" in ShaderVariantAssetBuilder for details on the naming convention). @@ -42,7 +54,7 @@ struct VSDepthOutput float3 m_bitangent : BITANGENT; float3 m_worldPosition : UV0; -#ifdef MULTILAYER +#if MULTILAYER float3 m_blendMask : UV3; #endif }; @@ -67,7 +79,7 @@ VSDepthOutput MainVS(VSInput IN) ConstructTBN(IN.m_normal, IN.m_tangent, IN.m_bitangent, objectToWorld, objectToWorldIT, OUT.m_normal, OUT.m_tangent, OUT.m_bitangent); } -#ifdef MULTILAYER +#if MULTILAYER if(o_blendMask_isBound) { OUT.m_blendMask = IN.m_optional_blendMask.rgb; @@ -111,18 +123,18 @@ PSDepthOutput MainPS(VSDepthOutput IN, bool isFrontFace : SV_IsFrontFace) bitangents[i]); } -#ifdef MULTILAYER +#if MULTILAYER MultilayerSetPixelDepth(IN.m_blendMask, IN.m_worldPosition, IN.m_normal, tangents, bitangents, IN.m_uv, isFrontFace, OUT.m_depth); #else SetPixelDepth(IN.m_worldPosition, IN.m_normal, tangents, bitangents, IN.m_uv, isFrontFace, OUT.m_depth); #endif -#ifdef SHADOWS +#if SHADOWS OUT.m_depth += PdoShadowMapBias; #endif } -#ifndef DEACTIVATE_ALPHA_CLIP +#if ENABLE_ALPHA_CLIP GetAlphaAndClip(IN.m_uv); #endif diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl index a13d04bdb8..eb220faec6 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl @@ -16,4 +16,5 @@ #include "MaterialFunctions/ParallaxDepth.azsli" #include "MaterialFunctions/StandardGetAlphaAndClip.azsli" +#define ENABLE_ALPHA_CLIP 1 #include "DepthPass_WithPS.azsli" diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Shadowmap_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Shadowmap_WithPS.azsl index e5a7b3eb3c..be350a3ce7 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Shadowmap_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Shadowmap_WithPS.azsl @@ -23,5 +23,6 @@ #include "MaterialFunctions/ParallaxDepth.azsli" #include "MaterialFunctions/StandardGetAlphaAndClip.azsli" -#define SHADOWS +#define SHADOWS 1 +#define ENABLE_ALPHA_CLIP 1 #include "DepthPass_WithPS.azsli" diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_DepthPass_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_DepthPass_WithPS.azsl index 7edea547ac..0f000fba98 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_DepthPass_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_DepthPass_WithPS.azsl @@ -27,6 +27,6 @@ COMMON_OPTIONS_PARALLAX(o_layer3_) #include "MaterialFunctions/StandardTransformUvs.azsli" #include "MaterialFunctions/MultilayerParallaxDepth.azsli" -#define MULTILAYER -#define DEACTIVATE_ALPHA_CLIP +#define MULTILAYER 1 +#define ENABLE_ALPHA_CLIP 0 #include "DepthPass_WithPS.azsli" diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Shadowmap_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Shadowmap_WithPS.azsl index 8d7314640b..9d64916444 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Shadowmap_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Shadowmap_WithPS.azsl @@ -27,7 +27,7 @@ COMMON_OPTIONS_PARALLAX(o_layer3_) #include "MaterialFunctions/EvaluateTangentFrame.azsli" #include "MaterialFunctions/MultilayerParallaxDepth.azsli" -#define MULTILAYER -#define DEACTIVATE_ALPHA_CLIP -#define SHADOWS +#define MULTILAYER 1 +#define ENABLE_ALPHA_CLIP 0 +#define SHADOWS 1 #include "DepthPass_WithPS.azsli" diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_DepthPass_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_DepthPass_WithPS.azsl index cf0b7b7311..b848ba03ba 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_DepthPass_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_DepthPass_WithPS.azsl @@ -16,4 +16,5 @@ #include "MaterialFunctions/StandardTransformUvs.azsli" #include "MaterialFunctions/ParallaxDepth.azsli" +#define ENABLE_ALPHA_CLIP 1 #include "DepthPass_WithPS.azsli" diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Shadowmap_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Shadowmap_WithPS.azsl index 665c85c02e..634d23daa1 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Shadowmap_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Shadowmap_WithPS.azsl @@ -20,5 +20,6 @@ #include "MaterialFunctions/EvaluateTangentFrame.azsli" #include "MaterialFunctions/ParallaxDepth.azsli" -#define SHADOWS +#define SHADOWS 1 +#define ENABLE_ALPHA_CLIP 1 #include "DepthPass_WithPS.azsli" diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli index c12cd2834b..961fbd49f9 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli @@ -40,7 +40,7 @@ class Surface float3 normal; //!< Normal in world-space float3 vertexNormal; //!< Vertex normal in world-space float3 baseColor; //!< Surface base color - float3 metallic; //!< Surface metallic property + float metallic; //!< Surface metallic property float roughnessLinear; //!< Perceptually linear roughness value authored by artists. Must be remapped to roughnessA before use float roughnessA; //!< Actual roughness value ( a.k.a. "alpha roughness") to be used in microfacet calculations float roughnessA2; //!< Alpha roughness ^ 2 (i.e. roughnessA * roughnessA), used in GGX, cached here for perfromance