Quellcode durchsuchen

Split Materialpipeline - shader code into two files (#18549)

* Split the material shader code into two files, defines and
implementation, to allow interfacing with the render-pipeline in between

Signed-off-by: Karl Haubenwallner <[email protected]>

* update test materials

Signed-off-by: Karl Haubenwallner <[email protected]>

* add more encapsulations for Srg access in material-functions

Signed-off-by: Karl Haubenwallner <[email protected]>

* make some Srgs optional for materials

Signed-off-by: Karl Haubenwallner <[email protected]>

* Ensure all materials fill the SV - struct

Signed-off-by: Karl Haubenwallner <[email protected]>

* bugfixes, remove some duplicated includes

Signed-off-by: Karl Haubenwallner <[email protected]>

* rename PIPELINE_VERTEX_POSITION to MATERIAL_USES_VERTEX_POSITION (among others)

Signed-off-by: Karl Haubenwallner <[email protected]>

* remove the AlphaUtils from the StandardMultiLayerPBR, but keep the o_opacity_mode

Signed-off-by: Karl Haubenwallner <[email protected]>

* fix testcase

Signed-off-by: Karl Haubenwallner <[email protected]>

* fixes after rebase

Signed-off-by: Karl Haubenwallner <[email protected]>

* enable vertex-color for basePBR again

Signed-off-by: Karl Haubenwallner <[email protected]>

* fix some comments

Signed-off-by: Karl Haubenwallner <[email protected]>

* revert changes to non-materialpipeline test materials

Signed-off-by: Karl Haubenwallner <[email protected]>

* don't recreate the material parameter buffers if only the shared samplers changed

Signed-off-by: Karl Haubenwallner <[email protected]>

---------

Signed-off-by: Karl Haubenwallner <[email protected]>
Karl Haubenwallner vor 1 Monat
Ursprung
Commit
38641fde6d
100 geänderte Dateien mit 2392 neuen und 1374 gelöschten Zeilen
  1. 1 1
      AutomatedTesting/Levels/ShaderReloadTest/SimpleMesh.azsl
  2. 1 1
      AutomatedTesting/Materials/UVs.azsl
  3. 18 1
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Common/DepthPass.azsli
  4. 23 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Common/DepthPass_CustomZ.azsli
  5. 24 4
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Common/MeshMotionVector.azsli
  6. 6 1
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Common/TransparentPassVertexAndPixel.azsli
  7. 17 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/LowEndPipeline/ForwardPass_BaseLighting.azsli
  8. 18 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/LowEndPipeline/ForwardPass_StandardLighting.azsli
  9. 17 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/LowEndPipeline/ForwardPass_StandardLighting_CustomZ.azsli
  10. 6 1
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/LowEndPipeline/LowEndForwardPassVertexAndPixel.azsli
  11. 18 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/LowEndPipeline/Transparent_StandardLighting.azsli
  12. 6 1
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPassVertexAndPixel.azsli
  13. 18 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPass_BaseLighting.azsli
  14. 17 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPass_EnhancedLighting.azsli
  15. 17 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPass_EnhancedLighting_CustomZ.azsli
  16. 17 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPass_SkinLighting.azsli
  17. 18 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPass_StandardLighting.azsli
  18. 17 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPass_StandardLighting_CustomZ.azsli
  19. 17 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/Transparent_EnhancedLighting.azsli
  20. 16 1
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/Transparent_StandardLighting.azsli
  21. 18 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Mobile/ForwardPass_BaseLighting.azsli
  22. 19 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Mobile/ForwardPass_StandardLighting.azsli
  23. 18 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Mobile/ForwardPass_StandardLighting_CustomZ.azsli
  24. 4 1
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Mobile/MobileForwardPassVertexAndPixel.azsli
  25. 17 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Mobile/Transparent_StandardLighting.azsli
  26. 17 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MultiView/ForwardPass_BaseLighting.azsli
  27. 17 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MultiView/ForwardPass_StandardLighting.azsli
  28. 20 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MultiView/ForwardPass_StandardLighting_CustomZ.azsli
  29. 5 1
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MultiView/MultiViewForwardPassVertexAndPixel.azsli
  30. 18 2
      Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MultiView/Transparent_StandardLighting.azsli
  31. 27 54
      Gems/Atom/Feature/Common/Assets/Materials/ReflectionProbe/ReflectionProbeVisualization.azsli
  32. 1 0
      Gems/Atom/Feature/Common/Assets/Materials/ReflectionProbe/ReflectionProbeVisualization.materialtype
  33. 59 0
      Gems/Atom/Feature/Common/Assets/Materials/ReflectionProbe/ReflectionProbeVisualization_Defines.azsli
  34. 0 20
      Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.azsli
  35. 1 0
      Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype
  36. 46 0
      Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_Defines.azsli
  37. 3 26
      Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR.azsli
  38. 1 0
      Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR.materialtype
  39. 42 0
      Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Defines.azsli
  40. 0 19
      Gems/Atom/Feature/Common/Assets/Materials/Types/Eye.azsli
  41. 2 0
      Gems/Atom/Feature/Common/Assets/Materials/Types/Eye.materialtype
  42. 39 0
      Gems/Atom/Feature/Common/Assets/Materials/Types/Eye_Defines.azsli
  43. 4 15
      Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsli
  44. 1 0
      Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.materialtype
  45. 41 0
      Gems/Atom/Feature/Common/Assets/Materials/Types/Skin_Defines.azsli
  46. 19 616
      Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR.azsli
  47. 1 0
      Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR.materialtype
  48. 41 0
      Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Defines.azsli
  49. 5 23
      Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR.azsli
  50. 1 0
      Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR.materialtype
  51. 45 0
      Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Defines.azsli
  52. 27 0
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/GoboTexture.azsli
  53. 3 3
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/InstancedTransforms.azsli
  54. 27 0
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/LightingChannels.azsli
  55. 15 5
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Materials/SceneMaterialSrg.azsli
  56. 0 17
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/DefaultObjectSrg.azsli
  57. 3 0
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli
  58. 2 10
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/Ibl.azsli
  59. 1 12
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/SimpleSpotLight.azsli
  60. 28 23
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/ParallaxMapping.azsli
  61. 83 0
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Pipeline/Deferred/DeferredPassPipelineCallbacks.azsli
  62. 192 0
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Pipeline/Deferred/DeferredPassVertexData.azsli
  63. 78 0
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli
  64. 4 0
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli
  65. 191 0
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli
  66. 31 0
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/SampleBrdfMap.azsli
  67. 0 19
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Skin/SkinObjectSrg.azsli
  68. 26 0
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/StreamTangentBitmask.azsli
  69. 0 24
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/VertexUtility.azsli
  70. 33 0
      Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/WrinkleMask.azsli
  71. 1 5
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_LightingData.azsli
  72. 0 1
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_MaterialInputs.azsli
  73. 6 5
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_PixelGeometryEval.azsli
  74. 8 66
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexData.azsli
  75. 24 18
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexEval.azsli
  76. 4 48
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli
  77. 13 10
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli
  78. 6 5
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_PixelGeometryEval.azsli
  79. 9 41
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_VertexData.azsli
  80. 9 4
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_VertexEval.azsli
  81. 8 6
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_PixelGeometryEval.azsli
  82. 9 21
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_VertexData.azsli
  83. 25 12
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_VertexEval.azsli
  84. 2 1
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/MaterialFunctions/EvaluateTangentFrame.azsli
  85. 1 0
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/MaterialFunctions/MultilayerParallaxDepth.azsli
  86. 1 0
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/MaterialFunctions/ParallaxDepth.azsli
  87. 7 6
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/MaterialInputs/ParallaxInput.azsli
  88. 0 28
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/MultilayerPBR/StandardMultilayerPBR_DepthPass_WithPS.azsl
  89. 0 27
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/MultilayerPBR/StandardMultilayerPBR_Shadowmap_WithPS.azsl
  90. 11 9
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_PixelGeometryEval.azsli
  91. 14 14
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_SurfaceEval.azsli
  92. 9 56
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_VertexData.azsli
  93. 40 24
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_VertexEval.azsli
  94. 3 28
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_Common.azsli
  95. 17 0
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_MaterialInputs.azsli
  96. 42 0
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_PixelGeometryData.azsli
  97. 66 0
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_PixelGeometryEval.azsli
  98. 414 0
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_SurfaceEval.azsli
  99. 17 0
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_VertexData.azsli
  100. 58 0
      Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_VertexEval.azsli

+ 1 - 1
AutomatedTesting/Levels/ShaderReloadTest/SimpleMesh.azsl

@@ -28,7 +28,7 @@ VSOutput MainVS(VSInput IN)
 {
 {
     VSOutput OUT;
     VSOutput OUT;
 
 
-    float3 worldPosition = mul(ObjectSrg::GetWorldMatrix(), float4(IN.m_position, 1.0)).xyz;
+    float3 worldPosition = mul(SceneSrg::GetObjectToWorldMatrix(ObjectSrg::m_objectId), float4(IN.m_position, 1.0)).xyz;
     OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(worldPosition, 1.0));
     OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(worldPosition, 1.0));
     OUT.m_normal = IN.m_normal;
     OUT.m_normal = IN.m_normal;
 
 

+ 1 - 1
AutomatedTesting/Materials/UVs.azsl

@@ -27,7 +27,7 @@ struct VertexOutput
 VertexOutput MainVS(VertexInput input)
 VertexOutput MainVS(VertexInput input)
 {
 {
     VertexOutput output;
     VertexOutput output;
-    float3 worldPosition = mul(ObjectSrg::GetWorldMatrix(), float4(input.m_position, 1)).xyz;
+    float3 worldPosition = mul(SceneSrg::GetObjectToWorldMatrix(ObjectSrg::m_objectId), float4(input.m_position, 1)).xyz;
     output.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(worldPosition, 1.0));
     output.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(worldPosition, 1.0));
 
 
     output.m_uv = input.m_uv;
     output.m_uv = input.m_uv;

+ 18 - 1
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Common/DepthPass.azsli

@@ -5,8 +5,25 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once 
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 0
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 0
+#define PIPELINE_HAS_PASS_SRG 0
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 

+ 23 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Common/DepthPass_CustomZ.azsli

@@ -5,8 +5,24 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE 1
+#define PIPELINE_HAS_PASS_SRG 0
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
@@ -18,6 +34,7 @@ VsOutput VertexShader(VsInput IN, uint instanceId : SV_InstanceID)
     VsSystemValues SV;
     VsSystemValues SV;
     SV.m_instanceId = instanceId;
     SV.m_instanceId = instanceId;
     VsOutput OUT = EvaluateVertexGeometry(IN, SV, GetMaterialParameters());
     VsOutput OUT = EvaluateVertexGeometry(IN, SV, GetMaterialParameters());
+    OUT.m_instanceId = instanceId;
     return OUT;
     return OUT;
 }
 }
 
 
@@ -28,7 +45,11 @@ struct PsOutput
 
 
 PsOutput PixelShader(VsOutput IN, bool isFrontFace : SV_IsFrontFace)
 PsOutput PixelShader(VsOutput IN, bool isFrontFace : SV_IsFrontFace)
 {
 {
-    PixelGeometryData geoData = EvaluatePixelGeometry(IN, isFrontFace, GetMaterialParameters());
+    // ------- Reconstruct the Instance-Id --------
+    VsSystemValues SV;
+    SV.m_instanceId = IN.m_instanceId;
+
+    PixelGeometryData geoData = EvaluatePixelGeometry(IN, SV, isFrontFace, GetMaterialParameters());
 
 
     // Pixel clipping can be done here
     // Pixel clipping can be done here
     EvaluateSurface(IN, geoData, GetMaterialParameters());
     EvaluateSurface(IN, geoData, GetMaterialParameters());

+ 24 - 4
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Common/MeshMotionVector.azsli

@@ -5,19 +5,32 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
 
 
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 0 // Well, it does have a pixel stage, but not one that can be customized.
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 0 // Well, it does have a pixel stage, but not one that can be customized.
 #define MATERIALPIPELINE_USES_PREV_VERTEX_POSITION 1
 #define MATERIALPIPELINE_USES_PREV_VERTEX_POSITION 1
+#define PIPELINE_HAS_PASS_SRG 0
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 #include <scenesrg_all.srgi>
 #include <scenesrg_all.srgi>
 #include <viewsrg_all.srgi>
 #include <viewsrg_all.srgi>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 struct PsOutput
 struct PsOutput
 {
 {
@@ -29,18 +42,25 @@ VsOutput VertexShader(VsInput IN, uint instanceId : SV_InstanceID)
     VsSystemValues SV;
     VsSystemValues SV;
     SV.m_instanceId = instanceId;
     SV.m_instanceId = instanceId;
     VsOutput OUT = EvaluateVertexGeometry(IN, SV, GetMaterialParameters());
     VsOutput OUT = EvaluateVertexGeometry(IN, SV, GetMaterialParameters());
+    OUT.m_instanceId = instanceId;
     return OUT;
     return OUT;
 }
 }
 
 
 PsOutput PixelShader(VsOutput IN)
 PsOutput PixelShader(VsOutput IN)
 {
 {
     PsOutput OUT;
     PsOutput OUT;
+    
+    // re-create the System-Values for the Pixel
+    VsSystemValues SV;
+    SV.m_instanceId = IN.m_instanceId;
 
 
     // Current clip position
     // Current clip position
-    float4 clipPos = mul(ViewSrg::m_viewProjectionMatrix, float4(IN.m_worldPos, 1.0));
+    float4x4 viewProjectionMatrix = GetViewProjectionMatrix(SV);
+    float4 clipPos = mul(viewProjectionMatrix, float4(IN.worldPosition, 1.0));
     
     
+    float4x4 viewProjectionPrevMatrix = GetViewProjectionPrevMatrix(SV);
     // Reprojected last frame's clip position, for skinned mesh it also implies last key frame
     // Reprojected last frame's clip position, for skinned mesh it also implies last key frame
-    float4 clipPosPrev = mul(ViewSrg::m_viewProjectionPrevMatrix, float4(IN.m_worldPosPrev, 1.0));
+    float4 clipPosPrev = mul(viewProjectionPrevMatrix, float4(IN.worldPosPrev, 1.0));
 
 
     float2 motion = (clipPos.xy / clipPos.w - clipPosPrev.xy / clipPosPrev.w) * 0.5;
     float2 motion = (clipPos.xy / clipPos.w - clipPosPrev.xy / clipPosPrev.w) * 0.5;
 
 

+ 6 - 1
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Common/TransparentPassVertexAndPixel.azsli

@@ -22,6 +22,7 @@ VsOutput VertexShader(VsInput IN, uint instanceId : SV_InstanceID)
     VsSystemValues SV;
     VsSystemValues SV;
     SV.m_instanceId = instanceId;
     SV.m_instanceId = instanceId;
     VsOutput OUT = EvaluateVertexGeometry(IN, SV, GetMaterialParameters());
     VsOutput OUT = EvaluateVertexGeometry(IN, SV, GetMaterialParameters());
+    OUT.m_instanceId = instanceId;
     return OUT;
     return OUT;
 }
 }
 
 
@@ -32,9 +33,13 @@ ForwardPassOutput PixelShader(VsOutput IN, bool isFrontFace : SV_IsFrontFace)
     float3 views[MAX_SHADING_VIEWS];
     float3 views[MAX_SHADING_VIEWS];
     views[0] = ViewSrg::m_worldPosition.xyz;    // Assume one view for forward pass for now
     views[0] = ViewSrg::m_worldPosition.xyz;    // Assume one view for forward pass for now
 
 
+    // ------- Reconstruct the Instance-Id --------
+    VsSystemValues SV;
+    SV.m_instanceId = IN.m_instanceId;
+
     // ------- Geometry -> Surface -> Lighting -------
     // ------- Geometry -> Surface -> Lighting -------
 
 
-    PixelGeometryData geoData = EvaluatePixelGeometry(IN, isFrontFace, GetMaterialParameters());
+    PixelGeometryData geoData = EvaluatePixelGeometry(IN, SV, isFrontFace, GetMaterialParameters());
 
 
     Surface surface = EvaluateSurface(IN, geoData, GetMaterialParameters());
     Surface surface = EvaluateSurface(IN, geoData, GetMaterialParameters());
 
 

+ 17 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/LowEndPipeline/ForwardPass_BaseLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -23,11 +26,23 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingData.azsli"
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingData.azsli"
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingBrdf.azsli"
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingBrdf.azsli"

+ 18 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/LowEndPipeline/ForwardPass_StandardLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -21,13 +24,26 @@
 #define ENABLE_SHADER_DEBUGGING 1
 #define ENABLE_SHADER_DEBUGGING 1
 #define ENABLE_CLEAR_COAT 1
 #define ENABLE_CLEAR_COAT 1
 
 
+
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 17 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/LowEndPipeline/ForwardPass_StandardLighting_CustomZ.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -23,11 +26,23 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 6 - 1
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/LowEndPipeline/LowEndForwardPassVertexAndPixel.azsli

@@ -17,6 +17,7 @@ VsOutput VertexShader(VsInput IN, uint instanceId : SV_InstanceID)
     VsSystemValues SV;
     VsSystemValues SV;
     SV.m_instanceId = instanceId;
     SV.m_instanceId = instanceId;
     VsOutput OUT = EvaluateVertexGeometry(IN, SV, GetMaterialParameters());
     VsOutput OUT = EvaluateVertexGeometry(IN, SV, GetMaterialParameters());
+    OUT.m_instanceId = instanceId;
     return OUT;
     return OUT;
 }
 }
 
 
@@ -31,9 +32,13 @@ ForwardPassOutput PixelShader(VsOutput IN, bool isFrontFace : SV_IsFrontFace)
     float3 views[MAX_SHADING_VIEWS];
     float3 views[MAX_SHADING_VIEWS];
     views[0] = ViewSrg::m_worldPosition.xyz;    // Assume one view for forward pass for now
     views[0] = ViewSrg::m_worldPosition.xyz;    // Assume one view for forward pass for now
     
     
+    // ------- Reconstruct the Instance-Id --------
+    VsSystemValues SV;
+    SV.m_instanceId = IN.m_instanceId;
+
     // ------- Geometry -> Surface -> Lighting -------
     // ------- Geometry -> Surface -> Lighting -------
 
 
-    PixelGeometryData geoData = EvaluatePixelGeometry(IN, isFrontFace, GetMaterialParameters());
+    PixelGeometryData geoData = EvaluatePixelGeometry(IN, SV, isFrontFace, GetMaterialParameters());
 
 
     Surface surface = EvaluateSurface(IN, geoData, GetMaterialParameters());
     Surface surface = EvaluateSurface(IN, geoData, GetMaterialParameters());
 
 

+ 18 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/LowEndPipeline/Transparent_StandardLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -21,11 +24,24 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 6 - 1
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPassVertexAndPixel.azsli

@@ -21,6 +21,7 @@ VsOutput VertexShader(VsInput IN, uint instanceId : SV_InstanceID)
     VsSystemValues SV;
     VsSystemValues SV;
     SV.m_instanceId = instanceId;
     SV.m_instanceId = instanceId;
     VsOutput OUT = EvaluateVertexGeometry(IN, SV, GetMaterialParameters());
     VsOutput OUT = EvaluateVertexGeometry(IN, SV, GetMaterialParameters());
+    OUT.m_instanceId = instanceId;
     return OUT;
     return OUT;
 }
 }
 
 
@@ -47,9 +48,13 @@ ForwardPassOutput PixelShader(VsOutput IN, bool isFrontFace : SV_IsFrontFace)
     float3 views[MAX_SHADING_VIEWS];
     float3 views[MAX_SHADING_VIEWS];
     views[0] = ViewSrg::m_worldPosition.xyz;    // Assume one view for forward pass for now
     views[0] = ViewSrg::m_worldPosition.xyz;    // Assume one view for forward pass for now
 
 
+    // ------- Reconstruct the Instance-Id --------
+    VsSystemValues SV;
+    SV.m_instanceId = IN.m_instanceId;
+    
     // ------- Geometry -> Surface -> Lighting -------
     // ------- Geometry -> Surface -> Lighting -------
 
 
-    PixelGeometryData geoData = EvaluatePixelGeometry(IN, isFrontFace, GetMaterialParameters());
+    PixelGeometryData geoData = EvaluatePixelGeometry(IN, SV, isFrontFace, GetMaterialParameters());
 
 
     Surface surface = EvaluateSurface(IN, geoData, GetMaterialParameters());
     Surface surface = EvaluateSurface(IN, geoData, GetMaterialParameters());
 
 

+ 18 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPass_BaseLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -18,11 +21,24 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
 
 
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingData.azsli"
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingData.azsli"
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingBrdf.azsli"
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingBrdf.azsli"

+ 17 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPass_EnhancedLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -18,11 +21,23 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 17 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPass_EnhancedLighting_CustomZ.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -18,11 +21,23 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 17 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPass_SkinLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -25,11 +28,23 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 18 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPass_StandardLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -16,13 +19,26 @@
 #define ENABLE_SHADER_DEBUGGING 1
 #define ENABLE_SHADER_DEBUGGING 1
 #define ENABLE_CLEAR_COAT 1
 #define ENABLE_CLEAR_COAT 1
 
 
+
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 17 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/ForwardPass_StandardLighting_CustomZ.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -18,11 +21,23 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 17 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/Transparent_EnhancedLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -18,11 +21,23 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 16 - 1
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MainPipeline/Transparent_StandardLighting.azsli

@@ -5,6 +5,9 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
 
 
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
@@ -18,11 +21,23 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 18 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Mobile/ForwardPass_BaseLighting.azsli

@@ -5,7 +5,11 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -39,11 +43,23 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingData.azsli"
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingData.azsli"
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingBrdf.azsli"
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingBrdf.azsli"

+ 19 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Mobile/ForwardPass_StandardLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -37,13 +40,27 @@
 #define ENABLE_PARALLAX 0
 #define ENABLE_PARALLAX 0
 #define ENABLE_MOBILEBRDF 1
 #define ENABLE_MOBILEBRDF 1
 
 
+
+
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 18 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Mobile/ForwardPass_StandardLighting_CustomZ.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -37,13 +40,26 @@
 #define ENABLE_PARALLAX 0
 #define ENABLE_PARALLAX 0
 #define ENABLE_MOBILEBRDF 1
 #define ENABLE_MOBILEBRDF 1
 
 
+
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 4 - 1
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Mobile/MobileForwardPassVertexAndPixel.azsli

@@ -30,10 +30,13 @@ ForwardPassOutput PixelShader(VsOutput IN, bool isFrontFace : SV_IsFrontFace)
 {
 {
     float3 views[MAX_SHADING_VIEWS];
     float3 views[MAX_SHADING_VIEWS];
     views[0] = ViewSrg::m_worldPosition.xyz;    // Assume one view for forward pass for now
     views[0] = ViewSrg::m_worldPosition.xyz;    // Assume one view for forward pass for now
+    // ------- Reconstruct the Instance-Id --------
+    VsSystemValues SV;
+    SV.m_instanceId = IN.m_instanceId;
 
 
     // ------- Geometry -> Surface -> Lighting -------
     // ------- Geometry -> Surface -> Lighting -------
 
 
-    PixelGeometryData geoData = EvaluatePixelGeometry(IN, isFrontFace, GetMaterialParameters());
+    PixelGeometryData geoData = EvaluatePixelGeometry(IN, SV, isFrontFace, GetMaterialParameters());
 
 
     Surface surface = EvaluateSurface(IN, geoData, GetMaterialParameters());
     Surface surface = EvaluateSurface(IN, geoData, GetMaterialParameters());
 
 

+ 17 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/Mobile/Transparent_StandardLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -37,11 +40,23 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 17 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MultiView/ForwardPass_BaseLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -34,11 +37,23 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingData.azsli"
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingData.azsli"
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingBrdf.azsli"
 #include "../../../Shaders/Materials/BasePBR/BasePBR_LightingBrdf.azsli"

+ 17 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MultiView/ForwardPass_StandardLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -34,11 +37,23 @@
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 20 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MultiView/ForwardPass_StandardLighting_CustomZ.azsli

@@ -5,7 +5,11 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -31,13 +35,27 @@
 #define ENABLE_REFLECTIONPROBE_BLENDING 0
 #define ENABLE_REFLECTIONPROBE_BLENDING 0
 #define ENABLE_SPECULARAA 0
 #define ENABLE_SPECULARAA 0
 
 
+
+
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 5 - 1
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MultiView/MultiViewForwardPassVertexAndPixel.azsli

@@ -31,9 +31,13 @@ ForwardPassOutput PixelShader(VsOutput IN, bool isFrontFace : SV_IsFrontFace)
     float3 views[MAX_SHADING_VIEWS];
     float3 views[MAX_SHADING_VIEWS];
     views[0] = ViewSrg::m_worldPosition.xyz;    // Assume one view for forward pass for now
     views[0] = ViewSrg::m_worldPosition.xyz;    // Assume one view for forward pass for now
     
     
+    // ------- Reconstruct the Instance-Id --------
+    VsSystemValues SV;
+    SV.m_instanceId = IN.m_instanceId;
+
     // ------- Geometry -> Surface -> Lighting -------
     // ------- Geometry -> Surface -> Lighting -------
 
 
-    PixelGeometryData geoData = EvaluatePixelGeometry(IN, isFrontFace, GetMaterialParameters());
+    PixelGeometryData geoData = EvaluatePixelGeometry(IN, SV, isFrontFace, GetMaterialParameters());
 
 
     Surface surface = EvaluateSurface(IN, geoData, GetMaterialParameters());
     Surface surface = EvaluateSurface(IN, geoData, GetMaterialParameters());
 
 

+ 18 - 2
Gems/Atom/Feature/Common/Assets/Materials/Pipelines/MultiView/Transparent_StandardLighting.azsli

@@ -5,7 +5,10 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
- 
+#pragma once
+
+#include <Atom/Features/SrgSemantics.azsli>
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
 // TODO(MaterialPipeline): In the end, after all refactoring and rearranging of our shader code is done, some of these flags might become unnecessary and should be re-evaluated.
@@ -30,13 +33,26 @@
 #define ENABLE_REFLECTIONPROBE_BLENDING 0
 #define ENABLE_REFLECTIONPROBE_BLENDING 0
 #define ENABLE_SPECULARAA 0
 #define ENABLE_SPECULARAA 0
 
 
+
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
-#include MATERIAL_TYPE_AZSLI_FILE_PATH
+#ifdef MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#include MATERIAL_TYPE_DEFINES_AZSLI_FILE_PATH
+#endif
 
 
 //////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////
 
 
+#include <viewsrg_all.srgi>
+#include <scenesrg_all.srgi>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 #include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli>
+#include <Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli>
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include MATERIAL_TYPE_AZSLI_FILE_PATH
+
+//////////////////////////////////////////////////////////////////////////////////////////////////
 
 
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // TODO(MaterialPipeline): I don't like how this file #includes something from BasePBR. I'd rather it include a file
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like
 // called StandardPBR_LightingData.azsli which just #includes the BasePBR file. Otherwise this looks suspicious like

+ 27 - 54
Gems/Atom/Feature/Common/Assets/Materials/ReflectionProbe/ReflectionProbeVisualization.azsli

@@ -6,54 +6,13 @@
  *
  *
  */
  */
 
 
-#include <viewsrg_all.srgi>
-#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
-#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
-#include <Atom/Features/VertexUtility.azsli>
-
-#include "../../Shaders/Materials/MaterialInputs/UvSetCount.azsli"
-
-
-struct MaterialParameters {};
-
-const MaterialParameters GetMaterialParameters()
-{
-    return (MaterialParameters)0;
-}
-
 #define ENABLE_DEBUG_MODIFY_OUTPUT 0
 #define ENABLE_DEBUG_MODIFY_OUTPUT 0
 
 
+
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
     
     
 #define MATERIAL_HAS_UVS 0
 #define MATERIAL_HAS_UVS 0
 
 
-    struct VsInput
-    {
-        float3 position : POSITION;
-        float3 normal : NORMAL;
-    };
-
-    struct VsSystemValues
-    {
-        uint m_instanceId;
-    };
-
-    struct VsOutput
-    {
-        precise linear centroid float4 position : SV_Position;
-        float3 normal: NORMAL;
-        float3 worldPosition : UV0;
-    };
-    
-    VsOutput EvaluateVertexGeometry(VsInput IN, VsSystemValues SV, const MaterialParameters params)
-    {        
-        VsOutput output;
-        output.worldPosition = LocalSpaceToWorldSpace(IN.position, SV.m_instanceId);
-        output.position = WorldSpaceToClipSpace(output.worldPosition);
-        output.normal = IN.normal;
-        return output;
-    }
-
     VsOutput EvaluateVertexGeometry(
     VsOutput EvaluateVertexGeometry(
         float3 position,
         float3 position,
         float3 normal,
         float3 normal,
@@ -63,20 +22,37 @@ const MaterialParameters GetMaterialParameters()
         uint instanceId)
         uint instanceId)
     {
     {
         VsOutput output;
         VsOutput output;
-        output.worldPosition = LocalSpaceToWorldSpace(position, instanceId);
-        output.position = WorldSpaceToClipSpace(output.worldPosition);
+
+        // TODO: this assumes a forward+ - pipeline
+        VsSystemValues SV;
+        SV.m_instanceId = instanceId;
+
+        float4x4 objectToWorld = GetObjectToWorldMatrix(SV);
+        float4 worldPosition = mul(objectToWorld, float4(position, 1.0));
+        float4x4 viewProjectionMatrix = GetViewProjectionMatrix(SV);
+        output.worldPosition = worldPosition.xyz;
+        output.position = mul(viewProjectionMatrix, worldPosition);
+
         output.normal = normal;
         output.normal = normal;
         return output;
         return output;
     }
     }
 
 
-    class PixelGeometryData
-    {
-        float3 positionWS;
-        float2 uvs[UvSetCount];
-        float3 vertexNormal;
-    };
+    VsOutput EvaluateVertexGeometry(VsInput IN, VsSystemValues SV, const MaterialParameters params)
+    {        
+        VsOutput output;
+
+        float4x4 objectToWorld = GetObjectToWorldMatrix(SV);
+        float4 worldPosition = mul(objectToWorld, float4(IN.position, 1.0));
+        float4x4 viewProjectionMatrix = GetViewProjectionMatrix(SV);
+        output.worldPosition = worldPosition.xyz;
+        output.position = mul(viewProjectionMatrix, worldPosition);
+
+        output.normal = IN.normal;
 
 
-    PixelGeometryData EvaluatePixelGeometry(VsOutput IN, bool isFrontFace, const MaterialParameters params)
+        return output;
+    }
+        
+    PixelGeometryData EvaluatePixelGeometry(VsOutput IN, VsSystemValues SV, bool isFrontFace, const MaterialParameters params)
     {
     {
         PixelGeometryData geoData;
         PixelGeometryData geoData;
         geoData.positionWS = IN.worldPosition;
         geoData.positionWS = IN.worldPosition;
@@ -91,8 +67,6 @@ const MaterialParameters GetMaterialParameters()
         return geoData;
         return geoData;
     }
     }
 
 
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_SurfaceData.azsli>
-
     Surface EvaluateSurface(VsOutput IN, PixelGeometryData geoData, const MaterialParameters params)
     Surface EvaluateSurface(VsOutput IN, PixelGeometryData geoData, const MaterialParameters params)
     {
     {
         Surface surface;
         Surface surface;
@@ -113,7 +87,6 @@ const MaterialParameters GetMaterialParameters()
 
 
 #else
 #else
 
 
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
 
 
 #endif
 #endif

+ 1 - 0
Gems/Atom/Feature/Common/Assets/Materials/ReflectionProbe/ReflectionProbeVisualization.materialtype

@@ -69,5 +69,6 @@
         }
         }
     },
     },
     "lightingModel": "Base",
     "lightingModel": "Base",
+    "materialShaderDefines": "ReflectionProbeVisualization_Defines.azsli",
     "materialShaderCode": "ReflectionProbeVisualization.azsli"
     "materialShaderCode": "ReflectionProbeVisualization.azsli"
 }
 }

+ 59 - 0
Gems/Atom/Feature/Common/Assets/Materials/ReflectionProbe/ReflectionProbeVisualization_Defines.azsli

@@ -0,0 +1,59 @@
+/*
+ * 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
+ *
+ */
+#pragma once
+
+#ifndef PIPELINE_HAS_OBJECT_SRG
+#define PIPELINE_HAS_OBJECT_SRG 1
+#endif
+#ifndef PIPELINE_HAS_DRAW_SRG
+#define PIPELINE_HAS_DRAW_SRG 1
+#endif
+
+#if PIPELINE_HAS_OBJECT_SRG
+#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
+#endif
+#if PIPELINE_HAS_DRAW_SRG
+#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
+#endif
+
+#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
+#include <Atom/Features/Materials/MaterialSrg.azsli>
+
+#define ENABLE_DEBUG_MODIFY_OUTPUT 0
+
+#if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
+
+#include <Atom/Feature/Common/Assets/Shaders/Materials/MaterialInputs/UvSetCount.azsli>
+
+// by default the Vertex-Data is empty, so enable the parts we need
+#define MATERIAL_USES_VERTEX_POSITION 1
+#define MATERIAL_USES_VERTEX_POSITIONWS 1
+// #define MATERIAL_USES_VERTEX_LOCALPOSITION 1
+// #define MATERIAL_USES_VERTEX_PREV_POSITION 1
+#define MATERIAL_USES_VERTEX_NORMAL 1
+// #define MATERIAL_USES_VERTEX_TANGENT 1
+// #define MATERIAL_USES_VERTEX_BITANGENT 1
+// #define MATERIAL_USES_VERTEX_UV 1
+// #define MATERIAL_USES_VERTEX_DETAIL_UV 1
+// #define MATERIAL_USES_VERTEX_COLOR 1
+// #define MATERIAL_USES_VERTEX_BLENDMASK 1
+
+    class PixelGeometryData
+    {
+        float3 positionWS;
+        float2 uvs[UvSetCount];
+        float3 vertexNormal;
+    };
+
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_SurfaceData.azsli>
+
+#else
+
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
+
+#endif

+ 0 - 20
Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.azsli

@@ -6,20 +6,6 @@
  *
  *
  */
  */
 
 
-#define ENABLE_VERTEX_COLOR 1
-     
-//TODO(MaterialPipeline): Try removing different parts of the SRG and see how hard/easy it is to customize the surface function.
-
-
-#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
-#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
-
-// This file contains the definition for 'struct MaterialParameters', which is generated by the Materialpipeline
-// e.g. for BasePBR this is "basepbr_parameters.azsli"
-// which is usually in [project]/Cache/Intermediate Assets/materials/types/basepbr_parameters.azsli
-#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
-#include <Atom/Features/Materials/MaterialSrg.azsli>
-
 #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_MaterialInputs.azsli>
 #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_MaterialInputs.azsli>
 
 
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
@@ -36,18 +22,12 @@
         return o_normal_useTexture;
         return o_normal_useTexture;
     }
     }
 
 
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexEval.azsli>
-    
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_PixelGeometryData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_PixelGeometryEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_PixelGeometryEval.azsli>
-
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_SurfaceData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_SurfaceEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_SurfaceEval.azsli>
 
 
 #else
 #else
 
 
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
 
 
 #endif
 #endif

+ 1 - 0
Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR.materialtype

@@ -45,6 +45,7 @@
         ]
         ]
     },
     },
     "lightingModel": "Base",
     "lightingModel": "Base",
+    "materialShaderDefines": "BasePBR_Defines.azsli",
     "materialShaderCode": "BasePBR.azsli",
     "materialShaderCode": "BasePBR.azsli",
     "functors": [
     "functors": [
     ],
     ],

+ 46 - 0
Gems/Atom/Feature/Common/Assets/Materials/Types/BasePBR_Defines.azsli

@@ -0,0 +1,46 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+#define ENABLE_VERTEX_COLOR 1
+#include <Atom/Feature/Common/Assets/Shaders/Materials/MaterialInputs/UvSetCount.azsli>
+
+#ifndef PIPELINE_HAS_OBJECT_SRG
+#define PIPELINE_HAS_OBJECT_SRG 1
+#endif
+#ifndef PIPELINE_HAS_DRAW_SRG
+#define PIPELINE_HAS_DRAW_SRG 1
+#endif
+
+#if PIPELINE_HAS_OBJECT_SRG
+#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
+#endif
+#if PIPELINE_HAS_DRAW_SRG
+#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
+#endif
+
+// This file contains the definition for 'struct MaterialParameters', which is generated by the Materialpipeline
+// e.g. for BasePBR this is "basepbr_parameters.azsli"
+// which is usually in [project]/Cache/Intermediate Assets/materials/types/basepbr_parameters.azsli
+#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
+#include <Atom/Features/Materials/MaterialSrg.azsli>
+
+#if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_PixelGeometryData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_SurfaceData.azsli>
+
+    // LightingData
+    // LightingBRDF
+#else 
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
+#endif
+
+
+

+ 3 - 26
Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR.azsli

@@ -8,21 +8,9 @@
 
 
 #pragma once
 #pragma once
 
 
-#define ENABLE_VERTEX_COLOR 1
-
-//TODO(MaterialPipeline): Try removing different parts of the SRG and see how hard/easy it is to customize the surface function.
-
-#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
-#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
-
-// This file contains the definition for 'struct MaterialParameters', which is generated by the Materialpipeline
-#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
-#include <Atom/Features/Materials/MaterialSrg.azsli>
-
 #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_MaterialInputs.azsli>
 #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_MaterialInputs.azsli>
 
 
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
-
     // Subsurface
     // Subsurface
     #include "Atom/Feature/Common/Assets/Shaders/Materials/MaterialInputs/SubsurfaceInput.azsli"
     #include "Atom/Feature/Common/Assets/Shaders/Materials/MaterialInputs/SubsurfaceInput.azsli"
 
 
@@ -53,18 +41,13 @@
     }
     }
     
     
     // Callback function for ParallaxMapping.azsli
     // Callback function for ParallaxMapping.azsli
-    DepthResult GetDepth(Texture2D heightmap, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
+    DepthResult GetDepth(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
     {
     {
         return SampleDepthFromHeightmap(heightmap, mapSampler, uv, uv_ddx, uv_ddy);
         return SampleDepthFromHeightmap(heightmap, mapSampler, uv, uv_ddx, uv_ddy);
     }
     }
 
 
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_VertexData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_VertexEval.azsli>
-
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_PixelGeometryData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_PixelGeometryEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_PixelGeometryEval.azsli>
-
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_SurfaceData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_SurfaceEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_SurfaceEval.azsli>
     
     
 #elif MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE
 #elif MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE
@@ -87,18 +70,16 @@
     }
     }
     
     
     // Callback function for ParallaxMapping.azsli
     // Callback function for ParallaxMapping.azsli
-    DepthResult GetDepth(Texture2D heightmap, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
+    DepthResult GetDepth(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
     {
     {
         return SampleDepthFromHeightmap(heightmap, mapSampler, uv, uv_ddx, uv_ddy);
         return SampleDepthFromHeightmap(heightmap, mapSampler, uv, uv_ddx, uv_ddy);
     }
     }
 
 
-    
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexEval.azsli>
     
     
     // For cases where the pixel stage is only calculating geometry (like alpha clipping and parallax PDO), we can use StandardPBR_PixelGeometryData
     // For cases where the pixel stage is only calculating geometry (like alpha clipping and parallax PDO), we can use StandardPBR_PixelGeometryData
     // instead of EnhancedPBR_PixelGeometryData because the detail-layer UVS are the only difference and those aren't used for clipping or depth.
     // instead of EnhancedPBR_PixelGeometryData because the detail-layer UVS are the only difference and those aren't used for clipping or depth.
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryData.azsli>
+
     #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryEval.azsli>
     
     
     #include "Atom/Feature/Common/Assets/Shaders/Materials/MaterialFunctions/StandardGetAlphaAndClip.azsli"
     #include "Atom/Feature/Common/Assets/Shaders/Materials/MaterialFunctions/StandardGetAlphaAndClip.azsli"
@@ -109,9 +90,5 @@
     }
     }
 
 
 #else
 #else
-
-    //TODO(MaterialPipeline): I think we should rename these to "PositionOnly_*"
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
-
 #endif
 #endif

+ 1 - 0
Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR.materialtype

@@ -134,6 +134,7 @@
         ]
         ]
     },
     },
     "lightingModel": "Enhanced",
     "lightingModel": "Enhanced",
+    "materialShaderDefines": "EnhancedPBR_Defines.azsli",
     "materialShaderCode": "EnhancedPBR.azsli",
     "materialShaderCode": "EnhancedPBR.azsli",
     "functors": [
     "functors": [
     ],
     ],

+ 42 - 0
Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Defines.azsli

@@ -0,0 +1,42 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+#include <Atom/Feature/Common/Assets/Shaders/Materials/MaterialInputs/UvSetCount.azsli>
+
+#ifndef PIPELINE_HAS_OBJECT_SRG
+#define PIPELINE_HAS_OBJECT_SRG 1
+#endif
+#ifndef PIPELINE_HAS_DRAW_SRG
+#define PIPELINE_HAS_DRAW_SRG 1
+#endif
+
+#if PIPELINE_HAS_OBJECT_SRG
+#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
+#endif
+#if PIPELINE_HAS_DRAW_SRG
+#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
+#endif
+
+// This file contains the definition for 'struct MaterialParameters', which is generated by the Materialpipeline
+// e.g. for BasePBR this is "basepbr_parameters.azsli"
+// which is usually in [project]/Cache/Intermediate Assets/materials/types/basepbr_parameters.azsli
+#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
+#include <Atom/Features/Materials/MaterialSrg.azsli>
+
+#if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_VertexData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_PixelGeometryData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_SurfaceData.azsli>
+#elif MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryData.azsli>
+#else
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
+#endif

+ 0 - 19
Gems/Atom/Feature/Common/Assets/Materials/Types/Eye.azsli

@@ -5,16 +5,6 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
-    
-
-#include <scenesrg_all.srgi>
-#include <viewsrg_all.srgi>
-#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
-#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
-
-// This file contains the definition for 'struct MaterialParameters', which is generated by the Materialpipeline
-#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
-#include <Atom/Features/Materials/MaterialSrg.azsli>
 
 
 #include <Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_MaterialInputs.azsli>
 #include <Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_MaterialInputs.azsli>
 
 
@@ -29,19 +19,10 @@
     COMMON_OPTIONS_SPECULAR_F0()
     COMMON_OPTIONS_SPECULAR_F0()
     COMMON_OPTIONS_OCCLUSION()
     COMMON_OPTIONS_OCCLUSION()
 
 
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_VertexData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_VertexEval.azsli>
-
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_PixelGeometryData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_PixelGeometryEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_PixelGeometryEval.azsli>
-
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_SurfaceData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_SurfaceEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_SurfaceEval.azsli>
     
     
 #else
 #else
-
-    //TODO(MaterialPipeline): I think we should rename these to "PositionOnly_*"
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
-
 #endif
 #endif

+ 2 - 0
Gems/Atom/Feature/Common/Assets/Materials/Types/Eye.materialtype

@@ -151,7 +151,9 @@
     },
     },
     // Skin lighting model works well because it supports subsurface scattering, and Eye doesn't need all the other stuff in the Enhanced lighting model.
     // Skin lighting model works well because it supports subsurface scattering, and Eye doesn't need all the other stuff in the Enhanced lighting model.
     "lightingModel": "Skin",
     "lightingModel": "Skin",
+    "materialShaderDefines": "Eye_Defines.azsli",
     "materialShaderCode": "Eye.azsli",
     "materialShaderCode": "Eye.azsli",
+
     "uvNameMap": {
     "uvNameMap": {
         "UV0": "Tiled",
         "UV0": "Tiled",
         "UV1": "Unwrapped"
         "UV1": "Unwrapped"

+ 39 - 0
Gems/Atom/Feature/Common/Assets/Materials/Types/Eye_Defines.azsli

@@ -0,0 +1,39 @@
+/*
+ * 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
+ *
+ */
+#pragma once
+
+#include <Atom/Feature/Common/Assets/Shaders/Materials/MaterialInputs/UvSetCount.azsli>
+
+
+#ifndef PIPELINE_HAS_OBJECT_SRG
+#define PIPELINE_HAS_OBJECT_SRG 1
+#endif
+#ifndef PIPELINE_HAS_DRAW_SRG
+#define PIPELINE_HAS_DRAW_SRG 1
+#endif
+
+#if PIPELINE_HAS_OBJECT_SRG
+#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
+#endif
+#if PIPELINE_HAS_DRAW_SRG
+#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
+#endif
+
+// This file contains the definition for 'struct MaterialParameters', which is generated by the Materialpipeline
+// e.g. for BasePBR this is "basepbr_parameters.azsli"
+// which is usually in [project]/Cache/Intermediate Assets/materials/types/basepbr_parameters.azsli
+#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
+#include <Atom/Features/Materials/MaterialSrg.azsli>
+
+#if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_VertexData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_PixelGeometryData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_SurfaceData.azsli>
+#else    
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
+#endif

+ 4 - 15
Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsli

@@ -5,20 +5,13 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
-    
-#include <scenesrg_all.srgi>
-
-#include <Atom/Features/Skin/SkinObjectSrg.azsli>
-#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
-
-// This file contains the definition for 'struct MaterialParameters', which is generated by the Materialpipeline
-#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
-#include <Atom/Features/Materials/MaterialSrg.azsli>
 
 
 #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_MaterialInputs.azsli>
 #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_MaterialInputs.azsli>
 
 
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
 
 
+    #include <Atom/Features/WrinkleMask.azsli>
+
     COMMON_OPTIONS_BASE_COLOR()
     COMMON_OPTIONS_BASE_COLOR()
     COMMON_OPTIONS_ROUGHNESS()
     COMMON_OPTIONS_ROUGHNESS()
     COMMON_OPTIONS_SPECULAR_F0()
     COMMON_OPTIONS_SPECULAR_F0()
@@ -31,19 +24,15 @@
         return o_normal_useTexture || o_detail_normal_useTexture;
         return o_normal_useTexture || o_detail_normal_useTexture;
     }
     }
     
     
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_VertexData.azsli>
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_VertexEval.azsli>
 
 
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_PixelGeometryData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_PixelGeometryEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_PixelGeometryEval.azsli>
-    
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_SurfaceData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_SurfaceEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_SurfaceEval.azsli>
 
 
 #else
 #else
 
 
     //TODO(MaterialPipeline): I think we should rename these to "PositionOnly_*"
     //TODO(MaterialPipeline): I think we should rename these to "PositionOnly_*"
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
+
     #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
 
 
 #endif
 #endif

+ 1 - 0
Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.materialtype

@@ -163,6 +163,7 @@
         ]
         ]
     },
     },
     "lightingModel": "Skin",
     "lightingModel": "Skin",
+    "materialShaderDefines": "Skin_Defines.azsli",
     "materialShaderCode": "Skin.azsli",
     "materialShaderCode": "Skin.azsli",
     "functors": [
     "functors": [
         {
         {

+ 41 - 0
Gems/Atom/Feature/Common/Assets/Materials/Types/Skin_Defines.azsli

@@ -0,0 +1,41 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+#include <Atom/Feature/Common/Assets/Shaders/Materials/MaterialInputs/UvSetCount.azsli>
+
+#ifndef PIPELINE_HAS_OBJECT_SRG
+#define PIPELINE_HAS_OBJECT_SRG 1
+#endif
+#ifndef PIPELINE_HAS_DRAW_SRG
+#define PIPELINE_HAS_DRAW_SRG 1
+#endif
+
+#if PIPELINE_HAS_OBJECT_SRG
+#include <Atom/Features/Skin/SkinObjectSrg.azsli>
+#endif
+#if PIPELINE_HAS_DRAW_SRG
+#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
+#endif
+
+// This file contains the definition for 'struct MaterialParameters', which is generated by the Materialpipeline
+// e.g. for BasePBR this is "basepbr_parameters.azsli"
+// which is usually in [project]/Cache/Intermediate Assets/materials/types/basepbr_parameters.azsli
+#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
+#include <Atom/Features/Materials/MaterialSrg.azsli>
+
+
+#if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_VertexData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_PixelGeometryData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_SurfaceData.azsli>
+#else
+
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
+#endif

+ 19 - 616
Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR.azsli

@@ -5,208 +5,31 @@
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  * SPDX-License-Identifier: Apache-2.0 OR MIT
  *
  *
  */
  */
-    
-#include <scenesrg_all.srgi>
-#include <viewsrg_all.srgi>
-#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
-#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
-#include <Atom/Features/InstancedTransforms.azsli>
+#pragma once
 
 
-#include <Atom/Feature/Common/Assets/Shaders/Materials/MultilayerPBR/StandardMultilayerPBR_Common.azsli>
+#include <Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_MaterialInputs.azsli>
 
 
 // TODO(MaterialPipeline): There is no good reason for StandardMultilayerPBR to have o_opacity_mode, it doesn't support transparency or alpha cutout.
 // TODO(MaterialPipeline): There is no good reason for StandardMultilayerPBR to have o_opacity_mode, it doesn't support transparency or alpha cutout.
-// It is only needed because it's part of the "Standard" lighting model's surface structure, but we can't use "Base" lighting because it uses things like
-// emission and clear coat. One option would be to add a new "StandardOpaque" lighting model. But really I think we should get rid of the "lighting model"
-// concept from the material pipeline interface and instead let the .materialtype communicate the specific combination features it wants, and this would
-// configure preprocessor flags to do something like omit transparency features. 
-option enum class OpacityMode {Opaque, Cutout, Blended, TintedTransparent} o_opacity_mode = OpacityMode::Opaque;
+// It is only needed because the Transparent - Shader needs it, and that shader is part of the "Standard" lighting model. We can't use "Base" lighting 
+// because the material uses things like emission and clear coat. One option would be to add a new "StandardOpaque" lighting model. 
+// But really I think we should get rid of the "lighting model" concept from the material pipeline interface and instead let the .materialtype 
+// communicate the specific combination features it wants, and this would configure preprocessor flags to do something like omit the transparency features.
+option enum class OpacityMode {Opaque, Cutout, Blended, TintedTransparent} o_opacity_mode;
 
 
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE || MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE || MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE
 
 
-    #define VsInput VsInput_StandardMultilayerPBR
-    #define VsSystemValues VsSystemValues_StandardMultilayerPBR
-    #define VsOutput VsOutput_StandardMultilayerPBR
-    #define EvaluateVertexGeometry EvaluateVertexGeometry_StandardMultilayerPBR
-    #define PixelGeometryData PixelGeometryData_StandardMultilayerPBR
-    #define EvaluatePixelGeometry EvaluatePixelGeometry_StandardMultilayerPBR
-    
-    #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
-        #define EvaluateSurface EvaluateSurface_StandardMultilayerPBR
-    #endif
-
-    struct VsInput_StandardMultilayerPBR 
-    {
-        // TODO: If we can make the shader builder understand class inheritance for reflection data, then
-        // we could make this a class that inherits from VsInput_BasePBR instead of repeating the fields here.
-        float3 position : POSITION;
-        float3 normal : NORMAL;
-        float4 tangent : TANGENT;
-        float2 uv0 : UV0;
-        float2 uv1 : UV1;
-
-        // 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).
-        // [GFX TODO][ATOM-14475]: Come up with a more elegant way to associate the isBound flag with the input stream.
-        float4 m_optional_blendMask : COLOR0;
-    };
-
-    struct VsSystemValues_StandardMultilayerPBR
-    {
-        uint m_instanceId;
-    };
-
-    struct VsOutput_StandardMultilayerPBR
-    {
-        // TODO: If we can make the shader builder understand class inheritance for reflection data, then
-        // we could make this a class that inherits from VsInput_BasePBR instead of repeating the fields here.
-        precise linear centroid 
-        float4 position : SV_Position;
-        float3 normal: NORMAL;
-        float4 tangent : TANGENT;
-        float3 worldPosition : UV0;
-        float2 uvs[UvSetCount] : UV1;
-
-        float3 m_blendMask : UV7;
-        uint m_instanceId : SV_InstanceID;
-    };
-    
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexEval.azsli>
-    
-    VsOutput EvaluateVertexGeometry_StandardMultilayerPBR(
-        const MaterialParameters params,
-        float3 position,
-        float3 normal,
-        float4 tangent,
-        float2 uv0,
-        float2 uv1,
-        float3 vertexBlendMask,
-        uint instanceId,
-        bool useVertexBlendMask)
-    {
-        VsOutput output = EvaluateVertexGeometry_BasePBR(params, position, normal, tangent, uv0, uv1, instanceId, false, float4(1.0f, 1.0f, 1.0f, 1.0f));
-
-        if(useVertexBlendMask)
-        {
-            output.m_blendMask = vertexBlendMask;
-        }
-        else
-        {
-            output.m_blendMask = float3(0,0,0);
-        }
-    
-        return output;
-    }
-
-    // Added this version to make it compatible with the number of arguments in BasePBR.
-    // Avoids compilation errors for compute shaders, listed in a materialpipeline,
-    // that call EvaluateVertexGeometry().
-    VsOutput EvaluateVertexGeometry_StandardMultilayerPBR(
-        const MaterialParameters params,
-        float3 position,
-        float3 normal,
-        float4 tangent,
-        float2 uv0_tiled,
-        float2 uv1_unwrapped,
-        uint instanceId)
-    {
-        return EvaluateVertexGeometry_StandardMultilayerPBR(params, position, normal, tangent, uv0_tiled, uv1_unwrapped, float3(0, 0, 0), instanceId, false);
-    }
-
-    VsOutput EvaluateVertexGeometry_StandardMultilayerPBR(VsInput IN, VsSystemValues SV, const MaterialParameters params)
-    {
-        return EvaluateVertexGeometry_StandardMultilayerPBR(
-            params,
-            IN.position,
-            IN.normal,
-            IN.tangent,
-            IN.uv0,
-            IN.uv1,
-            IN.m_optional_blendMask.rgb,
-            SV.m_instanceId,
-            o_blendMask_isBound
-            );
-    }
-
-    // Have to declare NeedsTangentFrame and ShouldHandleParallax before including StandardPBR_PixelGeometryData.azsli
-    // TODO(MaterialPipeline): consider moving this forward declaration inside StandardPBR_PixelGeometryData.azsli (and similar files that call it)
-    bool NeedsTangentFrame();
-
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryData.azsli>
-
-    class PixelGeometryData_StandardMultilayerPBR : PixelGeometryData_StandardPBR
-    {
-        real3 m_vertexBlendMask;
-    };
-    
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_PixelGeometryEval.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_Common.azsli>
 
 
     #include <Atom/Feature/Common/Assets/Shaders/Materials/MaterialFunctions/MultilayerParallaxDepth.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/MaterialFunctions/MultilayerParallaxDepth.azsli>
-
-    bool ShouldHandleParallax();
-
-    PixelGeometryData EvaluatePixelGeometry_StandardMultilayerPBR(
-        const MaterialParameters params,
-        inout float4 positionSV,
-        float3 positionWS,
-        real3 normalWS,
-        real3 tangentWS,
-        real3 bitangentWS,
-        float2 uvs[UvSetCount],
-        bool isFrontFace,
-        real4x4 objectToWorld,
-        real3 vertexBlendMask)
-    {
-        PixelGeometryData geoData = EvaluatePixelGeometry_BasePBR(params, positionWS, normalWS, tangentWS, bitangentWS, uvs, isFrontFace);
-
-        geoData.isDisplacementClipped = false;
-        geoData.m_vertexBlendMask = vertexBlendMask;
-
-#if ENABLE_PARALLAX
-        if(ShouldHandleParallax())
-        {
-            MultilayerSetPixelDepth(params, vertexBlendMask, geoData.positionWS, geoData.vertexNormal, geoData.tangents, geoData.bitangents,
-                geoData.uvs, isFrontFace, objectToWorld, positionSV.z, positionSV.w, geoData.isDisplacementClipped);
-        }
-#endif
-        return geoData;
-    }
-    
-    PixelGeometryData EvaluatePixelGeometry_StandardMultilayerPBR(inout VsOutput IN, bool isFrontFace, const MaterialParameters params)
-    {
-        real4x4 objectToWorld = real4x4(GetObjectToWorldMatrix(IN.m_instanceId));
-        real3x3 objectToWorldIT = real3x3(GetObjectToWorldMatrixInverseTranspose(IN.m_instanceId));
-
-        real3 normalWS, tangentWS, bitangentWS;
-        ConstructTBN(real3(IN.normal), real4(IN.tangent), objectToWorld, objectToWorldIT, normalWS, tangentWS, bitangentWS);
-
-        return EvaluatePixelGeometry_StandardMultilayerPBR(
-            params,
-            IN.position,
-            IN.worldPosition,
-            normalWS,
-            tangentWS,
-            bitangentWS,
-            IN.uvs,
-            isFrontFace,
-            objectToWorld,
-            real3(IN.m_blendMask));
-    }
-    
     bool CanHandleParallax()
     bool CanHandleParallax()
     {
     {
         // Parallax mapping's non uniform uv transformations break screen space subsurface scattering, disable it when subsurface scattering is enabled.
         // Parallax mapping's non uniform uv transformations break screen space subsurface scattering, disable it when subsurface scattering is enabled.
         // Also, all the debug draw modes avoid parallax (they early-return before parallax code actually) so you can see exactly where the various maps appear on the surface UV space.
         // Also, all the debug draw modes avoid parallax (they early-return before parallax code actually) so you can see exactly where the various maps appear on the surface UV space.
         return !o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_debugDrawMode == DebugDrawMode::None;
         return !o_enableSubsurfaceScattering && o_parallax_feature_enabled && o_debugDrawMode == DebugDrawMode::None;
     }
     }
-
-#else
-
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
-
 #endif
 #endif
 
 
+
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
 
 
     #define DEFINE_LAYER_OPTIONS(prefix) \
     #define DEFINE_LAYER_OPTIONS(prefix) \
@@ -242,435 +65,9 @@ option enum class OpacityMode {Opaque, Cutout, Blended, TintedTransparent} o_opa
             ;
             ;
     }
     }
 
 
-    //! Collects all the raw Standard material inputs for a single layer. See ProcessStandardMaterialInputs().
-    struct StandardMaterialInputs
-    {
-        COMMON_SRG_INPUTS_BASE_COLOR()
-        COMMON_SRG_INPUTS_ROUGHNESS()
-        COMMON_SRG_INPUTS_METALLIC()
-        COMMON_SRG_INPUTS_SPECULAR_F0()
-        COMMON_SRG_INPUTS_NORMAL()
-        COMMON_SRG_INPUTS_CLEAR_COAT()
-        COMMON_SRG_INPUTS_OCCLUSION()
-        COMMON_SRG_INPUTS_EMISSIVE()
-        // Note parallax is omitted here because that requires special handling.
-
-        bool m_normal_useTexture;
-        bool m_baseColor_useTexture;
-        bool m_metallic_useTexture;
-        bool m_specularF0_useTexture;
-        bool m_roughness_useTexture;
-        bool m_emissiveEnabled;
-        bool m_emissive_useTexture;
-        bool m_diffuseOcclusion_useTexture;
-        bool m_specularOcclusion_useTexture;
-        
-    #if ENABLE_CLEAR_COAT
-        bool m_clearCoatEnabled;
-        bool m_clearCoat_factor_useTexture;
-        bool m_clearCoat_roughness_useTexture;
-        bool m_clearCoat_normal_useTexture;
-    #endif
-
-        TextureBlendMode m_baseColorTextureBlendMode;
-
-        float2 m_vertexUv[UvSetCount];
-        float3x3 m_uvMatrix;
-        float3 m_normal;
-        float3 m_tangents[UvSetCount];
-        float3 m_bitangents[UvSetCount];
-
-        sampler m_sampler;
-
-        bool m_isFrontFace;
-    };
-    
-    #if ENABLE_CLEAR_COAT
-    #include <Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli>
-    #endif
-
-    //! Holds the final processed material inputs, after all flags have been checked, textures have been sampled, factors have been applied, etc.
-    //! This data is ready to be copied into a Surface and/or LightingData struct for the lighting system to consume.
-    class ProcessedMaterialInputs
-    {
-        real3 m_normalTS;   //!< Normal in tangent-space
-        real3 m_baseColor;
-        real m_specularF0Factor;
-        real m_metallic;
-        real m_roughness;
-        real3 m_emissiveLighting;
-        real m_diffuseAmbientOcclusion;
-        real m_specularOcclusion;
-    #if ENABLE_CLEAR_COAT
-        ClearCoatSurfaceData m_clearCoat;
-    #endif
-    
-        void InitializeToZero()
-        {
-            m_normalTS = real3(0,0,0);
-            m_baseColor = real3(0,0,0);
-            m_specularF0Factor = 0;
-            m_metallic = 0.0;
-            m_roughness = 0.0;
-            m_emissiveLighting = real3(0,0,0);
-            m_diffuseAmbientOcclusion = 0;
-            m_specularOcclusion = 0;
-    #if ENABLE_CLEAR_COAT
-            m_clearCoat.InitializeToZero();
-    #endif
-        }
-    };
-
-    //! Processes the set of Standard material inputs for a single layer.
-    //! The FILL_STANDARD_MATERIAL_INPUTS() macro below can be used to fill the StandardMaterialInputs struct.
-    ProcessedMaterialInputs ProcessStandardMaterialInputs(StandardMaterialInputs inputs, float4 uvDxDy = float4(0.0f, 0.0f, 0.0f, 0.0f), bool customDerivatives = false)
-    {
-        ProcessedMaterialInputs result;
-    
-        float2 transformedUv[UvSetCount];
-        transformedUv[0] = mul(inputs.m_uvMatrix, float3(inputs.m_vertexUv[0], 1.0)).xy;
-        transformedUv[1] = inputs.m_vertexUv[1];
-    
-        real3x3 normalUvMatrix = inputs.m_normalMapUvIndex == 0 ? real3x3(inputs.m_uvMatrix) : real3x3(CreateIdentity3x3());
-        result.m_normalTS = GetNormalInputTS(inputs.m_normalMap, inputs.m_sampler, transformedUv[inputs.m_normalMapUvIndex], inputs.m_flipNormalX, inputs.m_flipNormalY, normalUvMatrix, inputs.m_normal_useTexture, real(inputs.m_normalFactor), uvDxDy, customDerivatives);
-    
-        real3 sampledBaseColor = GetBaseColorInput(inputs.m_baseColorMap, inputs.m_sampler, transformedUv[inputs.m_baseColorMapUvIndex], real3(inputs.m_baseColor.rgb), inputs.m_baseColor_useTexture, uvDxDy, customDerivatives);
-        result.m_baseColor = BlendBaseColor(sampledBaseColor, real3(inputs.m_baseColor.rgb), real(inputs.m_baseColorFactor), inputs.m_baseColorTextureBlendMode, inputs.m_baseColor_useTexture);
-        result.m_specularF0Factor = GetSpecularInput(inputs.m_specularF0Map, inputs.m_sampler, transformedUv[inputs.m_specularF0MapUvIndex], real(inputs.m_specularF0Factor), inputs.m_specularF0_useTexture, uvDxDy, customDerivatives);
-        result.m_metallic = GetMetallicInput(inputs.m_metallicMap, inputs.m_sampler, transformedUv[inputs.m_metallicMapUvIndex], real(inputs.m_metallicFactor), inputs.m_metallic_useTexture, uvDxDy, customDerivatives);
-        result.m_roughness = GetRoughnessInput(inputs.m_roughnessMap, GetMaterialTextureSampler(), transformedUv[inputs.m_roughnessMapUvIndex], real(inputs.m_roughnessFactor), real(inputs.m_roughnessLowerBound), real(inputs.m_roughnessUpperBound), inputs.m_roughness_useTexture, uvDxDy, customDerivatives);
-
-        result.m_emissiveLighting = GetEmissiveInput(inputs.m_emissiveMap, inputs.m_sampler, transformedUv[inputs.m_emissiveMapUvIndex], real(inputs.m_emissiveIntensity), real3(inputs.m_emissiveColor.rgb), 0.0, 1.0, inputs.m_emissiveEnabled, inputs.m_emissive_useTexture, uvDxDy, customDerivatives);
-        result.m_diffuseAmbientOcclusion = GetOcclusionInput(inputs.m_diffuseOcclusionMap, inputs.m_sampler, transformedUv[inputs.m_diffuseOcclusionMapUvIndex], real(inputs.m_diffuseOcclusionFactor), inputs.m_diffuseOcclusion_useTexture, uvDxDy, customDerivatives);
-        result.m_specularOcclusion = GetOcclusionInput(inputs.m_specularOcclusionMap, GetMaterialTextureSampler(), transformedUv[inputs.m_specularOcclusionMapUvIndex], real(inputs.m_specularOcclusionFactor), inputs.m_specularOcclusion_useTexture, uvDxDy, customDerivatives);
-    
-    #if ENABLE_CLEAR_COAT
-        result.m_clearCoat.InitializeToZero();
-        if(inputs.m_clearCoatEnabled)
-        {
-            real3x3 clearCoatUvMatrix = inputs.m_clearCoatNormalMapUvIndex == 0 ? real3x3(inputs.m_uvMatrix) : real3x3(CreateIdentity3x3());
-
-            GetClearCoatInputs(inputs.m_clearCoatInfluenceMap, transformedUv[inputs.m_clearCoatInfluenceMapUvIndex], real(inputs.m_clearCoatFactor), inputs.m_clearCoat_factor_useTexture,
-                                inputs.m_clearCoatRoughnessMap, transformedUv[inputs.m_clearCoatRoughnessMapUvIndex], real(inputs.m_clearCoatRoughness), inputs.m_clearCoat_roughness_useTexture,
-                                inputs.m_clearCoatNormalMap,    transformedUv[inputs.m_clearCoatNormalMapUvIndex], inputs.m_normal, inputs.m_clearCoat_normal_useTexture, real(inputs.m_clearCoatNormalStrength),
-                                clearCoatUvMatrix, inputs.m_tangents[inputs.m_clearCoatNormalMapUvIndex], inputs.m_bitangents[inputs.m_clearCoatNormalMapUvIndex],
-                                inputs.m_sampler, inputs.m_isFrontFace,
-                                result.m_clearCoat.factor, result.m_clearCoat.roughness, result.m_clearCoat.normal, uvDxDy, customDerivatives);
-        }
-    #endif
-
-        return result;
-    }
-
-    //! Fills a StandardMaterialInputs struct with data from the MaterialSrg, shader options, and local vertex data.
-    #define FILL_STANDARD_MATERIAL_INPUTS(inputs, srgLayerPrefix, optionsLayerPrefix, blendWeight)                     \
-        inputs.m_sampler = GetMaterialTextureSampler();                                                                     \
-        inputs.m_vertexUv = uvs;                                                                                       \
-        inputs.m_uvMatrix = srgLayerPrefix##m_uvMatrix;                                                                \
-        inputs.m_normal = normalWS;                                                                                \
-        inputs.m_tangents = tangents;                                                                                  \
-        inputs.m_bitangents = bitangents;                                                                              \
-        inputs.m_isFrontFace = isFrontFace;                                                                            \
-                                                                                                                       \
-        inputs.m_normalMapUvIndex = srgLayerPrefix##m_normalMapUvIndex;                                                \
-        inputs.m_normalMap = GetMaterialTexture(srgLayerPrefix##m_normalMap);                                                              \
-        inputs.m_flipNormalX = srgLayerPrefix##m_flipNormalX;                                                          \
-        inputs.m_flipNormalY = srgLayerPrefix##m_flipNormalY;                                                          \
-        inputs.m_normal_useTexture = optionsLayerPrefix##o_normal_useTexture;                                          \
-        inputs.m_normalFactor = srgLayerPrefix##m_normalFactor * blendWeight;                                          \
-        inputs.m_baseColorMap = GetMaterialTexture(srgLayerPrefix##m_baseColorMap);                                                        \
-        inputs.m_baseColorMapUvIndex = srgLayerPrefix##m_baseColorMapUvIndex;                                          \
-        inputs.m_baseColor = srgLayerPrefix##m_baseColor.rgb;                                                              \
-        inputs.m_baseColor_useTexture = optionsLayerPrefix##o_baseColor_useTexture;                                    \
-        inputs.m_baseColorFactor = srgLayerPrefix##m_baseColorFactor;                                                  \
-        inputs.m_baseColorTextureBlendMode = optionsLayerPrefix##o_baseColorTextureBlendMode;                          \
-        inputs.m_metallicMap = GetMaterialTexture(srgLayerPrefix##m_metallicMap);                                                          \
-        inputs.m_metallicMapUvIndex = srgLayerPrefix##m_metallicMapUvIndex;                                            \
-        inputs.m_metallicFactor = srgLayerPrefix##m_metallicFactor;                                                    \
-        inputs.m_metallic_useTexture = optionsLayerPrefix##o_metallic_useTexture;                                      \
-        inputs.m_specularF0Map = GetMaterialTexture(srgLayerPrefix##m_specularF0Map);                                                      \
-        inputs.m_specularF0MapUvIndex = srgLayerPrefix##m_specularF0MapUvIndex;                                        \
-        inputs.m_specularF0Factor = srgLayerPrefix##m_specularF0Factor;                                                \
-        inputs.m_specularF0_useTexture = optionsLayerPrefix##o_specularF0_useTexture;                                  \
-        inputs.m_roughnessMap = GetMaterialTexture(srgLayerPrefix##m_roughnessMap);                                                        \
-        inputs.m_roughnessMapUvIndex = srgLayerPrefix##m_roughnessMapUvIndex;                                          \
-        inputs.m_roughnessFactor = srgLayerPrefix##m_roughnessFactor;                                                  \
-        inputs.m_roughnessLowerBound = srgLayerPrefix##m_roughnessLowerBound;                                          \
-        inputs.m_roughnessUpperBound = srgLayerPrefix##m_roughnessUpperBound;                                          \
-        inputs.m_roughness_useTexture = optionsLayerPrefix##o_roughness_useTexture;                                    \
-                                                                                                                       \
-        inputs.m_emissiveMap = GetMaterialTexture(srgLayerPrefix##m_emissiveMap);                                                          \
-        inputs.m_emissiveMapUvIndex = srgLayerPrefix##m_emissiveMapUvIndex;                                            \
-        inputs.m_emissiveIntensity = srgLayerPrefix##m_emissiveIntensity;                                              \
-        inputs.m_emissiveColor = srgLayerPrefix##m_emissiveColor.rgb;                                                      \
-        inputs.m_emissiveAffectedByAlpha = srgLayerPrefix##m_emissiveAffectedByAlpha;                                  \
-        inputs.m_emissiveEnabled = optionsLayerPrefix##o_emissiveEnabled;                                              \
-        inputs.m_emissive_useTexture = optionsLayerPrefix##o_emissive_useTexture;                                      \
-                                                                                                                       \
-        inputs.m_diffuseOcclusionMap = GetMaterialTexture(srgLayerPrefix##m_diffuseOcclusionMap);                                          \
-        inputs.m_diffuseOcclusionMapUvIndex = srgLayerPrefix##m_diffuseOcclusionMapUvIndex;                            \
-        inputs.m_diffuseOcclusionFactor = srgLayerPrefix##m_diffuseOcclusionFactor;                                    \
-        inputs.m_diffuseOcclusion_useTexture = optionsLayerPrefix##o_diffuseOcclusion_useTexture;                      \
-                                                                                                                       \
-        inputs.m_specularOcclusionMap = GetMaterialTexture(srgLayerPrefix##m_specularOcclusionMap);                                        \
-        inputs.m_specularOcclusionMapUvIndex = srgLayerPrefix##m_specularOcclusionMapUvIndex;                          \
-        inputs.m_specularOcclusionFactor = srgLayerPrefix##m_specularOcclusionFactor;                                  \
-        inputs.m_specularOcclusion_useTexture = optionsLayerPrefix##o_specularOcclusion_useTexture;                    
-                                                                                                                       
-             
-    #if ENABLE_CLEAR_COAT
-    #define FILL_STANDARD_MATERIAL_INPUTS_CLEAR_COAT(inputs, srgLayerPrefix, optionsLayerPrefix, blendWeight)        \
-        inputs.m_clearCoatEnabled = o_clearCoat_feature_enabled && optionsLayerPrefix##o_clearCoat_enabled;          \
-        inputs.m_clearCoatInfluenceMap = GetMaterialTexture(srgLayerPrefix##m_clearCoatInfluenceMap);                                    \
-        inputs.m_clearCoatInfluenceMapUvIndex = srgLayerPrefix##m_clearCoatInfluenceMapUvIndex;                      \
-        inputs.m_clearCoatFactor = srgLayerPrefix##m_clearCoatFactor;                                                \
-        inputs.m_clearCoat_factor_useTexture = optionsLayerPrefix##o_clearCoat_factor_useTexture;                    \
-        inputs.m_clearCoatRoughnessMap = GetMaterialTexture(srgLayerPrefix##m_clearCoatRoughnessMap);                                    \
-        inputs.m_clearCoatRoughnessMapUvIndex = srgLayerPrefix##m_clearCoatRoughnessMapUvIndex;                      \
-        inputs.m_clearCoatRoughness = srgLayerPrefix##m_clearCoatRoughness;                                          \
-        inputs.m_clearCoat_roughness_useTexture = optionsLayerPrefix##o_clearCoat_roughness_useTexture;              \
-        inputs.m_clearCoatNormalMap = GetMaterialTexture(srgLayerPrefix##m_clearCoatNormalMap);                                          \
-        inputs.m_clearCoatNormalMapUvIndex = srgLayerPrefix##m_clearCoatNormalMapUvIndex;                            \
-        inputs.m_clearCoat_normal_useTexture = optionsLayerPrefix##o_clearCoat_normal_useTexture;                    \
-        inputs.m_clearCoatNormalStrength = srgLayerPrefix##m_clearCoatNormalStrength;
-    #else
-    #define FILL_STANDARD_MATERIAL_INPUTS_CLEAR_COAT(inputs, srgLayerPrefix, optionsLayerPrefix, blendWeight)
-    #endif
-
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_SurfaceData.azsli>
-
-    Surface EvaluateSurface_StandardMultilayerPBR(
-        const MaterialParameters params,
-        float3 positionWS,
-        float3 normalWS,
-        float3 tangents[UvSetCount],
-        float3 bitangents[UvSetCount],
-        float2 uvs[UvSetCount],
-        bool isFrontFace,
-        bool isDisplacementClipped,
-        real3 vertexBlendMask,
-        float4 uvDxDy,
-        bool customDerivatives)
-    {
-        LayerBlendSource blendSource = GetFinalLayerBlendSource();
-        
-        // ------- Debug Modes -------
-
-        if(o_debugDrawMode == DebugDrawMode::BlendMask)
-        {
-            real3 blendMaskValues = GetApplicableBlendMaskValues(params, blendSource, uvs[params.m_blendMaskUvIndex], vertexBlendMask, uvDxDy, customDerivatives);
-            return MakeDebugSurface(positionWS, normalWS, real3(blendMaskValues));
-        }
-    
-        if(o_debugDrawMode == DebugDrawMode::Displacement)
-        {
-            real startDepth = real(-params.m_displacementMax);
-            real stopDepth = real(-params.m_displacementMin);
-            // the heightmap and sampler doesn't matter here, since they will simply be passed on to the GetDepth() - function in StandardMultiLayerPBR_Common.azsli, which ignores them.
-            real depth = GetNormalizedDepth(GetMaterialTexture(params.m_layer1_m_heightmap), GetMaterialTextureSampler(), startDepth, stopDepth, uvs[params.m_parallaxUvIndex], real2(0,0), real2(0,0));
-            real height = 1 - saturate(depth);
-            return MakeDebugSurface(positionWS, normalWS, real3(height,height,height));
-        }
-    
-        if(o_debugDrawMode == DebugDrawMode::FinalBlendWeights)
-        {
-            real3 blendWeights;
-            if (customDerivatives)
-            {
-                blendWeights = GetBlendWeights(params, blendSource, uvs[params.m_blendMaskUvIndex], vertexBlendMask, uvDxDy, customDerivatives);
-            }
-            else
-            {
-                blendWeights = GetBlendWeights(params, blendSource, uvs[params.m_blendMaskUvIndex], vertexBlendMask, float4(0.0f, 0.0f, 0.0f, 0.0f), false);
-            }
-            return MakeDebugSurface(positionWS, normalWS, real3(blendWeights));
-        }
-
-        // ------- Calculate Layer Blend Mask Values -------
-    
-        // Now that any parallax has been calculated, we calculate the blend factors for any layers that are impacted by the parallax.
-        real3 blendWeights;
-        if (customDerivatives)
-        {
-            blendWeights = real3(GetBlendWeights(params, blendSource, uvs[params.m_blendMaskUvIndex], vertexBlendMask, uvDxDy, customDerivatives));
-        }
-        else
-        {
-            blendWeights = real3(GetBlendWeights(params, blendSource, uvs[params.m_blendMaskUvIndex], vertexBlendMask, float4(0.0f, 0.0f, 0.0f, 0.0f), false));
-        }
-        
-        
-        // ------- Layer 1 (base layer) -----------
-
-        ProcessedMaterialInputs lightingInputLayer1;
-        if(blendWeights.r > 0)
-        {
-            StandardMaterialInputs inputs;
-            FILL_STANDARD_MATERIAL_INPUTS(inputs, params.m_layer1_, o_layer1_, blendWeights.r)
-            FILL_STANDARD_MATERIAL_INPUTS_CLEAR_COAT(inputs, params.m_layer1_, o_layer1_, blendWeights.r)
-            lightingInputLayer1 = ProcessStandardMaterialInputs(inputs, uvDxDy, customDerivatives);
-        }
-        else
-        {
-            lightingInputLayer1.InitializeToZero();
-            blendWeights.r = 0;
-        }
-    
-        // ----------- Layer 2 -----------
-
-        ProcessedMaterialInputs lightingInputLayer2; 
-        if(o_layer2_enabled && blendWeights.g > 0)
-        {
-            StandardMaterialInputs inputs;
-            FILL_STANDARD_MATERIAL_INPUTS(inputs, params.m_layer2_, o_layer2_, blendWeights.g)
-            FILL_STANDARD_MATERIAL_INPUTS_CLEAR_COAT(inputs, params.m_layer2_, o_layer2_, blendWeights.g)
-            lightingInputLayer2 = ProcessStandardMaterialInputs(inputs, uvDxDy, customDerivatives);
-        }
-        else
-        {
-            lightingInputLayer2.InitializeToZero();
-            blendWeights.g = 0;
-        }
-    
-        // ----------- Layer 3 -----------
-
-        ProcessedMaterialInputs lightingInputLayer3;
-        if(o_layer3_enabled && blendWeights.b > 0)
-        {
-            StandardMaterialInputs inputs;
-            FILL_STANDARD_MATERIAL_INPUTS(inputs, params.m_layer3_, o_layer3_, blendWeights.b)
-            FILL_STANDARD_MATERIAL_INPUTS_CLEAR_COAT(inputs, params.m_layer3_, o_layer3_, blendWeights.b)
-            lightingInputLayer3 = ProcessStandardMaterialInputs(inputs, uvDxDy, customDerivatives);
-        }
-        else
-        {
-            lightingInputLayer3.InitializeToZero();
-            blendWeights.b = 0;
-        }
-
-        // ------- Combine all layers ---------
-    
-        Surface surface;
-        surface.position = positionWS;
-
-        // ------- Combine Normals ---------
-
-        real3 normalTS = real3(0,0,1);
-        if(blendWeights.r > 0)
-        {
-            normalTS = lightingInputLayer1.m_normalTS;
-        }
-        if(o_layer2_enabled && blendWeights.g > 0)
-        {
-            normalTS = ReorientTangentSpaceNormal(normalTS, lightingInputLayer2.m_normalTS);
-        }
-        if(o_layer3_enabled && blendWeights.b > 0)
-        {
-            normalTS = ReorientTangentSpaceNormal(normalTS, lightingInputLayer3.m_normalTS);
-        }
-        // [GFX TODO][ATOM-14591]: This will only work if the normal maps all use the same UV stream. We would need to add support for having them in different UV streams.
-        surface.vertexNormal = normalWS;
-        surface.normal = normalize(TangentSpaceToWorld(normalTS, normalWS, tangents[params.m_parallaxUvIndex], bitangents[params.m_parallaxUvIndex]));
-        
-        // ------- Combine Albedo, roughness, specular, roughness ---------
-
-        real3 baseColor = BlendLayers(lightingInputLayer1.m_baseColor, lightingInputLayer2.m_baseColor, lightingInputLayer3.m_baseColor, blendWeights);
-        real specularF0Factor = BlendLayers(lightingInputLayer1.m_specularF0Factor, lightingInputLayer2.m_specularF0Factor, lightingInputLayer3.m_specularF0Factor, blendWeights);
-        real metallic = BlendLayers(lightingInputLayer1.m_metallic, lightingInputLayer2.m_metallic, lightingInputLayer3.m_metallic, blendWeights);
-    
-        if(o_parallax_highlightClipping && isDisplacementClipped)
-        {
-            ApplyParallaxClippingHighlight(baseColor);
-        }
-
-        surface.SetAlbedoAndSpecularF0(baseColor, specularF0Factor, metallic);
-
-        surface.roughnessLinear = BlendLayers(lightingInputLayer1.m_roughness, lightingInputLayer2.m_roughness, lightingInputLayer3.m_roughness, blendWeights);
-        surface.CalculateRoughnessA();
-    
-        // ------- Init and Combine Lighting Data -------
-
-        surface.emissiveLighting = BlendLayers(lightingInputLayer1.m_emissiveLighting, lightingInputLayer2.m_emissiveLighting, lightingInputLayer3.m_emissiveLighting, blendWeights);
-        surface.specularOcclusion = BlendLayers(lightingInputLayer1.m_specularOcclusion, lightingInputLayer2.m_specularOcclusion, lightingInputLayer3.m_specularOcclusion, blendWeights);
-        surface.diffuseAmbientOcclusion = BlendLayers(lightingInputLayer1.m_diffuseAmbientOcclusion, lightingInputLayer2.m_diffuseAmbientOcclusion, lightingInputLayer3.m_diffuseAmbientOcclusion, blendWeights);
-
-        // ------- Combine Clearcoat -------
-
-    #if ENABLE_CLEAR_COAT
-        if(o_clearCoat_feature_enabled)
-        {
-            surface.clearCoat.factor = BlendLayers(lightingInputLayer1.m_clearCoat.factor, lightingInputLayer2.m_clearCoat.factor, lightingInputLayer3.m_clearCoat.factor, blendWeights);
-            surface.clearCoat.roughness = BlendLayers(lightingInputLayer1.m_clearCoat.roughness, lightingInputLayer2.m_clearCoat.roughness, lightingInputLayer3.m_clearCoat.roughness, blendWeights);
-
-            // [GFX TODO][ATOM-14592] This is not the right way to blend the normals. We need to use ReorientTangentSpaceNormal(), and that requires GetClearCoatInputs() to return the normal in TS instead of WS.
-            surface.clearCoat.normal = BlendLayers(lightingInputLayer1.m_clearCoat.normal, lightingInputLayer2.m_clearCoat.normal, lightingInputLayer3.m_clearCoat.normal, blendWeights);
-            surface.clearCoat.normal = normalize(surface.clearCoat.normal);
-        
-            ApplyClearCoatToSpecularF0(surface.specularF0, surface.clearCoat.factor);
-        }
-    #endif
-
-        return surface;
-    }
-
-    // helper function to keep compatible with the previous version
-    // because dxc compiler doesn't allow default parameters on functions with overloads
-    Surface EvaluateSurface_StandardMultilayerPBR(
-        const MaterialParameters params,
-        float3 positionWS,
-        real3 normalWS,
-        float3 tangents[UvSetCount],
-        float3 bitangents[UvSetCount],
-        float2 uvs[UvSetCount],
-        bool isFrontFace,
-        bool isDisplacementClipped,
-        real3 vertexBlendMask)
-    {
-        return EvaluateSurface_StandardMultilayerPBR(
-            params,
-            positionWS,
-            normalWS,
-            tangents,
-            bitangents,
-            uvs,
-            isFrontFace,
-            isDisplacementClipped,
-            vertexBlendMask,
-            float4(0.0f, 0.0f, 0.0f, 0.0f),
-            false);
-    }
-
-    Surface EvaluateSurface_StandardMultilayerPBR(VsOutput IN, PixelGeometryData geoData, const MaterialParameters params, float4 uvDxDy, bool customDerivatives)
-    {
-        return EvaluateSurface_StandardMultilayerPBR(
-            params,
-            geoData.positionWS,
-            geoData.vertexNormal,
-            geoData.tangents,
-            geoData.bitangents,
-            geoData.uvs,
-            geoData.isFrontFace,
-            geoData.isDisplacementClipped,
-            geoData.m_vertexBlendMask,
-            uvDxDy,
-            customDerivatives);
-    }
-
-    Surface EvaluateSurface_StandardMultilayerPBR(VsOutput IN, PixelGeometryData geoData, const MaterialParameters params)
-    {
-        return EvaluateSurface_StandardMultilayerPBR(
-            params,
-            geoData.positionWS,
-            geoData.vertexNormal,
-            geoData.tangents,
-            geoData.bitangents,
-            geoData.uvs,
-            geoData.isFrontFace,
-            geoData.isDisplacementClipped,
-            geoData.m_vertexBlendMask,
-            float4(0.0f, 0.0f, 0.0f, 0.0f),
-            false);
-    }
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_VertexEval.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_PixelGeometryEval.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_SurfaceEval.azsli>
 
 
 #elif MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE
 #elif MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE
 
 
@@ -685,10 +82,16 @@ option enum class OpacityMode {Opaque, Cutout, Blended, TintedTransparent} o_opa
     {
     {
         return ShouldHandleParallax();
         return ShouldHandleParallax();
     }
     }
-    
+
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_VertexEval.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_PixelGeometryEval.azsli>
+
     void EvaluateSurface(VsOutput IN, PixelGeometryData geoData, const MaterialParameters params)
     void EvaluateSurface(VsOutput IN, PixelGeometryData geoData, const MaterialParameters params)
     {
     {
         // do nothing, this is where alpha clip can be done if it's supported
         // do nothing, this is where alpha clip can be done if it's supported
     }
     }
 
 
+#else
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
+
 #endif
 #endif

+ 1 - 0
Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR.materialtype

@@ -362,6 +362,7 @@
         ]
         ]
     },
     },
     "lightingModel": "Standard",
     "lightingModel": "Standard",
+    "materialShaderDefines": "StandardMultilayerPBR_Defines.azsli",
     "materialShaderCode": "StandardMultilayerPBR.azsli",
     "materialShaderCode": "StandardMultilayerPBR.azsli",
     "functors": [
     "functors": [
         {
         {

+ 41 - 0
Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_Defines.azsli

@@ -0,0 +1,41 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+#include <Atom/Feature/Common/Assets/Shaders/Materials/MaterialInputs/UvSetCount.azsli>
+
+#ifndef PIPELINE_HAS_OBJECT_SRG
+#define PIPELINE_HAS_OBJECT_SRG 1
+#endif
+#ifndef PIPELINE_HAS_DRAW_SRG
+#define PIPELINE_HAS_DRAW_SRG 1
+#endif
+
+#if PIPELINE_HAS_OBJECT_SRG
+#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
+#endif
+#if PIPELINE_HAS_DRAW_SRG
+#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
+#endif
+
+// This file contains the definition for 'struct MaterialParameters', which is generated by the Materialpipeline
+#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
+#include <Atom/Features/Materials/MaterialSrg.azsli>
+
+
+#if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_VertexData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_PixelGeometryData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_SurfaceData.azsli>
+#elif MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_VertexData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_PixelGeometryData.azsli>
+#else
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
+#endif

+ 5 - 23
Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR.azsli

@@ -8,18 +8,6 @@
 
 
 #pragma once
 #pragma once
 
 
-#define ENABLE_VERTEX_COLOR 1
-
-
-//TODO(MaterialPipeline): Try removing different parts of the SRG and see how hard/easy it is to customize the surface function.
-
-#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
-#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
-
-// This file contains the definition for 'struct MaterialParameters', which is generated by the Materialpipeline
-#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
-#include <Atom/Features/Materials/MaterialSrg.azsli>
-
 #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_MaterialInputs.azsli>
 #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_MaterialInputs.azsli>
 
 
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
 #if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
@@ -47,18 +35,14 @@
     }
     }
     
     
     // Callback function for ParallaxMapping.azsli
     // Callback function for ParallaxMapping.azsli
-    DepthResult GetDepth(Texture2D heightmap, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
+    DepthResult GetDepth(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
     {
     {
         return SampleDepthFromHeightmap(heightmap, mapSampler, uv, uv_ddx, uv_ddy);
         return SampleDepthFromHeightmap(heightmap, mapSampler, uv, uv_ddx, uv_ddy);
     }
     }
 
 
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexData.azsli>
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexEval.azsli>
 
 
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryEval.azsli>
-
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_SurfaceData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_SurfaceEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_SurfaceEval.azsli>
 
 
 #elif MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE
 #elif MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE
@@ -81,17 +65,15 @@
     }
     }
     
     
     // Callback function for ParallaxMapping.azsli
     // Callback function for ParallaxMapping.azsli
-    DepthResult GetDepth(Texture2D heightmap, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
+    DepthResult GetDepth(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
     {
     {
         return SampleDepthFromHeightmap(heightmap, mapSampler, uv, uv_ddx, uv_ddy);
         return SampleDepthFromHeightmap(heightmap, mapSampler, uv, uv_ddx, uv_ddy);
     }
     }
     
     
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexEval.azsli>
     
     
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryEval.azsli>
-    
+
     #include "Atom/Feature/Common/Assets/Shaders/Materials/MaterialFunctions/StandardGetAlphaAndClip.azsli"
     #include "Atom/Feature/Common/Assets/Shaders/Materials/MaterialFunctions/StandardGetAlphaAndClip.azsli"
 
 
     void EvaluateSurface(VsOutput IN, PixelGeometryData geoData, const MaterialParameters params)
     void EvaluateSurface(VsOutput IN, PixelGeometryData geoData, const MaterialParameters params)
@@ -99,10 +81,10 @@
         GetAlphaAndClip(params, geoData.uvs);
         GetAlphaAndClip(params, geoData.uvs);
     }
     }
 
 
+
 #else
 #else
 
 
     //TODO(MaterialPipeline): I think we should rename these to "PositionOnly_*"
     //TODO(MaterialPipeline): I think we should rename these to "PositionOnly_*"
-    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
     #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli>
 
 
 #endif
 #endif

+ 1 - 0
Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR.materialtype

@@ -66,6 +66,7 @@
         ]
         ]
     },
     },
     "lightingModel": "Standard",
     "lightingModel": "Standard",
+    "materialShaderDefines": "StandardPBR_Defines.azsli",
     "materialShaderCode": "StandardPBR.azsli",
     "materialShaderCode": "StandardPBR.azsli",
     "functors": [
     "functors": [
     ],
     ],

+ 45 - 0
Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Defines.azsli

@@ -0,0 +1,45 @@
+
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+#define ENABLE_VERTEX_COLOR 1
+#include <Atom/Feature/Common/Assets/Shaders/Materials/MaterialInputs/UvSetCount.azsli>
+
+#ifndef PIPELINE_HAS_OBJECT_SRG
+#define PIPELINE_HAS_OBJECT_SRG 1
+#endif
+#ifndef PIPELINE_HAS_DRAW_SRG
+#define PIPELINE_HAS_DRAW_SRG 1
+#endif
+
+#if PIPELINE_HAS_OBJECT_SRG
+#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
+#endif
+#if PIPELINE_HAS_DRAW_SRG
+#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
+#endif
+
+// This file contains the definition for 'struct MaterialParameters', which is generated by the Materialpipeline
+// e.g. for BasePBR this is "basepbr_parameters.azsli"
+// which is usually in [project]/Cache/Intermediate Assets/materials/types/basepbr_parameters.azsli
+#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
+#include <Atom/Features/Materials/MaterialSrg.azsli>
+
+#if MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_SurfaceData.azsli>
+#elif  MATERIALPIPELINE_SHADER_HAS_GEOMETRIC_PIXEL_STAGE
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexData.azsli>
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/StandardPBR/StandardPBR_PixelGeometryData.azsli>
+    
+#else
+    #include <Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli>
+#endif

+ 27 - 0
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/GoboTexture.azsli

@@ -0,0 +1,27 @@
+/*
+ * 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
+ *
+ */
+#pragma once
+
+float SampleGoboTexture(int goboTexIndex, sampler goboSampler, float4x4 lightViewProjectionMatrix, float3 positionWs)
+{
+    if (goboTexIndex < ViewSrg::MaxGoboTextureCount)
+    {
+        float4 positionInView = mul(lightViewProjectionMatrix, float4(positionWs, 1.0));
+        positionInView /= positionInView.w;
+        float2 goboUv = float2((positionInView.x + 1.0)/2.0, (positionInView.y + 1.0)/2.0);
+
+        #ifdef CS_SAMPLERS
+            return ViewSrg::m_goboTextures[goboTexIndex].SampleLevel(goboSampler, goboUv, 0);
+        #else
+            return ViewSrg::m_goboTextures[goboTexIndex].Sample(goboSampler, goboUv);
+        #endif
+    }
+    else {
+        return 1.0f;
+    }
+}

+ 3 - 3
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/InstancedTransforms.azsli

@@ -28,7 +28,7 @@ float4x4 GetObjectToWorldMatrix(uint instanceId)
     }
     }
     else
     else
     {
     {
-        return ObjectSrg::GetWorldMatrix();
+        return SceneSrg::GetObjectToWorldMatrix(ObjectSrg::m_objectId);
     }
     }
 }
 }
 
 
@@ -42,7 +42,7 @@ float3x3 GetObjectToWorldMatrixInverseTranspose(uint instanceId)
     }
     }
     else
     else
     {
     {
-        return ObjectSrg::GetWorldMatrixInverseTranspose();
+        return SceneSrg::GetObjectToWorldInverseTransposeMatrix(ObjectSrg::m_objectId);
     }
     }
 }
 }
 
 
@@ -55,6 +55,6 @@ float4x4 GetObjectToWorldMatrixPrev(uint instanceId)
     }
     }
     else
     else
     {
     {
-        return ObjectSrg::GetWorldMatrixPrev();
+        return SceneSrg::GetObjectToWorldMatrixPrev(ObjectSrg::m_objectId);
     }
     }
 }
 }

+ 27 - 0
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/LightingChannels.azsli

@@ -0,0 +1,27 @@
+/*
+ * 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
+ *
+ */
+#pragma once
+
+#ifndef PIPELINE_HAS_OBJECT_SRG
+// assume we have an object-srg by default
+#define PIPELINE_HAS_OBJECT_SRG 1
+#endif 
+
+#if PIPELINE_HAS_OBJECT_SRG
+uint GetLightingChannelMask(VsSystemValues SV)
+{
+    return ObjectSrg::m_lightingChannelMask;
+}
+#else
+uint GetLightingChannelMask(VsSystemValues SV)
+{
+    return SV.m_lightingChannelMask;
+}
+#endif // PIPELINE_HAS_PASS_SRG
+
+

+ 15 - 5
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Materials/SceneMaterialSrg.azsli

@@ -45,24 +45,34 @@ Texture2D GetMaterialTexture(const int readIndex)
     return Bindless::GetTexture2D(readIndex);
     return Bindless::GetTexture2D(readIndex);
 }
 }
 
 
-const MaterialParameters GetMaterialParameters()
+const MaterialParameters GetMaterialParameters(const int materialTypeId, const int materialInstanceId)
 {
 {
     // The ByteAddressBuffers referenced in the SceneMaterialSrg hold the MaterialParameters for all MaterialTypes
     // The ByteAddressBuffers referenced in the SceneMaterialSrg hold the MaterialParameters for all MaterialTypes
     // but any given material-shader knows only it's MaterialParameter - struct.
     // but any given material-shader knows only it's MaterialParameter - struct.
     // The first two integers in the MaterialParameter struct are the MaterialType-Id and the MaterialInstanceId:
     // The first two integers in the MaterialParameter struct are the MaterialType-Id and the MaterialInstanceId:
     // Load only those and compare the values to the DrawSrg to make sure we are converting the contents of the ByteAddresBuffer
     // Load only those and compare the values to the DrawSrg to make sure we are converting the contents of the ByteAddresBuffer
     // to the correct MaterialParameter struct
     // to the correct MaterialParameter struct
-    int materialTypeBufferIndex = int(SceneMaterialSrg::m_materialTypeBufferIndices.Load(ObjectSrg::m_materialTypeId * 4 /* sizeof(int)*/));
+    int materialTypeBufferIndex = int(SceneMaterialSrg::m_materialTypeBufferIndices.Load(materialTypeId * 4 /* sizeof(int)*/));
+    if (materialTypeBufferIndex < 0)
+    {
+        return (MaterialParameters)0;
+    }
     ByteAddressBuffer materialInstances = Bindless::GetByteAddressBuffer(materialTypeBufferIndex);
     ByteAddressBuffer materialInstances = Bindless::GetByteAddressBuffer(materialTypeBufferIndex);
-    uint baseOffset = sizeof(MaterialParameters) * ObjectSrg::m_materialInstanceId;
+    uint baseOffset = sizeof(MaterialParameters) * materialInstanceId;
     uint2 loadedId = materialInstances.Load2(baseOffset);
     uint2 loadedId = materialInstances.Load2(baseOffset);
-    if (loadedId.x != ObjectSrg::m_materialTypeId || loadedId.y != ObjectSrg::m_materialInstanceId)
+    if (loadedId.x != materialTypeId || loadedId.y != materialInstanceId)
     {
     {
         return (MaterialParameters)0;
         return (MaterialParameters)0;
     }
     }
 
 
-    return materialInstances.Load<MaterialParameters>(sizeof(MaterialParameters) * ObjectSrg::m_materialInstanceId);
+    return materialInstances.Load<MaterialParameters>(sizeof(MaterialParameters) * materialInstanceId);
+}
+#if PIPELINE_HAS_OBJECT_SRG
+const MaterialParameters GetMaterialParameters()
+{
+    return GetMaterialParameters(ObjectSrg::m_materialTypeId, ObjectSrg::m_materialInstanceId);
 }
 }
+#endif // PIPELINE_HAS_OBJECT_SRG
 
 
 // All MaterialProperties with the type TextureSampler are collected from all active Materials and stored in the SceneMaterialSrg::m_samplers array.
 // All MaterialProperties with the type TextureSampler are collected from all active Materials and stored in the SceneMaterialSrg::m_samplers array.
 // The Shader - Parameter (in the Srg or the Parameter-Buffer) is then the sampler-index.
 // The Shader - Parameter (in the Srg or the Parameter-Buffer) is then the sampler-index.

+ 0 - 17
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/DefaultObjectSrg.azsli

@@ -21,23 +21,6 @@ ShaderResourceGroup ObjectSrg : SRG_PerObject
     int m_materialTypeId;
     int m_materialTypeId;
     int m_materialInstanceId;
     int m_materialInstanceId;
     
     
-    //! Returns the matrix for transforming points from Object Space to World Space.
-    float4x4 GetWorldMatrix()
-    {
-        return SceneSrg::GetObjectToWorldMatrix(m_objectId);
-    }
-
-    //! Returns the inverse-transpose of the world matrix.
-    //! Commonly used to transform normals while supporting non-uniform scale.
-    float3x3 GetWorldMatrixInverseTranspose()
-    {
-        return SceneSrg::GetObjectToWorldInverseTransposeMatrix(m_objectId);
-    }
-
-    float4x4 GetWorldMatrixPrev()
-    {
-        return SceneSrg::GetObjectToWorldMatrixPrev(m_objectId);
-    }
 
 
     ReflectionProbeData m_reflectionProbeData;
     ReflectionProbeData m_reflectionProbeData;
     TextureCube m_reflectionProbeCubeMap;
     TextureCube m_reflectionProbeCubeMap;

+ 3 - 0
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli

@@ -21,6 +21,9 @@
 #include <Atom/Features/PBR/Microfacet/Brdf.azsli>
 #include <Atom/Features/PBR/Microfacet/Brdf.azsli>
 
 
 
 
+#include <Atom/Features/SampleBrdfMap.azsli>
+#include <Atom/Features/GoboTexture.azsli>
+
 // Then define the Diffuse and Specular lighting functions
 // Then define the Diffuse and Specular lighting functions
 real3 GetDiffuseLighting(Surface surface, LightingData lightingData, real3 lightIntensity, real3 dirToLight)
 real3 GetDiffuseLighting(Surface surface, LightingData lightingData, real3 lightIntensity, real3 dirToLight)
 {
 {

+ 2 - 10
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/Ibl.azsli

@@ -135,11 +135,7 @@ void ApplyIBL(Surface surface, inout LightingData lightingData, bool useDiffuseI
                 {
                 {
                     real clearCoatNdotV = saturate(dot(surface.clearCoat.normal, lightingData.dirToCamera[viewIndex]));
                     real clearCoatNdotV = saturate(dot(surface.clearCoat.normal, lightingData.dirToCamera[viewIndex]));
                     clearCoatNdotV = max(clearCoatNdotV, 0.01);  // [GFX TODO][ATOM-4466] This is a current band-aid for specular noise at grazing angles.
                     clearCoatNdotV = max(clearCoatNdotV, 0.01);  // [GFX TODO][ATOM-4466] This is a current band-aid for specular noise at grazing angles.
-                    #ifdef CS_SAMPLERS
-                    real2 clearCoatBrdf = real2(PassSrg::m_brdfMap.SampleLevel(PassSrg::LinearSampler, GetBRDFTexCoords(surface.clearCoat.roughness, clearCoatNdotV), 0).rg);
-                    #else
-                    real2 clearCoatBrdf = real2(PassSrg::m_brdfMap.Sample(PassSrg::LinearSampler, GetBRDFTexCoords(surface.clearCoat.roughness, clearCoatNdotV)).rg);
-                    #endif
+                    real2 clearCoatBrdf = real2(SampleBrdfMap(GetBRDFTexCoords(surface.clearCoat.roughness, clearCoatNdotV)));
 
 
                     // clear coat uses fixed IOR = 1.5 represents polyurethane which is the most common material for gloss clear coat
                     // clear coat uses fixed IOR = 1.5 represents polyurethane which is the most common material for gloss clear coat
                     // coat layer assumed to be dielectric thus don't need multiple scattering compensation
                     // coat layer assumed to be dielectric thus don't need multiple scattering compensation
@@ -157,11 +153,7 @@ void ApplyIBL(Surface surface, inout LightingData lightingData, bool useDiffuseI
 #if ENABLE_DUAL_SPECULAR
 #if ENABLE_DUAL_SPECULAR
                 if(o_enableDualSpecular)
                 if(o_enableDualSpecular)
                 {
                 {
-                    #ifdef CS_SAMPLERS
-                    real2 dualSpecularBrdf = real2(PassSrg::m_brdfMap.SampleLevel(PassSrg::LinearSampler, GetBRDFTexCoords(surface.dualSpecRoughness, lightingData.GetSpecularNdotV(viewIndex)), 0).rg);
-                    #else
-                    real2 dualSpecularBrdf = real2(PassSrg::m_brdfMap.Sample(PassSrg::LinearSampler, GetBRDFTexCoords(surface.dualSpecRoughness, lightingData.GetSpecularNdotV(viewIndex))).rg);
-                    #endif
+                    real2 dualSpecularBrdf = real2(SampleBrdfMap(GetBRDFTexCoords(surface.dualSpecRoughness, lightingData.GetSpecularNdotV(viewIndex))));
                     real3 dualSpecular = GetIblSpecular(surface.position, surface.GetSpecularNormal(), surface.dualSpecF0.xxx, surface.dualSpecRoughness, lightingData.dirToCamera[viewIndex], dualSpecularBrdf, reflectionProbe, reflectionProbeCubemap);
                     real3 dualSpecular = GetIblSpecular(surface.position, surface.GetSpecularNormal(), surface.dualSpecF0.xxx, surface.dualSpecRoughness, lightingData.dirToCamera[viewIndex], dualSpecularBrdf, reflectionProbe, reflectionProbeCubemap);
                     iblSpecular = lerp(iblSpecular, dualSpecular, surface.dualSpecFactor);
                     iblSpecular = lerp(iblSpecular, dualSpecular, surface.dualSpecFactor);
                 }
                 }

+ 1 - 12
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/SimpleSpotLight.azsli

@@ -59,18 +59,7 @@ void ApplySimpleSpotLight(SimpleSpotLight light, Surface surface, inout Lighting
         }
         }
 #endif
 #endif
 
 
-        // apply gobo texture
-        if (light.m_goboTexIndex < ViewSrg::MaxGoboTextureCount)
-        {
-            float4 positionInView = mul(light.m_viewProjectionMatrix, float4(surface.position, 1.0));
-            positionInView /= positionInView.w;
-            float2 goboUv = float2((positionInView.x + 1.0)/2.0, (positionInView.y + 1.0)/2.0);
-            #ifdef CS_SAMPLERS
-            lightIntensity *= ViewSrg::m_goboTextures[light.m_goboTexIndex].SampleLevel(PassSrg::LinearSampler, goboUv, 0);
-            #else
-            lightIntensity *= ViewSrg::m_goboTextures[light.m_goboTexIndex].Sample(PassSrg::LinearSampler, goboUv);
-            #endif
-        }
+        lightIntensity *=  SampleGoboTexture(light.m_goboTexIndex, PassSrg::LinearSampler, light.m_viewProjectionMatrix, surface.position);
 
 
         if (dotWithDirection < cosInnerConeAngle) // in penumbra
         if (dotWithDirection < cosInnerConeAngle) // in penumbra
         {
         {

+ 28 - 23
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/ParallaxMapping.azsli

@@ -55,17 +55,19 @@ DepthResult DepthResultAbsolute(float depth)
 //! The client shader must define this function.
 //! The client shader must define this function.
 //! This allows the client shader to implement special depth map sampling, for example procedurally generating or blending depth maps.
 //! This allows the client shader to implement special depth map sampling, for example procedurally generating or blending depth maps.
 //! In simple cases though, the implementation of GetDepth() can simply call SampleDepthFromHeightmap().
 //! In simple cases though, the implementation of GetDepth() can simply call SampleDepthFromHeightmap().
+//! @param params The MaterialParameters struct, as defined by the material. Passed through unchanged
 //! @param uv the UV coordinates to use for sampling
 //! @param uv the UV coordinates to use for sampling
 //! @param uv_ddx will be set to ddx_fine(uv)
 //! @param uv_ddx will be set to ddx_fine(uv)
 //! @param uv_ddy will be set to ddy_fine(uv)
 //! @param uv_ddy will be set to ddy_fine(uv)
 //! @return see struct DepthResult
 //! @return see struct DepthResult
-DepthResult GetDepth(Texture2D heightmap, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy);
+DepthResult GetDepth(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy);
 
 
 //! Convenience function that can be used to implement GetDepth().
 //! Convenience function that can be used to implement GetDepth().
 //! @return see struct DepthResult. In this case it will always contain a Code::Normalized result. 
 //! @return see struct DepthResult. In this case it will always contain a Code::Normalized result. 
 DepthResult SampleDepthFromHeightmap(Texture2D map, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
 DepthResult SampleDepthFromHeightmap(Texture2D map, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
 {
 {
     DepthResult result;
     DepthResult result;
+    // TODO: there is no guarantee that the heightmap is actually normalized
     result.m_resultCode = DepthResultCode_Normalized;
     result.m_resultCode = DepthResultCode_Normalized;
     result.m_depth = 1.0 - map.SampleGrad(mapSampler, uv, uv_ddx, uv_ddy).r;
     result.m_depth = 1.0 - map.SampleGrad(mapSampler, uv, uv_ddx, uv_ddy).r;
     return result;
     return result;
@@ -79,7 +81,7 @@ DepthResult SampleDepthFromHeightmap(Texture2D map, sampler mapSampler, float2 u
 //! @param uv_ddx must be set to ddx_fine(uv)
 //! @param uv_ddx must be set to ddx_fine(uv)
 //! @param uv_ddy must be set to ddy_fine(uv)
 //! @param uv_ddy must be set to ddy_fine(uv)
 //! @param a depth value in the range [0,1]
 //! @param a depth value in the range [0,1]
-float GetNormalizedDepth(Texture2D heightmap, sampler mapSampler, float startDepth, float stopDepth, float inverseDepthRange, float2 uv, float2 uv_ddx, float2 uv_ddy)
+float GetNormalizedDepth(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float startDepth, float stopDepth, float inverseDepthRange, float2 uv, float2 uv_ddx, float2 uv_ddy)
 {
 {
     // startDepth can be less than 0, representing a displacement above the mesh surface.
     // startDepth can be less than 0, representing a displacement above the mesh surface.
     // But since we don't currently support any vertex displacement, negative depth values would cause various 
     // But since we don't currently support any vertex displacement, negative depth values would cause various 
@@ -88,7 +90,7 @@ float GetNormalizedDepth(Texture2D heightmap, sampler mapSampler, float startDep
 
 
     float normalizedDepth = 0.0;
     float normalizedDepth = 0.0;
 
 
-    DepthResult depthResult = GetDepth(heightmap, mapSampler, uv, uv_ddx, uv_ddy);
+    DepthResult depthResult = GetDepth(params, heightmap, mapSampler, uv, uv_ddx, uv_ddy);
 
 
     if(stopDepth - startDepth > 0.0001)
     if(stopDepth - startDepth > 0.0001)
     {
     {
@@ -107,10 +109,10 @@ float GetNormalizedDepth(Texture2D heightmap, sampler mapSampler, float startDep
     return normalizedDepth;
     return normalizedDepth;
 }
 }
 
 
-float GetNormalizedDepth(Texture2D heightmap, sampler mapSampler, float startDepth, float stopDepth, float2 uv, float2 uv_ddx, float2 uv_ddy)
+float GetNormalizedDepth(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float startDepth, float stopDepth, float2 uv, float2 uv_ddx, float2 uv_ddy)
 {
 {
     float inverseDepthRange = 1.0 / (stopDepth - startDepth);
     float inverseDepthRange = 1.0 / (stopDepth - startDepth);
-    return GetNormalizedDepth(heightmap, mapSampler, startDepth, stopDepth, inverseDepthRange, uv, uv_ddx, uv_ddy);
+    return GetNormalizedDepth(params, heightmap, mapSampler, startDepth, stopDepth, inverseDepthRange, uv, uv_ddx, uv_ddy);
 }
 }
 
 
 void ApplyParallaxClippingHighlight(inout float3 baseColor)
 void ApplyParallaxClippingHighlight(inout float3 baseColor)
@@ -126,13 +128,13 @@ struct ParallaxOffset
 
 
 // dirToCameraTS should be in tangent space and normalized
 // dirToCameraTS should be in tangent space and normalized
 // From Reat-Time Rendering 3rd edition, p.192
 // From Reat-Time Rendering 3rd edition, p.192
-ParallaxOffset BasicParallaxMapping(Texture2D heightmap, sampler mapSampler, float depthFactor, float2 uv, float3 dirToCameraTS)
+ParallaxOffset BasicParallaxMapping(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float depthFactor, float2 uv, float3 dirToCameraTS)
 {
 {
     // the amount to shift
     // the amount to shift
 #ifdef CS_SAMPLERS
 #ifdef CS_SAMPLERS
-    float2 delta = dirToCameraTS.xy * GetNormalizedDepth(heightmap, mapSampler, 0, depthFactor, uv, float2(0, 0), float2(0, 0)) * depthFactor;
+    float2 delta = dirToCameraTS.xy * GetNormalizedDepth(params, heightmap, mapSampler, 0, depthFactor, uv, float2(0, 0), float2(0, 0)) * depthFactor;
 #else
 #else
-    float2 delta = dirToCameraTS.xy * GetNormalizedDepth(heightmap, mapSampler, 0, depthFactor, uv, ddx_fine(uv), ddy_fine(uv)) * depthFactor;
+    float2 delta = dirToCameraTS.xy * GetNormalizedDepth(params, heightmap, mapSampler, 0, depthFactor, uv, ddx_fine(uv), ddy_fine(uv)) * depthFactor;
 #endif
 #endif
 
 
     ParallaxOffset result;
     ParallaxOffset result;
@@ -146,6 +148,7 @@ ParallaxOffset BasicParallaxMapping(Texture2D heightmap, sampler mapSampler, flo
 // Performs ray intersection against a surface with a heightmap.
 // Performs ray intersection against a surface with a heightmap.
 // Adapted from CryEngine shader shadelib.cfi and POM function in https://github.com/a-riccardi/shader-toy
 // Adapted from CryEngine shader shadelib.cfi and POM function in https://github.com/a-riccardi/shader-toy
 // check https://github.com/UPBGE/blender/issues/1009 for more details.
 // check https://github.com/UPBGE/blender/issues/1009 for more details.
+// @param params - The MaterialParameters struct as defined by the Material. Passed through unchanged to GetDepth()
 // @param heightmap - the heightmap texture.
 // @param heightmap - the heightmap texture.
 // @param mapSampler - the sampler for the heightmap texture.
 // @param mapSampler - the sampler for the heightmap texture.
 // @param depthFactor - scales the heightmap in tangent space units (which normally ends up being world units).
 // @param depthFactor - scales the heightmap in tangent space units (which normally ends up being world units).
@@ -155,7 +158,7 @@ ParallaxOffset BasicParallaxMapping(Texture2D heightmap, sampler mapSampler, flo
 // @param dirToLightTS - normalized direction to a light source, in tangent space, for self-shadowing (if enabled via o_parallax_shadow).
 // @param dirToLightTS - normalized direction to a light source, in tangent space, for self-shadowing (if enabled via o_parallax_shadow).
 // @param numSteps - the number of steps to take when marching along the ray searching for intersection.
 // @param numSteps - the number of steps to take when marching along the ray searching for intersection.
 // @param parallaxShadowAttenuation - returns a factor for attenuating a light source, for self-shadowing (if enabled via o_parallax_shadow).
 // @param parallaxShadowAttenuation - returns a factor for attenuating a light source, for self-shadowing (if enabled via o_parallax_shadow).
-ParallaxOffset AdvancedParallaxMapping(Texture2D heightmap, sampler mapSampler, float depthFactor, float depthOffset, float2 uv, float3 dirToCameraTS, float3 dirToLightTS, int numSteps, inout float parallaxShadowAttenuation)
+ParallaxOffset AdvancedParallaxMapping(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float depthFactor, float depthOffset, float2 uv, float3 dirToCameraTS, float3 dirToLightTS, int numSteps, inout float parallaxShadowAttenuation)
 {
 {
     ParallaxOffset result;
     ParallaxOffset result;
     result.m_isClipped = false;
     result.m_isClipped = false;
@@ -185,7 +188,7 @@ ParallaxOffset AdvancedParallaxMapping(Texture2D heightmap, sampler mapSampler,
     float3 parallaxOffset = -dirToCameraTS.xyz * dirToCameraZInverse * depthOffset;
     float3 parallaxOffset = -dirToCameraTS.xyz * dirToCameraZInverse * depthOffset;
     
     
     // Get an initial heightmap sample to start the intersection search, starting at our initial parallaxOffset position.
     // Get an initial heightmap sample to start the intersection search, starting at our initial parallaxOffset position.
-    float currentSample = GetNormalizedDepth(heightmap, mapSampler, depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv);
+    float currentSample = GetNormalizedDepth(params, heightmap, mapSampler, depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv);
     float prevSample;
     float prevSample;
     
     
     // Note that when depthOffset > 0, we could actually narrow the search so that instead of going through the entire [depthSearchStart,depthSearchEnd] range
     // Note that when depthOffset > 0, we could actually narrow the search so that instead of going through the entire [depthSearchStart,depthSearchEnd] range
@@ -199,7 +202,7 @@ ParallaxOffset AdvancedParallaxMapping(Texture2D heightmap, sampler mapSampler,
         parallaxOffset += delta;
         parallaxOffset += delta;
                 
                 
         prevSample = currentSample;
         prevSample = currentSample;
-        currentSample = GetNormalizedDepth(heightmap, mapSampler, depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv);
+        currentSample = GetNormalizedDepth(params, heightmap, mapSampler, depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv);
     }
     }
 
 
     // Depending on the algorithm, we refine the result of the above search
     // Depending on the algorithm, we refine the result of the above search
@@ -239,7 +242,7 @@ ParallaxOffset AdvancedParallaxMapping(Texture2D heightmap, sampler mapSampler,
                     parallaxOffset += reliefDelta * depthSign;
                     parallaxOffset += reliefDelta * depthSign;
                     currentStep += reliefStep * depthSign;
                     currentStep += reliefStep * depthSign;
 
 
-                    currentSample = GetNormalizedDepth(heightmap, mapSampler, depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv);
+                    currentSample = GetNormalizedDepth(params, heightmap, mapSampler, depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv);
                 }
                 }
             }
             }
             break;
             break;
@@ -267,7 +270,7 @@ ParallaxOffset AdvancedParallaxMapping(Texture2D heightmap, sampler mapSampler,
                     parallaxOffset += adjustedDelta;
                     parallaxOffset += adjustedDelta;
                     prevSample = currentSample;
                     prevSample = currentSample;
 
 
-                    currentSample = GetNormalizedDepth(heightmap, mapSampler, depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv);
+                    currentSample = GetNormalizedDepth(params, heightmap, mapSampler, depthSearchStart, depthSearchEnd, inverseDepthFactor, uv + parallaxOffset.xy, ddx_uv, ddy_uv);
                 }
                 }
             }
             }
             break;
             break;
@@ -288,7 +291,7 @@ ParallaxOffset AdvancedParallaxMapping(Texture2D heightmap, sampler mapSampler,
         // The most accurate way to report clipping is to sample the heightmap one last time at the final adjusted UV.
         // The most accurate way to report clipping is to sample the heightmap one last time at the final adjusted UV.
         // (trying to do it based on parallaxOffset.z values just leads to too many edge cases)
         // (trying to do it based on parallaxOffset.z values just leads to too many edge cases)
 
 
-        DepthResult depthResult = GetDepth(heightmap, mapSampler, float2(uv + parallaxOffset.xy), ddx_uv, ddy_uv);
+        DepthResult depthResult = GetDepth(params, heightmap, mapSampler, float2(uv + parallaxOffset.xy), ddx_uv, ddy_uv);
         
         
         if(DepthResultCode_Normalized == depthResult.m_resultCode)
         if(DepthResultCode_Normalized == depthResult.m_resultCode)
         {
         {
@@ -323,7 +326,7 @@ ParallaxOffset AdvancedParallaxMapping(Texture2D heightmap, sampler mapSampler,
             }
             }
 
 
             shadowUV += shadowDelta;
             shadowUV += shadowDelta;
-            currentSample = GetNormalizedDepth(heightmap, mapSampler, depthSearchStart, depthSearchEnd, inverseDepthFactor, shadowUV, ddx_uv, ddy_uv);
+            currentSample = GetNormalizedDepth(params, heightmap, mapSampler, depthSearchStart, depthSearchEnd, inverseDepthFactor, shadowUV, ddx_uv, ddy_uv);
             currentStep -= step;
             currentStep -= step;
         }
         }
 
 
@@ -342,11 +345,11 @@ ParallaxOffset AdvancedParallaxMapping(Texture2D heightmap, sampler mapSampler,
 }
 }
 
 
 // return offset in tangent space
 // return offset in tangent space
-ParallaxOffset CalculateParallaxOffset(Texture2D heightmap, sampler mapSampler, float depthFactor, float depthOffset, float2 uv, float3 dirToCameraTS, float3 dirToLightTS, inout float parallaxShadowAttenuation)
+ParallaxOffset CalculateParallaxOffset(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float depthFactor, float depthOffset, float2 uv, float3 dirToCameraTS, float3 dirToLightTS, inout float parallaxShadowAttenuation)
 {
 {
     if(o_parallax_algorithm == ParallaxAlgorithm::Basic)
     if(o_parallax_algorithm == ParallaxAlgorithm::Basic)
     {
     {
-        return BasicParallaxMapping(heightmap, mapSampler, depthFactor, uv, dirToCameraTS);
+        return BasicParallaxMapping(params, heightmap, mapSampler, depthFactor, uv, dirToCameraTS);
     }
     }
     else
     else
     {
     {
@@ -354,16 +357,16 @@ ParallaxOffset CalculateParallaxOffset(Texture2D heightmap, sampler mapSampler,
         switch(o_parallax_quality)
         switch(o_parallax_quality)
         {
         {
             case ParallaxQuality::Low:
             case ParallaxQuality::Low:
-                parallaxOffset = AdvancedParallaxMapping(heightmap, mapSampler, depthFactor, depthOffset, uv, dirToCameraTS, dirToLightTS, 16, parallaxShadowAttenuation);
+                parallaxOffset = AdvancedParallaxMapping(params, heightmap, mapSampler, depthFactor, depthOffset, uv, dirToCameraTS, dirToLightTS, 16, parallaxShadowAttenuation);
                 break;
                 break;
             case ParallaxQuality::Medium:
             case ParallaxQuality::Medium:
-                parallaxOffset = AdvancedParallaxMapping(heightmap, mapSampler, depthFactor, depthOffset, uv, dirToCameraTS, dirToLightTS, 32, parallaxShadowAttenuation);
+                parallaxOffset = AdvancedParallaxMapping(params, heightmap, mapSampler, depthFactor, depthOffset, uv, dirToCameraTS, dirToLightTS, 32, parallaxShadowAttenuation);
                 break;
                 break;
             case ParallaxQuality::High:
             case ParallaxQuality::High:
-                parallaxOffset = AdvancedParallaxMapping(heightmap, mapSampler, depthFactor, depthOffset, uv, dirToCameraTS, dirToLightTS, 64, parallaxShadowAttenuation);
+                parallaxOffset = AdvancedParallaxMapping(params, heightmap, mapSampler, depthFactor, depthOffset, uv, dirToCameraTS, dirToLightTS, 64, parallaxShadowAttenuation);
                 break;
                 break;
             case ParallaxQuality::Ultra:
             case ParallaxQuality::Ultra:
-                parallaxOffset = AdvancedParallaxMapping(heightmap, mapSampler, depthFactor, depthOffset, uv, dirToCameraTS, dirToLightTS, 128, parallaxShadowAttenuation);
+                parallaxOffset = AdvancedParallaxMapping(params, heightmap, mapSampler, depthFactor, depthOffset, uv, dirToCameraTS, dirToLightTS, 128, parallaxShadowAttenuation);
                 break;
                 break;
         }
         }
         return parallaxOffset;
         return parallaxOffset;
@@ -371,12 +374,14 @@ ParallaxOffset CalculateParallaxOffset(Texture2D heightmap, sampler mapSampler,
 }
 }
 
 
 // Performs ray intersection against a surface with a heightmap, to determine an offset amount required for a parallax effect.
 // Performs ray intersection against a surface with a heightmap, to determine an offset amount required for a parallax effect.
+// @param params - The MaterialParameters - struct as defined by the material. Passed through to GetDepth() unchanged
 // @param depthFactor - scales the heightmap in tangent space units (which normally ends up being world units).
 // @param depthFactor - scales the heightmap in tangent space units (which normally ends up being world units).
 // @param depthOffset - offsets the heighmap up or down in tangent space units (which normally ends up being world units).
 // @param depthOffset - offsets the heighmap up or down in tangent space units (which normally ends up being world units).
 // @param uv - the UV coordinates on the surface, where the search will begin, used to sample the heightmap.
 // @param uv - the UV coordinates on the surface, where the search will begin, used to sample the heightmap.
 // @param dirToCameraTS - normalized direction to the camera, in tangent space.
 // @param dirToCameraTS - normalized direction to the camera, in tangent space.
 // @param dirToLightTS - normalized direction to a light source, in tangent space, for self-shadowing (if enabled via o_parallax_shadow).
 // @param dirToLightTS - normalized direction to a light source, in tangent space, for self-shadowing (if enabled via o_parallax_shadow).
-ParallaxOffset GetParallaxOffset( Texture2D heightmap,
+ParallaxOffset GetParallaxOffset( const MaterialParameters params,
+                                  Texture2D heightmap,
                                   sampler mapSampler,
                                   sampler mapSampler,
                                   float depthFactor, 
                                   float depthFactor, 
                                   float depthOffset,
                                   float depthOffset,
@@ -401,7 +406,7 @@ ParallaxOffset GetParallaxOffset( Texture2D heightmap,
     float4 dirToCameraTransformed = mul(uv3DTransform, float4(dirToCameraTS, 0.0));
     float4 dirToCameraTransformed = mul(uv3DTransform, float4(dirToCameraTS, 0.0));
 
 
     float dummy = 1;
     float dummy = 1;
-    return CalculateParallaxOffset(heightmap, mapSampler, depthFactor, depthOffset, uv, normalize(dirToCameraTransformed.xyz), float3(0,0,0), dummy);
+    return CalculateParallaxOffset(params, heightmap, mapSampler, depthFactor, depthOffset, uv, normalize(dirToCameraTransformed.xyz), float3(0,0,0), dummy);
 }
 }
 
 
 struct PixelDepthOffset
 struct PixelDepthOffset

+ 83 - 0
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Pipeline/Deferred/DeferredPassPipelineCallbacks.azsli

@@ -0,0 +1,83 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+#ifndef VsSystemValues
+#error "VsSystemValues needs to be declared"
+#endif
+
+// ViewSrg and SceneSrg need to be defined fully before this file. We don't really have an ObjectSrg nor a DrawSrg
+
+#if PIPELINE_HAS_OBJECT_SRG
+#error "Deferred Pipelines don't support an ObjectSrg"
+#endif
+
+#if PIPELINE_HAS_DRAW_SRG
+#error "Deferred Pipelines don't support a DrawSrg"
+#endif
+
+#include <Atom/Features/GoboTexture.azsli>
+#include <Atom/Features/LightingChannels.azsli>
+#include <Atom/Features/StreamTangentBitmask.azsli>
+#include <Atom/Features/SampleBrdfMap.azsli>
+
+option bool o_meshInstancingIsEnabled = false;
+rootconstant uint m_rootConstantInstanceDataOffset;
+
+float4x4 GetObjectToWorldMatrix(VsSystemValues SV)
+{
+    if(o_meshInstancingIsEnabled)
+    {
+        return SceneSrg::GetObjectToWorldMatrix(ViewSrg::m_instanceData[m_rootConstantInstanceDataOffset + SV.m_instanceId]);
+    }
+    else
+    {
+        return SceneSrg::GetObjectToWorldMatrix(SV.m_objectId);
+    }
+}
+
+float3x3 GetObjectToWorldMatrixInverseTranspose(VsSystemValues SV)
+{
+    if(o_meshInstancingIsEnabled)
+    {
+        return SceneSrg::GetObjectToWorldInverseTransposeMatrix(ViewSrg::m_instanceData[m_rootConstantInstanceDataOffset + SV.m_instanceId]);
+    }
+    else
+    {
+        return SceneSrg::GetObjectToWorldInverseTransposeMatrix(SV.m_objectId);
+    }
+}
+
+float4x4 GetViewProjectionMatrix(VsSystemValues SV)
+{
+    return ViewSrg::m_viewProjectionMatrix;
+}
+
+#if MATERIALPIPELINE_USES_PREV_VERTEX_POSITION
+float4x4 GetObjectToWorldMatrixPrev(VsSystemValues SV)
+{
+    if(o_meshInstancingIsEnabled)
+    {
+        return SceneSrg::GetObjectToWorldMatrixPrev(ViewSrg::m_instanceData[m_rootConstantInstanceDataOffset + SV.m_instanceId]);
+    }
+    else
+    {
+        return SceneSrg::GetObjectToWorldMatrixPrev(SV.m_objectId);
+    }
+}
+
+float4x4 GetViewProjectionPrevMatrix(VsSystemValues SV)
+{
+    return ViewSrg::m_viewProjectionPrevMatrix;
+}
+#endif // MATERIALPIPELINE_USES_PREV_VERTEX_POSITION
+
+
+
+

+ 192 - 0
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Pipeline/Deferred/DeferredPassVertexData.azsli

@@ -0,0 +1,192 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+// This #define magic lets you use the VsInput & VsOutput classes in this file without making it the final VsInput & VsOutput
+// used in your shader. Simply #define VsInput & VsOutput to your custom definitions before including this file
+//
+
+#ifndef VsInput
+#define VsInput         VsInput_DeferredPass
+#endif
+
+#ifndef VsSystemValues
+#define VsSystemValues  VsSystemValues_DeferredPass
+#endif
+
+#ifndef VsOutput
+#define VsOutput        VsOutput_DeferredPass
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_POSITION
+#define MATERIAL_USES_VERTEX_POSITION 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_POSITIONWS
+#define MATERIAL_USES_VERTEX_POSITIONWS 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_LOCALPOSITION
+#define MATERIAL_USES_VERTEX_LOCALPOSITION 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_PREV_POSITION
+#define MATERIAL_USES_VERTEX_PREV_POSITION 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_NORMAL
+#define MATERIAL_USES_VERTEX_NORMAL 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_TANGENT
+#define MATERIAL_USES_VERTEX_TANGENT 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_BITANGENT
+#define MATERIAL_USES_VERTEX_BITANGENT 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_UV
+#define MATERIAL_USES_VERTEX_UV 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_DETAIL_UV
+#define MATERIAL_USES_VERTEX_DETAIL_UV 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_COLOR
+#define MATERIAL_USES_VERTEX_COLOR 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_BLENDMASK 
+#define MATERIAL_USES_VERTEX_BLENDMASK 0
+#endif
+
+#if MATERIAL_USES_VERTEX_COLOR && MATERIAL_USES_VERTEX_BLENDMASK
+#error("Only one of MATERIAL_USES_VERTEX_BLENDMASK and MATERIAL_USES_VERTEX_COLOR can be active at once")
+#endif
+
+
+// These options indicate whether the vertex input struct's "m_optional_xxx" is bound. If false, it is not safe to read from m_optional_xxx.
+// This option gets set automatically by the system at runtime; there is a soft naming convention that associates it with m_optional_xx.
+// (search "m_optional_" in ShaderVariantAssetBuilder for details on the naming convention).
+// [GFX TODO][ATOM-14475]: Come up with a more elegant way to associate the isBound flag with the input stream.
+
+#if MATERIAL_USES_VERTEX_COLOR
+    option bool o_color0_isBound = false;
+#endif
+#if MATERIAL_USES_VERTEX_BLENDMASK
+    option bool o_blendMask_isBound = false;
+#endif
+#if MATERIAL_USES_VERTEX_PREV_POSITION
+    option bool o_prevPosition_isBound = false;
+#endif
+
+// we are running in a FullscreenTriangle-Pass, so our VertexShader - Input can't come from the Input-Assembly, 
+// and cant't have semantics
+struct VsInput_DeferredPass
+{
+    // Base fields (required by the template azsli file)...
+#if MATERIAL_USES_VERTEX_POSITION
+    float3 position;
+#endif
+
+#if MATERIAL_USES_VERTEX_NORMAL
+    float3 normal;
+#endif
+#if MATERIAL_USES_VERTEX_TANGENT
+    float4 tangent;
+#endif
+#if MATERIAL_USES_VERTEX_BITANGENT
+    float3 bitangent;
+#endif
+
+#if MATERIAL_USES_VERTEX_UV
+    float2 uv0;
+    float2 uv1;
+#endif
+
+#if MATERIAL_USES_VERTEX_PREV_POSITION
+    float3 m_optional_prevPosition;
+#endif
+
+#if MATERIAL_USES_VERTEX_COLOR
+    // 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_color0_isBound, which will be set to true whenever m_optional_color0 is available.
+    float4 m_optional_color0;
+#endif
+
+#if MATERIAL_USES_VERTEX_BLENDMASK
+    // 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.
+    float4 m_optional_blendMask;
+#endif
+
+};
+
+// We don't have an Object or Draw-SRG, so we place what we need in this struct
+struct VsSystemValues_DeferredPass
+{
+    uint m_instanceId;
+    uint m_lightingChannelMask;
+    uint m_objectId;
+    int m_materialTypeId;
+    int m_materialInstanceId;
+    uint m_uvStreamTangentBitmask;
+};
+
+// we are running in a FullscreenTriangle-Pass, so our VertexShader-Output doesn't need semantics
+struct VsOutput_DeferredPass
+{
+    // Base fields (required by the template azsli file)...
+#if MATERIAL_USES_VERTEX_POSITION
+    float4 position;
+#endif
+
+#if MATERIAL_USES_VERTEX_NORMAL
+    float3 normal;
+#endif 
+
+#if MATERIAL_USES_VERTEX_TANGENT
+    float4 tangent;
+#endif
+
+#if MATERIAL_USES_VERTEX_BITANGENT
+    float3 bitangent;
+#endif
+
+#if MATERIAL_USES_VERTEX_UV
+    float2 uvs[UvSetCount];
+#endif
+
+#if MATERIAL_USES_VERTEX_DETAIL_UV
+    float2 detailUvs[UvSetCount];
+#endif
+
+#if MATERIAL_USES_VERTEX_POSITIONWS
+    float3 worldPosition;
+#endif
+
+#if MATERIAL_USES_VERTEX_LOCALPOSITION
+    float3 localPosition;
+#endif
+
+#if MATERIAL_USES_VERTEX_PREV_POSITION
+    float3 worldPosPrev;
+#endif
+
+#if MATERIAL_USES_VERTEX_COLOR
+    float4 color0;
+#endif
+
+#if MATERIAL_USES_VERTEX_BLENDMASK
+    float4 blendFactors;
+#endif
+
+};

+ 78 - 0
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Pipeline/Forward/ForwardPassPipelineCallbacks.azsli

@@ -0,0 +1,78 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+#ifndef VsSystemValues
+#error "VsSystemValues needs to be declared"
+#endif
+
+// DrawSrg, ObjectSrg, ViewSrg and SceneSrg need to be defined fully before this file 
+
+#ifndef PIPELINE_HAS_PASS_SRG
+// assume we have a pass-srg by default
+#define PIPELINE_HAS_PASS_SRG 1
+#endif
+
+#include <Atom/Features/GoboTexture.azsli>
+#include <Atom/Features/LightingChannels.azsli>
+#include <Atom/Features/StreamTangentBitmask.azsli>
+#include <Atom/Features/SampleBrdfMap.azsli>
+
+option bool o_meshInstancingIsEnabled = false;
+rootconstant uint m_rootConstantInstanceDataOffset;
+
+float4x4 GetObjectToWorldMatrix(VsSystemValues SV)
+{
+    if(o_meshInstancingIsEnabled)
+    {
+        return SceneSrg::GetObjectToWorldMatrix(ViewSrg::m_instanceData[m_rootConstantInstanceDataOffset + SV.m_instanceId]);
+    }
+    else
+    {
+        return SceneSrg::GetObjectToWorldMatrix(ObjectSrg::m_objectId);
+    }
+}
+
+float3x3 GetObjectToWorldMatrixInverseTranspose(VsSystemValues SV)
+{
+    if(o_meshInstancingIsEnabled)
+    {
+        return SceneSrg::GetObjectToWorldInverseTransposeMatrix(ViewSrg::m_instanceData[m_rootConstantInstanceDataOffset + SV.m_instanceId]);
+    }
+    else
+    {
+        return SceneSrg::GetObjectToWorldInverseTransposeMatrix(ObjectSrg::m_objectId);
+    }
+}
+
+float4x4 GetViewProjectionMatrix(VsSystemValues SV)
+{
+    return ViewSrg::m_viewProjectionMatrix;
+}
+
+#if MATERIALPIPELINE_USES_PREV_VERTEX_POSITION
+float4x4 GetObjectToWorldMatrixPrev(VsSystemValues SV)
+{
+    if(o_meshInstancingIsEnabled)
+    {
+        return SceneSrg::GetObjectToWorldMatrixPrev(ViewSrg::m_instanceData[m_rootConstantInstanceDataOffset + SV.m_instanceId]);
+    }
+    else
+    {
+        return SceneSrg::GetObjectToWorldMatrixPrev(ObjectSrg::m_objectId);
+    }
+}
+
+float4x4 GetViewProjectionPrevMatrix(VsSystemValues SV)
+{
+    return ViewSrg::m_viewProjectionPrevMatrix;
+}
+#endif // MATERIALPIPELINE_USES_PREV_VERTEX_POSITION
+
+

+ 4 - 0
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli

@@ -50,3 +50,7 @@ ShaderResourceGroup PassSrg : SRG_PerPass
     // And the shaders can calculate linear depth themselves
     // And the shaders can calculate linear depth themselves
     uint m_isOriginalDepth;
     uint m_isOriginalDepth;
 }
 }
+
+
+
+

+ 191 - 0
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Pipeline/Forward/ForwardPassVertexData.azsli

@@ -0,0 +1,191 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+// This #define magic lets you use the VsInput & VsOutput classes in this file without making it the final VsInput & VsOutput
+// used in your shader. Simply #define VsInput & VsOutput to your custom definitions before including this file
+//
+
+
+
+#ifndef VsInput
+#define VsInput         VsInput_ForwardPass
+#endif
+
+#ifndef VsSystemValues
+#define VsSystemValues  VsSystemValues_ForwardPass
+#endif
+
+#ifndef VsOutput
+#define VsOutput        VsOutput_ForwardPass
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_POSITION
+#define MATERIAL_USES_VERTEX_POSITION 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_POSITIONWS
+#define MATERIAL_USES_VERTEX_POSITIONWS 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_LOCALPOSITION
+#define MATERIAL_USES_VERTEX_LOCALPOSITION 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_PREV_POSITION
+#define MATERIAL_USES_VERTEX_PREV_POSITION 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_NORMAL
+#define MATERIAL_USES_VERTEX_NORMAL 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_TANGENT
+#define MATERIAL_USES_VERTEX_TANGENT 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_BITANGENT
+#define MATERIAL_USES_VERTEX_BITANGENT 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_UV
+#define MATERIAL_USES_VERTEX_UV 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_DETAIL_UV
+#define MATERIAL_USES_VERTEX_DETAIL_UV 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_COLOR
+#define MATERIAL_USES_VERTEX_COLOR 0
+#endif
+
+#ifndef MATERIAL_USES_VERTEX_BLENDMASK 
+#define MATERIAL_USES_VERTEX_BLENDMASK 0
+#endif
+
+#if MATERIAL_USES_VERTEX_COLOR && MATERIAL_USES_VERTEX_BLENDMASK
+#error("Only one of MATERIAL_USES_VERTEX_BLENDMASK and MATERIAL_USES_VERTEX_COLOR can be active at once")
+#endif
+
+
+// These options indicate whether the vertex input struct's "m_optional_xxx" is bound. If false, it is not safe to read from m_optional_xxx.
+// This option gets set automatically by the system at runtime; there is a soft naming convention that associates it with m_optional_xx.
+// (search "m_optional_" in ShaderVariantAssetBuilder for details on the naming convention).
+// [GFX TODO][ATOM-14475]: Come up with a more elegant way to associate the isBound flag with the input stream.
+
+#if MATERIAL_USES_VERTEX_COLOR
+    option bool o_color0_isBound = false;
+#endif
+#if MATERIAL_USES_VERTEX_BLENDMASK
+    option bool o_blendMask_isBound = false;
+#endif
+#if MATERIAL_USES_VERTEX_PREV_POSITION
+    option bool o_prevPosition_isBound = false;
+#endif
+
+
+struct VsInput_ForwardPass
+{
+    // Base fields (required by the template azsli file)...
+#if MATERIAL_USES_VERTEX_POSITION
+    float3 position : POSITION;
+#endif
+
+#if MATERIAL_USES_VERTEX_NORMAL
+    float3 normal : NORMAL;
+#endif
+#if MATERIAL_USES_VERTEX_TANGENT
+    float4 tangent : TANGENT;
+#endif
+#if MATERIAL_USES_VERTEX_BITANGENT
+    float3 bitangent : BITANGENT;
+#endif
+
+#if MATERIAL_USES_VERTEX_UV
+    float2 uv0 : UV0;
+    float2 uv1 : UV1;
+#endif
+
+#if MATERIAL_USES_VERTEX_PREV_POSITION
+    float3 m_optional_prevPosition : POSITIONT;
+#endif
+
+#if MATERIAL_USES_VERTEX_COLOR
+    // 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_color0_isBound, which will be set to true whenever m_optional_color0 is available.
+    float4 m_optional_color0 : COLOR0;
+#endif
+
+#if MATERIAL_USES_VERTEX_BLENDMASK
+    // 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.
+    float4 m_optional_blendMask : COLOR0;
+#endif
+
+};
+
+struct VsSystemValues_ForwardPass
+{
+    uint m_instanceId;
+};
+
+struct VsOutput_ForwardPass
+{
+    // Base fields (required by the template azsli file)...
+    // "centroid" is needed for SV_Depth to compile
+#if MATERIAL_USES_VERTEX_POSITION
+    precise linear centroid 
+    float4 position : SV_Position;
+#endif
+
+#if MATERIAL_USES_VERTEX_NORMAL
+    float3 normal: NORMAL;
+#endif 
+
+#if MATERIAL_USES_VERTEX_TANGENT
+    float4 tangent : TANGENT;
+#endif
+
+#if MATERIAL_USES_VERTEX_BITANGENT
+    float3 bitangent : BITANGENT;
+#endif
+
+#if MATERIAL_USES_VERTEX_UV
+    float2 uvs[UvSetCount] : UV0;
+#endif
+
+#if MATERIAL_USES_VERTEX_DETAIL_UV
+    float2 detailUvs[UvSetCount] : UV2;
+#endif
+
+#if MATERIAL_USES_VERTEX_POSITIONWS
+    float3 worldPosition : UV4;
+#endif
+
+#if MATERIAL_USES_VERTEX_LOCALPOSITION
+    float3 localPosition: UV5;
+#endif
+
+#if MATERIAL_USES_VERTEX_PREV_POSITION
+    float3 worldPosPrev: UV6;
+#endif
+
+#if MATERIAL_USES_VERTEX_COLOR
+    float4 color0 : UV7;
+#endif
+
+#if MATERIAL_USES_VERTEX_BLENDMASK
+    float4 blendFactors: UV8;
+#endif
+
+    // instanceId is only required for InstancedRendering with the ForwardPass
+    uint m_instanceId : SV_InstanceID;
+
+};

+ 31 - 0
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/SampleBrdfMap.azsli

@@ -0,0 +1,31 @@
+/*
+ * 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
+ *
+ */
+#pragma once
+
+#ifndef PIPELINE_HAS_PASS_SRG
+// assume we have a pass-srg by default
+#define PIPELINE_HAS_PASS_SRG 1
+#endif 
+
+#if PIPELINE_HAS_PASS_SRG
+float2 SampleBrdfMap(float2 brdfUV)
+{
+#ifdef CS_SAMPLERS
+    return PassSrg::m_brdfMap.SampleLevel(PassSrg::LinearSampler, brdfUV, 0).rg;
+#else
+    return PassSrg::m_brdfMap.Sample(PassSrg::LinearSampler, brdfUV).rg;
+#endif // CS_SAMPLERS
+}
+#else
+float2 SampleBrdfMap(float2 brdfUV)
+{
+    // TODO: We currently always need a Pass-Srg if we want the BrdfMap
+    return float2(0, 0);
+}
+#endif // PIPELINE_HAS_PASS_SRG
+

+ 0 - 19
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Skin/SkinObjectSrg.azsli

@@ -8,7 +8,6 @@
 
 
 #pragma once
 #pragma once
 
 
-#include <Atom/Features/SrgSemantics.azsli>
 #include <Atom/Features/PBR/Lights/ReflectionProbeData.azsli>
 #include <Atom/Features/PBR/Lights/ReflectionProbeData.azsli>
 
 
 #ifndef MATERIAL_PIPELINE_OBJECT_SRG_MEMBERS
 #ifndef MATERIAL_PIPELINE_OBJECT_SRG_MEMBERS
@@ -21,24 +20,6 @@ ShaderResourceGroup ObjectSrg : SRG_PerObject
     int m_materialTypeId;
     int m_materialTypeId;
     int m_materialInstanceId;
     int m_materialInstanceId;
 
 
-    //! Returns the matrix for transforming points from Object Space to World Space.
-    float4x4 GetWorldMatrix()
-    {
-        return SceneSrg::GetObjectToWorldMatrix(m_objectId);
-    }
-
-    //! Returns the inverse-transpose of the world matrix.
-    //! Commonly used to transform normals while supporting non-uniform scale.
-    float3x3 GetWorldMatrixInverseTranspose()
-    {
-        return SceneSrg::GetObjectToWorldInverseTransposeMatrix(m_objectId);
-    }
-
-    float4x4 GetWorldMatrixPrev()
-    {
-        return SceneSrg::GetObjectToWorldMatrixPrev(m_objectId);
-    }
-
     uint m_wrinkle_mask_count;
     uint m_wrinkle_mask_count;
     float4 m_wrinkle_mask_weights[4];
     float4 m_wrinkle_mask_weights[4];
     Texture2D m_wrinkle_masks[16];
     Texture2D m_wrinkle_masks[16];

+ 26 - 0
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/StreamTangentBitmask.azsli

@@ -0,0 +1,26 @@
+/*
+ * 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
+ *
+ */
+#pragma once
+
+
+#ifndef PIPELINE_HAS_DRAW_SRG
+// assume we have an object-srg by default
+#define PIPELINE_HAS_DRAW_SRG 1
+#endif 
+
+#if PIPELINE_HAS_DRAW_SRG
+uint HasTangentForUvChannel(VsSystemValues SV, uint uvIndex)
+{
+    return (DrawSrg::m_uvStreamTangentBitmask >> (4 * uvIndex)) & 0xF;
+}
+#else 
+uint HasTangentForUvChannel(VsSystemValues SV, uint uvIndex)
+{
+    return (SV.m_uvStreamTangentBitmask >> (4 * uvIndex)) & 0xF;
+}
+#endif

+ 0 - 24
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/VertexUtility.azsli

@@ -1,24 +0,0 @@
-/*
- * 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
- *
- */
-
-#pragma once
-
-#include <viewsrg_all.srgi>
-#include <Atom/Features/InstancedTransforms.azsli>
-
-// Helper functions for doing common transformations.
-float3 LocalSpaceToWorldSpace(float3 position, uint instanceId)
-{
-    return mul(GetObjectToWorldMatrix(instanceId), float4(position, 1.0)).xyz;
-}
-
-float4 WorldSpaceToClipSpace(float3 position)
-{
-    return mul(ViewSrg::m_viewProjectionMatrix, float4(position, 1.0));
-}
-

+ 33 - 0
Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/WrinkleMask.azsli

@@ -0,0 +1,33 @@
+/*
+ * 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
+ *
+ */
+#pragma once
+
+uint GetWrinkleMaskCount(VsSystemValues SV)
+{
+    return ObjectSrg::m_wrinkle_mask_count;
+}
+real4 SampleWrinkleMask(VsSystemValues SV, sampler textureSampler, uint wrinkleMaskIndex, float2 wrinkleMaskUv, float4 uvDxDy, bool customDerivatives)
+{
+    if (customDerivatives)
+    {
+        return real4(ObjectSrg::m_wrinkle_masks[wrinkleMaskIndex].SampleGrad(textureSampler, wrinkleMaskUv, uvDxDy.xy, uvDxDy.zw));
+    }
+    else
+    {
+#ifdef CS_SAMPLERS
+        return real4(ObjectSrg::m_wrinkle_masks[wrinkleMaskIndex].SampleLevel(textureSampler, wrinkleMaskUv, 0));
+#else
+        return real4(ObjectSrg::m_wrinkle_masks[wrinkleMaskIndex].Sample(textureSampler, wrinkleMaskUv));
+#endif
+    }
+}
+real GetWrinkleMaskWeight(VsSystemValues SV, uint wrinkleMaskIndex)
+{
+    return ObjectSrg::GetWrinkleMaskWeight(wrinkleMaskIndex);
+}
+

+ 1 - 5
Gems/Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_LightingData.azsli

@@ -97,11 +97,7 @@ void LightingData_BasePBR::Init(float3 positionWS, real3 specularNormal, real ro
 
 
         // sample BRDF map (indexed by smoothness values rather than roughness)
         // sample BRDF map (indexed by smoothness values rather than roughness)
         float2 brdfUV = float2(NdotV[i], (1.0 - roughnessLinear));
         float2 brdfUV = float2(NdotV[i], (1.0 - roughnessLinear));
-    #ifdef CS_SAMPLERS
-        brdf[i] = real2(PassSrg::m_brdfMap.SampleLevel(PassSrg::LinearSampler, brdfUV, 0).rg);
-    #else
-        brdf[i] = real2(PassSrg::m_brdfMap.Sample(PassSrg::LinearSampler, brdfUV).rg);
-    #endif
+        brdf[i] = real2(SampleBrdfMap(brdfUV));
     }
     }
 }
 }
 
 

+ 0 - 1
Gems/Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_MaterialInputs.azsli

@@ -14,5 +14,4 @@
 #include "../MaterialInputs/MetallicInput.azsli"
 #include "../MaterialInputs/MetallicInput.azsli"
 #include "../MaterialInputs/SpecularInput.azsli"
 #include "../MaterialInputs/SpecularInput.azsli"
 #include "../MaterialInputs/NormalInput.azsli"
 #include "../MaterialInputs/NormalInput.azsli"
-#include "../MaterialInputs/UvSetCount.azsli"
 #include "../MaterialInputs/SilhouetteBlockerInput.azsli"
 #include "../MaterialInputs/SilhouetteBlockerInput.azsli"

+ 6 - 5
Gems/Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_PixelGeometryEval.azsli

@@ -16,9 +16,9 @@
 #endif
 #endif
 
 
 #include "../MaterialFunctions/EvaluateTangentFrame.azsli"
 #include "../MaterialFunctions/EvaluateTangentFrame.azsli"
-#include <Atom/Features/InstancedTransforms.azsli>
 
 
 PixelGeometryData EvaluatePixelGeometry_BasePBR(
 PixelGeometryData EvaluatePixelGeometry_BasePBR(
+    VsSystemValues SV,
     const MaterialParameters params,
     const MaterialParameters params,
     float3 positionWS,
     float3 positionWS,
     real3 normalWS,
     real3 normalWS,
@@ -39,7 +39,7 @@ PixelGeometryData EvaluatePixelGeometry_BasePBR(
     {
     {
         for (int i = 0; i != UvSetCount; ++i)
         for (int i = 0; i != UvSetCount; ++i)
         {
         {
-            EvaluateTangentFrame(geoData.vertexNormal, positionWS, isFrontFace, uvs[i], i,
+            EvaluateTangentFrame(SV, geoData.vertexNormal, positionWS, isFrontFace, uvs[i], i,
                 tangentWS, bitangentWS, geoData.tangents[i], geoData.bitangents[i]);
                 tangentWS, bitangentWS, geoData.tangents[i], geoData.bitangents[i]);
         }
         }
     }
     }
@@ -47,15 +47,16 @@ PixelGeometryData EvaluatePixelGeometry_BasePBR(
     return geoData;
     return geoData;
 }
 }
 
 
-PixelGeometryData EvaluatePixelGeometry_BasePBR(VsOutput IN, bool isFrontFace, const MaterialParameters params)
+PixelGeometryData EvaluatePixelGeometry_BasePBR(VsOutput IN, VsSystemValues SV, bool isFrontFace, const MaterialParameters params)
 {
 {
-    real4x4 objectToWorld = real4x4(GetObjectToWorldMatrix(IN.m_instanceId));
-    real3x3 objectToWorldIT = real3x3(GetObjectToWorldMatrixInverseTranspose(IN.m_instanceId));
+    real4x4 objectToWorld = real4x4(GetObjectToWorldMatrix(SV));
+    real3x3 objectToWorldIT = real3x3(GetObjectToWorldMatrixInverseTranspose(SV));
 
 
     real3 normalWS, tangentWS, bitangentWS;
     real3 normalWS, tangentWS, bitangentWS;
     ConstructTBN(real3(IN.normal), real4(IN.tangent), objectToWorld, objectToWorldIT, normalWS, tangentWS, bitangentWS);
     ConstructTBN(real3(IN.normal), real4(IN.tangent), objectToWorld, objectToWorldIT, normalWS, tangentWS, bitangentWS);
 
 
     return EvaluatePixelGeometry_BasePBR(
     return EvaluatePixelGeometry_BasePBR(
+        SV,
         params,
         params,
         IN.worldPosition,
         IN.worldPosition,
         normalWS,
         normalWS,

+ 8 - 66
Gems/Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexData.azsli

@@ -8,70 +8,12 @@
 
 
 #pragma once
 #pragma once
 
 
-// This #define magic lets you use the VsInput & VsOutput classes in this file without making it the final VsInput & VsOutput
-// used in your shader. Simply #define VsInput & VsOutput to your custom definitions before including this file
-//
-#ifndef VsInput
-#define VsInput         VsInput_BasePBR
-#endif
+// by default the Vertex-Data is empty, so enable the parts we need
+#define MATERIAL_USES_VERTEX_POSITION 1
+#define MATERIAL_USES_VERTEX_POSITIONWS 1
+#define MATERIAL_USES_VERTEX_LOCALPOSITION 1
+#define MATERIAL_USES_VERTEX_NORMAL 1
+#define MATERIAL_USES_VERTEX_TANGENT 1
+#define MATERIAL_USES_VERTEX_UV 1
+#define MATERIAL_USES_VERTEX_COLOR 1
 
 
-#ifndef VsSystemValues
-#define VsSystemValues  VsSystemValues_BasePBR
-#endif
-
-#ifndef VsOutput
-#define VsOutput        VsOutput_BasePBR
-#endif
-
-#ifndef ENABLE_VERTEX_COLOR
-#define ENABLE_VERTEX_COLOR 0
-#endif
-
-#if ENABLE_VERTEX_COLOR
-option bool o_color0_isBound = false;
-#endif
-
-struct VsInput_BasePBR
-{
-    // Base fields (required by the template azsli file)...
-    float3 position : POSITION;
-    float3 normal : NORMAL;
-    float4 tangent : TANGENT;
-    // Bitangent is temporarily added back to fix the eye material screenshot test.
-    float3 bitangent : BITANGENT;
-
-    // Extended fields (only referenced in this azsl file)...
-    float2 uv0 : UV0;
-    float2 uv1 : UV1;
-
-#if ENABLE_VERTEX_COLOR
-    // 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_color0_isBound, which will be set to true whenever o_color0_isBound is available.
-    float4 m_optional_color0 : COLOR0;
-#endif
-};
-
-struct VsSystemValues_BasePBR
-{
-    uint m_instanceId;
-};
-
-struct VsOutput_BasePBR
-{
-    // Base fields (required by the template azsli file)...
-    // "centroid" is needed for SV_Depth to compile
-    precise linear centroid 
-    float4 position : SV_Position;
-    float3 normal: NORMAL;
-    float4 tangent : TANGENT;
-    float3 worldPosition : UV0;
-
-    // Extended fields (only referenced in this azsl file)...
-    float2 uvs[UvSetCount] : UV1;
-    uint m_instanceId : SV_InstanceID;
-
-#if ENABLE_VERTEX_COLOR
-    // Optional
-    float4 color0 : UV7; // Using UV7 just to leave some room for non optional attributes
-#endif
-};

+ 24 - 18
Gems/Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexEval.azsli

@@ -8,10 +8,6 @@
 
 
 #pragma once
 #pragma once
 
 
-#ifndef ENABLE_VERTEX_COLOR
-#define ENABLE_VERTEX_COLOR 0
-#endif
-
 // This #define magic allows you to use the EvaluateVertexGeometry function in this file without making it the final
 // This #define magic allows you to use the EvaluateVertexGeometry function in this file without making it the final
 // EvaluateVertexGeometry used in your shader. Simply #define EvaluateVertexGeometry before including this file
 // EvaluateVertexGeometry used in your shader. Simply #define EvaluateVertexGeometry before including this file
 //
 //
@@ -21,7 +17,6 @@
 
 
 #include <viewsrg_all.srgi>
 #include <viewsrg_all.srgi>
 #include <Atom/RPI/TangentSpace.azsli>
 #include <Atom/RPI/TangentSpace.azsli>
-#include <Atom/Features/InstancedTransforms.azsli>
 
 
 VsOutput EvaluateVertexGeometry_BasePBR(
 VsOutput EvaluateVertexGeometry_BasePBR(
     const MaterialParameters params,
     const MaterialParameters params,
@@ -30,25 +25,38 @@ VsOutput EvaluateVertexGeometry_BasePBR(
     float4 tangent,
     float4 tangent,
     float2 uv0,
     float2 uv0,
     float2 uv1,
     float2 uv1,
-    uint instanceId,
+    VsSystemValues SV,
     bool useVertexColor0,
     bool useVertexColor0,
     float4 color0)
     float4 color0)
 {
 {
     VsOutput output;
     VsOutput output;
 
 
-    float4x4 objectToWorld = GetObjectToWorldMatrix(instanceId);
+
+#if MATERIAL_USES_VERTEX_POSITION
+    float4x4 objectToWorld = GetObjectToWorldMatrix(SV);
     float4 worldPosition = mul(objectToWorld, float4(position, 1.0));
     float4 worldPosition = mul(objectToWorld, float4(position, 1.0));
+    float4x4 viewProjectionMatrix = GetViewProjectionMatrix(SV);
+    output.position = mul(viewProjectionMatrix, worldPosition);
+#if MATERIAL_USES_VERTEX_POSITIONWS
     output.worldPosition = worldPosition.xyz;
     output.worldPosition = worldPosition.xyz;
-    output.position = mul(ViewSrg::m_viewProjectionMatrix, worldPosition);
+#endif // MATERIAL_USES_VERTEX_POSITIONWS
+#endif // MATERIAL_USES_VERTEX_POSITION
 
 
+#if MATERIAL_USES_VERTEX_UV
     // By design, only UV0 is allowed to apply transforms.
     // By design, only UV0 is allowed to apply transforms.
     output.uvs[0] = mul(params.m_uvMatrix, float3(uv0, 1.0)).xy;
     output.uvs[0] = mul(params.m_uvMatrix, float3(uv0, 1.0)).xy;
     output.uvs[1] = uv1;
     output.uvs[1] = uv1;
+#endif // MATERIAL_USES_VERTEX_UV
 
 
+#if MATERIAL_USES_VERTEX_NORMAL
     output.normal = normal;
     output.normal = normal;
+#endif // MATERIAL_USES_VERTEX_NORMAL
+
+#if MATERIAL_USES_VERTEX_TANGENT
     output.tangent = tangent;
     output.tangent = tangent;
+#endif // MATERIAL_USES_VERTEX_TANGENT
 
 
-#if ENABLE_VERTEX_COLOR
+#if MATERIAL_USES_VERTEX_COLOR
     if(useVertexColor0)
     if(useVertexColor0)
     {
     {
         output.color0 =  color0;
         output.color0 =  color0;
@@ -57,18 +65,13 @@ VsOutput EvaluateVertexGeometry_BasePBR(
     {
     {
         output.color0 = float4(1,1,1,1);
         output.color0 = float4(1,1,1,1);
     }
     }
-#endif
-
-    // Set the instanceId on the output so the pixel shader can use it
-    // since you can't use SV_InstanceID for both a vertex and a pixel shader at the same time
-    output.m_instanceId = instanceId;
-
+#endif // MATERIAL_USES_VERTEX_COLOR
     return output;
     return output;
 }
 }
 
 
 void GetVertexColor(VsInput IN, out float4 color, out bool useVertexColor)
 void GetVertexColor(VsInput IN, out float4 color, out bool useVertexColor)
 {
 {
-#if ENABLE_VERTEX_COLOR
+#if MATERIAL_USES_VERTEX_COLOR
     color = IN.m_optional_color0;
     color = IN.m_optional_color0;
     useVertexColor = o_color0_isBound;
     useVertexColor = o_color0_isBound;
 #else
 #else
@@ -90,7 +93,7 @@ VsOutput EvaluateVertexGeometry_BasePBR(VsInput IN, VsSystemValues SV, const Mat
         IN.tangent,
         IN.tangent,
         IN.uv0,
         IN.uv0,
         IN.uv1,
         IN.uv1,
-        SV.m_instanceId,
+        SV,
         useVertexColor0,
         useVertexColor0,
         color0);
         color0);
 }
 }
@@ -104,6 +107,9 @@ VsOutput EvaluateVertexGeometry_BasePBR(
     float2 uv1,
     float2 uv1,
     uint instanceId)
     uint instanceId)
 {
 {
+    VsSystemValues SV;
+    SV.m_instanceId = instanceId;
+
     return EvaluateVertexGeometry_BasePBR(
     return EvaluateVertexGeometry_BasePBR(
         params,
         params,
         position,
         position,
@@ -111,7 +117,7 @@ VsOutput EvaluateVertexGeometry_BasePBR(
         tangent,
         tangent,
         uv0,
         uv0,
         uv1,
         uv1,
-        instanceId,
+        SV,
         false,
         false,
         float4(1.0f, 1.0f, 1.0f, 1.0f));
         float4(1.0f, 1.0f, 1.0f, 1.0f));
 }
 }

+ 4 - 48
Gems/Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexData.azsli

@@ -8,55 +8,11 @@
 
 
 #pragma once
 #pragma once
 
 
-#ifndef VsInput
-#define VsInput         VsInput_DepthCommon
-#endif
-
-#ifndef VsSystemValues
-#define VsSystemValues  VsSystemValues_DepthCommon
-#endif
-
-#ifndef VsOutput
-#define VsOutput        VsOutput_DepthCommon
-#endif
-
-struct VsInput_DepthCommon
-{
-    float3 m_position : POSITION;
-    
+// by default the Vertex-Data is empty, so enable the parts we need
+#define MATERIAL_USES_VERTEX_POSITION 1
+#define MATERIAL_USES_VERTEX_POSITIONWS 1
 #if MATERIALPIPELINE_USES_PREV_VERTEX_POSITION
 #if MATERIALPIPELINE_USES_PREV_VERTEX_POSITION
-    // 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_prevPosition_isBound, which will be set to true whenever m_optional_prevPosition is available.
-    // (search "m_optional_" in ShaderVariantAssetBuilder for details on the naming convention).
-    // [GFX TODO][ATOM-14475]: Come up with a more elegant way to associate the isBound flag with the input stream.
-    // Vertex position of last frame to capture small scale motion due to vertex animation
-    float3 m_optional_prevPosition : POSITIONT;
+#define MATERIAL_USES_VERTEX_PREV_POSITION 1
 #endif
 #endif
-};
 
 
-struct VsSystemValues_DepthCommon
-{
-    uint m_instanceId;
-};
-
-#if MATERIALPIPELINE_USES_PREV_VERTEX_POSITION
-    // Indicates whether the vertex input struct's "m_optional_prevPosition" is bound. If false, it is not safe to read from m_optional_prevPosition.
-    // This option gets set automatically by the system at runtime; there is a soft naming convention that associates it with m_optional_prevPosition.
-    // (search "m_optional_" in ShaderVariantAssetBuilder for details on the naming convention).
-    // [GFX TODO][ATOM-14475]: Come up with a more elegant way to associate the isBound flag with the input stream.
-    option bool o_prevPosition_isBound;
-#endif
-
-struct VsOutput_DepthCommon
-{
-    // "centroid" is needed for SV_Depth to compile
-    precise linear centroid 
-    float4 m_position : SV_Position;
-    
-#if MATERIALPIPELINE_USES_PREV_VERTEX_POSITION
-    float3 m_worldPos : TEXCOORD0;
-    float3 m_worldPosPrev: TEXCOORD1;
-#endif
-    uint m_instanceId : SV_InstanceID;
-};
 
 

+ 13 - 10
Gems/Atom/Feature/Common/Assets/Shaders/Materials/DepthPass_VertexEval.azsli

@@ -13,28 +13,31 @@
 #endif
 #endif
 
 
 #include <Atom/RPI/TangentSpace.azsli>
 #include <Atom/RPI/TangentSpace.azsli>
-#include <Atom/Features/InstancedTransforms.azsli>
 
 
 VsOutput EvaluateVertexGeometry_DepthPass(VsInput IN, VsSystemValues SV, const MaterialParameters params)
 VsOutput EvaluateVertexGeometry_DepthPass(VsInput IN, VsSystemValues SV, const MaterialParameters params)
 {
 {
     VsOutput output;
     VsOutput output;
 
 
-    float4x4 objectToWorld = GetObjectToWorldMatrix(SV.m_instanceId);
-    float4 worldPosition = mul(objectToWorld, float4(IN.m_position, 1.0));
-    output.m_position = mul(ViewSrg::m_viewProjectionMatrix, worldPosition);
-    
-#if MATERIALPIPELINE_USES_PREV_VERTEX_POSITION
-    output.m_worldPos = worldPosition.xyz;
+#if MATERIAL_USES_VERTEX_POSITION
+    float4x4 objectToWorld = GetObjectToWorldMatrix(SV);
+    float4 worldPosition = mul(objectToWorld, float4(IN.position, 1.0));
+    float4x4 viewProjectionMatrix = GetViewProjectionMatrix(SV);
+    output.position = mul(viewProjectionMatrix, worldPosition);
+#if MATERIAL_USES_VERTEX_POSITIONWS
+    output.worldPosition = worldPosition.xyz;
+#endif // MATERIAL_USES_VERTEX_POSITIONWS
+#endif // MATERIAL_USES_VERTEX_POSITION
 
 
+#if MATERIAL_USES_VERTEX_PREV_POSITION
     if (o_prevPosition_isBound)
     if (o_prevPosition_isBound)
     {
     {
-        output.m_worldPosPrev = mul(GetObjectToWorldMatrixPrev(SV.m_instanceId), float4(IN.m_optional_prevPosition, 1.0)).xyz;
+        output.worldPosPrev = mul(GetObjectToWorldMatrixPrev(SV), float4(IN.m_optional_prevPosition, 1.0)).xyz;
     }
     }
     else
     else
     {
     {
-        output.m_worldPosPrev = mul(GetObjectToWorldMatrixPrev(SV.m_instanceId), float4(IN.m_position, 1.0)).xyz;
+        output.worldPosPrev = mul(GetObjectToWorldMatrixPrev(SV), float4(IN.position, 1.0)).xyz;
     }
     }
-#endif
+#endif // MATERIAL_USES_VERTEX_PREV_POSITION
 
 
     return output;
     return output;
 }
 }

+ 6 - 5
Gems/Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_PixelGeometryEval.azsli

@@ -16,11 +16,11 @@
 #endif
 #endif
 
 
 #include "../StandardPBR/StandardPBR_PixelGeometryEval.azsli"
 #include "../StandardPBR/StandardPBR_PixelGeometryEval.azsli"
-#include <Atom/Features/InstancedTransforms.azsli>
 
 
 #include <Atom/Features/Debug.azsli>
 #include <Atom/Features/Debug.azsli>
 
 
 PixelGeometryData EvaluatePixelGeometry_EnhancedPBR(
 PixelGeometryData EvaluatePixelGeometry_EnhancedPBR(
+    VsSystemValues SV,
     const MaterialParameters params,
     const MaterialParameters params,
     inout float4 positionSV,
     inout float4 positionSV,
     float3 positionWS,
     float3 positionWS,
@@ -32,7 +32,7 @@ PixelGeometryData EvaluatePixelGeometry_EnhancedPBR(
     bool isFrontFace,
     bool isFrontFace,
     real4x4 objectToWorld)
     real4x4 objectToWorld)
 {
 {
-    PixelGeometryData geoData = EvaluatePixelGeometry_BasePBR(params, positionWS, normalWS, tangentWS, bitangentWS, uvs, isFrontFace);
+    PixelGeometryData geoData = EvaluatePixelGeometry_BasePBR(SV, params, positionWS, normalWS, tangentWS, bitangentWS, uvs, isFrontFace);
 
 
     // ------- Detail UVs -------
     // ------- Detail UVs -------
 
 
@@ -53,15 +53,16 @@ PixelGeometryData EvaluatePixelGeometry_EnhancedPBR(
     return geoData;
     return geoData;
 }
 }
 
 
-PixelGeometryData EvaluatePixelGeometry_EnhancedPBR(inout VsOutput IN, bool isFrontFace, const MaterialParameters params)
+PixelGeometryData EvaluatePixelGeometry_EnhancedPBR(inout VsOutput IN, VsSystemValues SV, bool isFrontFace, const MaterialParameters params)
 {
 {
-    real4x4 objectToWorld = real4x4(GetObjectToWorldMatrix(IN.m_instanceId));
-    real3x3 objectToWorldIT = real3x3(GetObjectToWorldMatrixInverseTranspose(IN.m_instanceId));
+    real4x4 objectToWorld = real4x4(GetObjectToWorldMatrix(SV));
+    real3x3 objectToWorldIT = real3x3(GetObjectToWorldMatrixInverseTranspose(SV));
 
 
     real3 normalWS, tangentWS, bitangentWS;
     real3 normalWS, tangentWS, bitangentWS;
     ConstructTBN(real3(IN.normal), real4(IN.tangent), objectToWorld, objectToWorldIT, normalWS, tangentWS, bitangentWS);
     ConstructTBN(real3(IN.normal), real4(IN.tangent), objectToWorld, objectToWorldIT, normalWS, tangentWS, bitangentWS);
 
 
     return EvaluatePixelGeometry_EnhancedPBR(
     return EvaluatePixelGeometry_EnhancedPBR(
+        SV,
         params,
         params,
         IN.position,
         IN.position,
         IN.worldPosition,
         IN.worldPosition,

+ 9 - 41
Gems/Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_VertexData.azsli

@@ -8,45 +8,13 @@
 
 
 #pragma once
 #pragma once
 
 
-#ifndef ENABLE_VERTEX_COLOR
-#define ENABLE_VERTEX_COLOR 0
-#endif
+// by default the Vertex-Data is empty, so enable the parts we need
+#define MATERIAL_USES_VERTEX_POSITION 1
+#define MATERIAL_USES_VERTEX_POSITIONWS 1
+#define MATERIAL_USES_VERTEX_NORMAL 1
+#define MATERIAL_USES_VERTEX_TANGENT 1
+#define MATERIAL_USES_VERTEX_BITANGENT 1
+#define MATERIAL_USES_VERTEX_UV 1
+#define MATERIAL_USES_VERTEX_DETAIL_UV 1  // we need detail UVS for the enhanced PBR
+#define MATERIAL_USES_VERTEX_COLOR 1
 
 
-#ifndef VsOutput
-#define VsOutput        VsOutput_EnhancedPBR
-#endif
-
-#include "../BasePBR/BasePBR_VertexData.azsli"
-
-// Class inheritance doesn't seem to be working
-#define DOES_CLASS_INHERITANCE_WORK_IN_ASZL 0
-#if DOES_CLASS_INHERITANCE_WORK_IN_ASZL
-
-    struct VsOutput_EnhancedPBR : VsOutput_BasePBR
-    {
-        float2 m_detailUvs[UvSetCount] : UV3;
-    }
-
-#else
-
-    struct VsOutput_EnhancedPBR
-    {
-        // Base fields (required by the template azsli file)...
-        precise linear centroid
-        float4 position : SV_Position;
-        float3 normal: NORMAL;
-        float4 tangent : TANGENT;
-        float3 worldPosition : UV0;
-        uint m_instanceId : SV_InstanceID;
-
-        // Extended fields (only referenced in this azsl file)...
-        float2 uvs[UvSetCount] : UV1;
-        float2 detailUvs[UvSetCount] : UV3;
-
-#if ENABLE_VERTEX_COLOR
-        // Optional
-        float4 color0 : UV7; // Using UV7 just to leave some room for non optional attributes
-#endif
-    };
-
-#endif

+ 9 - 4
Gems/Atom/Feature/Common/Assets/Shaders/Materials/EnhancedPBR/EnhancedPBR_VertexEval.azsli

@@ -25,16 +25,18 @@ VsOutput EvaluateVertexGeometry_EnhancedPBR(
     float4 tangent,
     float4 tangent,
     float2 uv0,
     float2 uv0,
     float2 uv1,
     float2 uv1,
-    uint instanceId,
+    VsSystemValues SV,
     bool useVertexColor,
     bool useVertexColor,
     float4 color0)
     float4 color0)
 {
 {
     // BasePBRP
     // BasePBRP
-    VsOutput output = EvaluateVertexGeometry_BasePBR(params, position, normal, tangent, uv0, uv1, instanceId, useVertexColor, color0);
+    VsOutput output = EvaluateVertexGeometry_BasePBR(params, position, normal, tangent, uv0, uv1, SV, useVertexColor, color0);
 
 
+#ifdef MATERIAL_USES_VERTEX_DETAIL_UV
     // Detail UVs
     // Detail UVs
     float2 detailUvs[UvSetCount] = { uv0, uv1 };
     float2 detailUvs[UvSetCount] = { uv0, uv1 };
     TransformDetailUvs(params, detailUvs, output.detailUvs);
     TransformDetailUvs(params, detailUvs, output.detailUvs);
+#endif
 
 
     return output;
     return output;
 }
 }
@@ -54,7 +56,7 @@ VsOutput EvaluateVertexGeometry_EnhancedPBR(VsInput IN, VsSystemValues SV, const
         IN.tangent,
         IN.tangent,
         IN.uv0,
         IN.uv0,
         IN.uv1,
         IN.uv1,
-        SV.m_instanceId,
+        SV,
         useVertexColor0,
         useVertexColor0,
         color0);
         color0);
 }
 }
@@ -68,6 +70,9 @@ VsOutput EvaluateVertexGeometry_EnhancedPBR(
     float2 uv1,
     float2 uv1,
     uint instanceId)
     uint instanceId)
 {
 {
+    VsSystemValues  SV;
+    SV.m_instanceId = instanceId;
+
     return EvaluateVertexGeometry_EnhancedPBR(
     return EvaluateVertexGeometry_EnhancedPBR(
         params,
         params,
         position,
         position,
@@ -75,7 +80,7 @@ VsOutput EvaluateVertexGeometry_EnhancedPBR(
         tangent,
         tangent,
         uv0,
         uv0,
         uv1,
         uv1,
-        instanceId,
+        SV,
         false,
         false,
         float4(1.0f, 1.0f, 1.0f, 1.0f));
         float4(1.0f, 1.0f, 1.0f, 1.0f));
 }
 }

+ 8 - 6
Gems/Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_PixelGeometryEval.azsli

@@ -16,12 +16,12 @@
 #endif
 #endif
 
 
 #include "../MaterialFunctions/EvaluateTangentFrame.azsli"
 #include "../MaterialFunctions/EvaluateTangentFrame.azsli"
-#include <Atom/Features/InstancedTransforms.azsli>
 
 
 // TODO: The body of this function is copy pasted from BasePBR_PixelGeometryEval.azsli as that file could not be included here
 // TODO: The body of this function is copy pasted from BasePBR_PixelGeometryEval.azsli as that file could not be included here
 // since the file references an option o_normal_useTexture, which is not defined for the Eye shader. Need to find an elegant
 // since the file references an option o_normal_useTexture, which is not defined for the Eye shader. Need to find an elegant
 // way to handle this.
 // way to handle this.
 PixelGeometryData EvaluatePixelGeometry_Eye(
 PixelGeometryData EvaluatePixelGeometry_Eye(
+    VsSystemValues SV,
     const MaterialParameters params,
     const MaterialParameters params,
     float3 positionWS,
     float3 positionWS,
     real3 normalWS,
     real3 normalWS,
@@ -49,7 +49,7 @@ PixelGeometryData EvaluatePixelGeometry_Eye(
     {
     {
         for (int i = 0; i != UvSetCount; ++i)
         for (int i = 0; i != UvSetCount; ++i)
         {
         {
-            EvaluateTangentFrame(geoData.vertexNormal, positionWS, isFrontFace, uvs[i], i,
+            EvaluateTangentFrame(SV, geoData.vertexNormal, positionWS, isFrontFace, uvs[i], i,
                 tangentWS, bitangentWS, geoData.tangents[i], geoData.bitangents[i]);
                 tangentWS, bitangentWS, geoData.tangents[i], geoData.bitangents[i]);
         }
         }
     }
     }
@@ -58,6 +58,7 @@ PixelGeometryData EvaluatePixelGeometry_Eye(
 }
 }
 
 
 PixelGeometryData EvaluatePixelGeometry_Eye(
 PixelGeometryData EvaluatePixelGeometry_Eye(
+    VsSystemValues SV,
     const MaterialParameters params,
     const MaterialParameters params,
     float3 positionWS,
     float3 positionWS,
     real3 normalWS,
     real3 normalWS,
@@ -69,7 +70,7 @@ PixelGeometryData EvaluatePixelGeometry_Eye(
 {
 {
     // Base PBR Geo Data
     // Base PBR Geo Data
     bool evaluateTangentFrame = o_iris_o_normal_useTexture || o_sclera_o_normal_useTexture;
     bool evaluateTangentFrame = o_iris_o_normal_useTexture || o_sclera_o_normal_useTexture;
-    PixelGeometryData geoData = EvaluatePixelGeometry_Eye(params, positionWS, normalWS, tangentWS, bitangentWS, uv, isFrontFace, evaluateTangentFrame);
+    PixelGeometryData geoData = EvaluatePixelGeometry_Eye(SV, params, positionWS, normalWS, tangentWS, bitangentWS, uv, isFrontFace, evaluateTangentFrame);
 
 
     // Skin specifics
     // Skin specifics
     geoData.localPosition = localPosition;
     geoData.localPosition = localPosition;
@@ -77,10 +78,10 @@ PixelGeometryData EvaluatePixelGeometry_Eye(
     return geoData;
     return geoData;
 }
 }
 
 
-PixelGeometryData EvaluatePixelGeometry_Eye(VsOutput IN, bool isFrontFace, const MaterialParameters params)
+PixelGeometryData EvaluatePixelGeometry_Eye(VsOutput IN,  VsSystemValues SV, bool isFrontFace, const MaterialParameters params)
 {
 {
-    real4x4 objectToWorld = real4x4(GetObjectToWorldMatrix(IN.m_instanceId));
-    real3x3 objectToWorldIT = real3x3(GetObjectToWorldMatrixInverseTranspose(IN.m_instanceId));
+    real4x4 objectToWorld = real4x4(GetObjectToWorldMatrix(SV));
+    real3x3 objectToWorldIT = real3x3(GetObjectToWorldMatrixInverseTranspose(SV));
 
 
     real3 normalWS, tangentWS, bitangentWS;
     real3 normalWS, tangentWS, bitangentWS;
     ConstructTBN(real3(IN.normal), real4(IN.tangent), objectToWorld, objectToWorldIT, normalWS, tangentWS, bitangentWS);
     ConstructTBN(real3(IN.normal), real4(IN.tangent), objectToWorld, objectToWorldIT, normalWS, tangentWS, bitangentWS);
@@ -89,6 +90,7 @@ PixelGeometryData EvaluatePixelGeometry_Eye(VsOutput IN, bool isFrontFace, const
     bitangentWS = real3(normalize(mul(objectToWorld, float4(IN.bitangent, 0.0)).xyz));
     bitangentWS = real3(normalize(mul(objectToWorld, float4(IN.bitangent, 0.0)).xyz));
 
 
     PixelGeometryData geoData = EvaluatePixelGeometry_Eye(
     PixelGeometryData geoData = EvaluatePixelGeometry_Eye(
+        SV,
         params,
         params,
         IN.worldPosition,
         IN.worldPosition,
         normalWS,
         normalWS,

+ 9 - 21
Gems/Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_VertexData.azsli

@@ -8,24 +8,12 @@
 
 
 #pragma once
 #pragma once
 
 
-#ifndef VsOutput
-#define VsOutput        VSOutput_Eye
-#endif
-
-#include "../BasePBR/BasePBR_VertexData.azsli"
-
-struct VSOutput_Eye
-{
-    // Base fields (required by the template azsli file)...
-    precise linear centroid
-    float4 position : SV_Position;
-    float3 normal: NORMAL;
-    float4 tangent : TANGENT;
-    float3 bitangent : BITANGENT;
-    float3 worldPosition : UV0;
-    float2 uvs[UvSetCount] : UV1;
-
-    // Used for eye refraction
-    float3 localPosition : UV3;
-    uint m_instanceId : SV_InstanceID;
-};
+// by default the Vertex-Data is empty, so enable the parts we need
+#define MATERIAL_USES_VERTEX_POSITION 1
+#define MATERIAL_USES_VERTEX_POSITIONWS 1
+#define MATERIAL_USES_VERTEX_LOCALPOSITION 1 // used for eye refraction
+#define MATERIAL_USES_VERTEX_NORMAL 1
+#define MATERIAL_USES_VERTEX_TANGENT 1
+#define MATERIAL_USES_VERTEX_BITANGENT 1
+#define MATERIAL_USES_VERTEX_UV 1
+#define MATERIAL_USES_VERTEX_COLOR 1

+ 25 - 12
Gems/Atom/Feature/Common/Assets/Shaders/Materials/Eye/Eye_VertexEval.azsli

@@ -15,9 +15,6 @@
 #define EvaluateVertexGeometry EvaluateVertexGeometry_Eye
 #define EvaluateVertexGeometry EvaluateVertexGeometry_Eye
 #endif
 #endif
 
 
-#include <Atom/RPI/TangentSpace.azsli>
-#include <Atom/Features/InstancedTransforms.azsli>
-
 VsOutput EvaluateVertexGeometry_Eye(
 VsOutput EvaluateVertexGeometry_Eye(
     const MaterialParameters params,
     const MaterialParameters params,
     float3 position,
     float3 position,
@@ -26,28 +23,42 @@ VsOutput EvaluateVertexGeometry_Eye(
     float3 bitangent,
     float3 bitangent,
     float2 uv0,
     float2 uv0,
     float2 uv1,
     float2 uv1,
-    uint instanceId)
+    VsSystemValues SV)
 {
 {
     VsOutput output;
     VsOutput output;
 
 
-    float4x4 objectToWorld = GetObjectToWorldMatrix(instanceId);
+#if MATERIAL_USES_VERTEX_POSITION
+    float4x4 objectToWorld = GetObjectToWorldMatrix(SV);
     float4 worldPosition = mul(objectToWorld, float4(position, 1.0));
     float4 worldPosition = mul(objectToWorld, float4(position, 1.0));
     output.worldPosition = worldPosition.xyz;
     output.worldPosition = worldPosition.xyz;
-    output.position = mul(ViewSrg::m_viewProjectionMatrix, worldPosition);
 
 
+#if MATERIAL_USES_VERTEX_POSITIONWS
+    float4x4 viewProjectionMatrix = GetViewProjectionMatrix(SV);
+    output.position = mul(viewProjectionMatrix, worldPosition);
+#endif // MATERIAL_USES_VERTEX_POSITIONWS
+#endif // MATERIAL_USES_VERTEX_POSITION
+
+#if MATERIAL_USES_VERTEX_UV
     output.uvs[0] = uv0;
     output.uvs[0] = uv0;
     output.uvs[1] = uv1;
     output.uvs[1] = uv1;
+#endif // MATERIAL_USES_VERTEX_UV
 
 
+#if MATERIAL_USES_VERTEX_NORMAL
     output.normal = normal;
     output.normal = normal;
+#endif // MATERIAL_USES_VERTEX_NORMAL
+
+#if MATERIAL_USES_VERTEX_TANGENT
     output.tangent = tangent;
     output.tangent = tangent;
+#endif // MATERIAL_USES_VERTEX_TANGENT
+    
+#if MATERIAL_USES_VERTEX_BITANGENT
     // Bitangent is temporarily added back to fix the eye material screenshot test.
     // Bitangent is temporarily added back to fix the eye material screenshot test.
     output.bitangent = bitangent;
     output.bitangent = bitangent;
+#endif // MATERIAL_USES_VERTEX_BITANGENT
 
 
+#if MATERIAL_USES_VERTEX_LOCALPOSITION
     output.localPosition = position.xyz;
     output.localPosition = position.xyz;
-    
-    // Set the instanceId on the output so the pixel shader can use it
-    // since you can't use SV_InstanceID for both a vertex and a pixel shader at the same time
-    output.m_instanceId = instanceId;
+#endif // MATERIAL_USES_VERTEX_LOCALPOSITION
 
 
     return output;
     return output;
 }
 }
@@ -64,8 +75,10 @@ VsOutput EvaluateVertexGeometry_Eye(
     float2 uv1,
     float2 uv1,
     uint instanceId)
     uint instanceId)
 {
 {
+    VsSystemValues SV;
+    SV.m_instanceId = instanceId;
     const float3 bitangent = float3(0, 0, 0);
     const float3 bitangent = float3(0, 0, 0);
-    return EvaluateVertexGeometry_Eye(params, position, normal, tangent, bitangent, uv0, uv1, instanceId);
+    return EvaluateVertexGeometry_Eye(params, position, normal, tangent, bitangent, uv0, uv1, SV);
 }
 }
 
 
 VsOutput EvaluateVertexGeometry_Eye(VsInput IN, VsSystemValues SV, const MaterialParameters params)
 VsOutput EvaluateVertexGeometry_Eye(VsInput IN, VsSystemValues SV, const MaterialParameters params)
@@ -78,5 +91,5 @@ VsOutput EvaluateVertexGeometry_Eye(VsInput IN, VsSystemValues SV, const Materia
         IN.bitangent,
         IN.bitangent,
         IN.uv0,
         IN.uv0,
         IN.uv1,
         IN.uv1,
-        SV.m_instanceId);
+        SV);
 }
 }

+ 2 - 1
Gems/Atom/Feature/Common/Assets/Shaders/Materials/MaterialFunctions/EvaluateTangentFrame.azsli

@@ -11,6 +11,7 @@
 // The built-in tangent frame evaluation forwards the tangent frame interpolated from the vertex
 // The built-in tangent frame evaluation forwards the tangent frame interpolated from the vertex
 // data streams for UV-index 0. For UV-index 1, the tangent frame is computed from UV surface gradients.
 // data streams for UV-index 0. For UV-index 1, the tangent frame is computed from UV surface gradients.
 void EvaluateTangentFrame(
 void EvaluateTangentFrame(
+    VsSystemValues SV,
     real3 normal,
     real3 normal,
     float3 worldPosition,
     float3 worldPosition,
     bool isFrontFace,
     bool isFrontFace,
@@ -22,7 +23,7 @@ void EvaluateTangentFrame(
     out float3 OUT_tangent,
     out float3 OUT_tangent,
     out float3 OUT_bitangent)
     out float3 OUT_bitangent)
 {
 {
-    if (DrawSrg::GetTangentAtUv(uvIndex) == 0)
+    if (HasTangentForUvChannel(SV, uvIndex) == 0)
     {
     {
         OUT_tangent = IN_tangent;
         OUT_tangent = IN_tangent;
         OUT_bitangent = IN_bitangent;
         OUT_bitangent = IN_bitangent;

+ 1 - 0
Gems/Atom/Feature/Common/Assets/Shaders/Materials/MaterialFunctions/MultilayerParallaxDepth.azsli

@@ -37,6 +37,7 @@
     
     
     // heightmap and heightmap sampler don't matter here: They get passed to the GetDepth() - function of the StandardMultiLayerPBR - material, where they are ignored.
     // heightmap and heightmap sampler don't matter here: They get passed to the GetDepth() - function of the StandardMultiLayerPBR - material, where they are ignored.
     GetParallaxInput(
     GetParallaxInput(
+        params,
         GetMaterialTexture(params.m_layer1_m_heightmap), GetMaterialTextureSampler(), normal, tangents[params.m_parallaxUvIndex], bitangents[params.m_parallaxUvIndex],
         GetMaterialTexture(params.m_layer1_m_heightmap), GetMaterialTextureSampler(), normal, tangents[params.m_parallaxUvIndex], bitangents[params.m_parallaxUvIndex],
         parallaxOverallFactor, parallaxOverallOffset, 
         parallaxOverallFactor, parallaxOverallOffset, 
         objectToWorld, uvMatrix, uvMatrixInverse,
         objectToWorld, uvMatrix, uvMatrixInverse,

+ 1 - 0
Gems/Atom/Feature/Common/Assets/Shaders/Materials/MaterialFunctions/ParallaxDepth.azsli

@@ -35,6 +35,7 @@
     AdjustParallaxShadowCaster(heightmapScale, heightmapOffset, float(params.m_parallax_pdo_shadowFactor));
     AdjustParallaxShadowCaster(heightmapScale, heightmapOffset, float(params.m_parallax_pdo_shadowFactor));
 
 
     GetParallaxInput(
     GetParallaxInput(
+        params,
         GetMaterialTexture(params.m_heightmap), GetMaterialTextureSampler(), normal, tangents[params.m_parallaxUvIndex], bitangents[params.m_parallaxUvIndex],
         GetMaterialTexture(params.m_heightmap), GetMaterialTextureSampler(), normal, tangents[params.m_parallaxUvIndex], bitangents[params.m_parallaxUvIndex],
         heightmapScale, heightmapOffset,
         heightmapScale, heightmapOffset,
         objectToWorld, uvMatrix, uvMatrixInverse,
         objectToWorld, uvMatrix, uvMatrixInverse,

+ 7 - 6
Gems/Atom/Feature/Common/Assets/Shaders/Materials/MaterialInputs/ParallaxInput.azsli

@@ -25,7 +25,7 @@ float       prefix##m_heightmapOffset;
 #define COMMON_OPTIONS_PARALLAX(prefix) \
 #define COMMON_OPTIONS_PARALLAX(prefix) \
 option bool prefix##o_useHeightmap; 
 option bool prefix##o_useHeightmap; 
 
 
-void GetParallaxInput(Texture2D heightmap, sampler mapSampler, float3 normal, float3 tangent, float3 bitangent, float heightmapScale, float heightmapOffset,
+void GetParallaxInput(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float3 normal, float3 tangent, float3 bitangent, float heightmapScale, float heightmapOffset,
                       float4x4 objectWorldMatrix, real3x3 uvMatrix, real3x3 uvMatrixInverse,
                       float4x4 objectWorldMatrix, real3x3 uvMatrix, real3x3 uvMatrixInverse,
                       inout float2 uv, inout float3 worldPosition, inout float depthNDC, inout float depthCS, out bool isClipped)
                       inout float2 uv, inout float3 worldPosition, inout float depthNDC, inout float depthCS, out bool isClipped)
 {
 {
@@ -45,7 +45,8 @@ void GetParallaxInput(Texture2D heightmap, sampler mapSampler, float3 normal, fl
             dirToCamera = float3(ViewSrg::m_worldPosition.xyz - worldPosition);
             dirToCamera = float3(ViewSrg::m_worldPosition.xyz - worldPosition);
         }
         }
     
     
-        ParallaxOffset tangentOffset = GetParallaxOffset( heightmap,
+        ParallaxOffset tangentOffset = GetParallaxOffset( params,
+                                                          heightmap,
                                                           mapSampler,
                                                           mapSampler,
                                                           heightmapScale,
                                                           heightmapScale,
                                                           -heightmapOffset,
                                                           -heightmapOffset,
@@ -79,19 +80,19 @@ void GetParallaxInput(Texture2D heightmap, sampler mapSampler, float3 normal, fl
     }
     }
 }
 }
 
 
-void GetParallaxInput(Texture2D heightmap, sampler mapSampler, float3 normal, float3 tangent, float3 bitangent, float heightmapScale, float heightmapOffset,
+void GetParallaxInput(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float3 normal, float3 tangent, float3 bitangent, float heightmapScale, float heightmapOffset,
                       float4x4 objectWorldMatrix, float3x3 uvMatrix, float3x3 uvMatrixInverse,
                       float4x4 objectWorldMatrix, float3x3 uvMatrix, float3x3 uvMatrixInverse,
                       inout float2 uv, inout float3 worldPosition, inout float depthNDC, inout float depthCS)
                       inout float2 uv, inout float3 worldPosition, inout float depthNDC, inout float depthCS)
 {
 {
     bool isClipped = false;
     bool isClipped = false;
-    GetParallaxInput(heightmap, mapSampler, normal, tangent, bitangent, heightmapScale, heightmapOffset, objectWorldMatrix, uvMatrix, uvMatrixInverse, uv, worldPosition, depthNDC, depthCS, isClipped);
+    GetParallaxInput(params, heightmap, mapSampler, normal, tangent, bitangent, heightmapScale, heightmapOffset, objectWorldMatrix, uvMatrix, uvMatrixInverse, uv, worldPosition, depthNDC, depthCS, isClipped);
 }
 }
 
 
-void GetParallaxInput(Texture2D heightmap, sampler mapSampler, float3 normal, float3 tangent, float3 bitangent, float heightmapScale, float heightmapOffset,
+void GetParallaxInput(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float3 normal, float3 tangent, float3 bitangent, float heightmapScale, float heightmapOffset,
     float4x4 objectWorldMatrix, float3x3 uvMatrix, float3x3 uvMatrixInverse,
     float4x4 objectWorldMatrix, float3x3 uvMatrix, float3x3 uvMatrixInverse,
     inout float2 uv, inout float3 worldPosition, inout float depthNDC)
     inout float2 uv, inout float3 worldPosition, inout float depthNDC)
 {
 {
     float depthCS;
     float depthCS;
-    GetParallaxInput(heightmap, mapSampler, normal, tangent, bitangent, heightmapScale, heightmapOffset, objectWorldMatrix, uvMatrix, uvMatrixInverse, uv, worldPosition, depthNDC, depthCS);
+    GetParallaxInput(params, heightmap, mapSampler, normal, tangent, bitangent, heightmapScale, heightmapOffset, objectWorldMatrix, uvMatrix, uvMatrixInverse, uv, worldPosition, depthNDC, depthCS);
 }
 }
 
 

+ 0 - 28
Gems/Atom/Feature/Common/Assets/Shaders/Materials/MultilayerPBR/StandardMultilayerPBR_DepthPass_WithPS.azsl

@@ -1,28 +0,0 @@
-/*
- * 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_all.srgi>
-#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
-#include <Atom/Features/ParallaxMapping.azsli>
-#include <Atom/Features/MatrixUtility.azsli>
-
-#include "../MaterialInputs/ParallaxInput.azsli"
-
-
-#include "../MaterialInputs/ParallaxInput.azsli"
-COMMON_OPTIONS_PARALLAX(o_layer1_)
-COMMON_OPTIONS_PARALLAX(o_layer2_)
-COMMON_OPTIONS_PARALLAX(o_layer3_)
-
-#include "./StandardMultilayerPBR_Common.azsli"
-
-#include "../MaterialFunctions/EvaluateTangentFrame.azsli"
-#include "../MaterialFunctions/MultilayerParallaxDepth.azsli"
-
-#define MULTILAYER 1
-#define ENABLE_ALPHA_CLIP 0

+ 0 - 27
Gems/Atom/Feature/Common/Assets/Shaders/Materials/MultilayerPBR/StandardMultilayerPBR_Shadowmap_WithPS.azsl

@@ -1,27 +0,0 @@
-/*
- * 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
- *
- */
- 
-#define MULTILAYER 1
-#define ENABLE_ALPHA_CLIP 0
-#define SHADOWMAP 1
-
-#include <scenesrg_all.srgi>
-#include <viewsrg_all.srgi>
-#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
-#include <Atom/Features/ParallaxMapping.azsli>
-#include <Atom/Features/MatrixUtility.azsli>
-
-#include "../MaterialInputs/ParallaxInput.azsli"
-COMMON_OPTIONS_PARALLAX(o_layer1_)
-COMMON_OPTIONS_PARALLAX(o_layer2_)
-COMMON_OPTIONS_PARALLAX(o_layer3_)
-
-#include "StandardMultilayerPBR_Common.azsli"
-
-#include "../MaterialFunctions/EvaluateTangentFrame.azsli"
-#include "../MaterialFunctions/MultilayerParallaxDepth.azsli"

+ 11 - 9
Gems/Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_PixelGeometryEval.azsli

@@ -16,45 +16,47 @@
 #endif
 #endif
 
 
 #include "../BasePBR/BasePBR_PixelGeometryEval.azsli"
 #include "../BasePBR/BasePBR_PixelGeometryEval.azsli"
-#include <Atom/Features/InstancedTransforms.azsli>
 
 
 PixelGeometryData EvaluatePixelGeometry_Skin(
 PixelGeometryData EvaluatePixelGeometry_Skin(
+    VsSystemValues SV,
     const MaterialParameters params,
     const MaterialParameters params,
     float3 positionWS,
     float3 positionWS,
     real3 normalWS,
     real3 normalWS,
     real3 tangentWS,
     real3 tangentWS,
     real3 bitangentWS,
     real3 bitangentWS,
     float2 uvs[UvSetCount],
     float2 uvs[UvSetCount],
-    float2 detailUv,
+    float2 detailUvs[UvSetCount],
     real4 wrinkleBlendFactors,
     real4 wrinkleBlendFactors,
     bool isFrontFace)
     bool isFrontFace)
 {
 {
     // Base PBR Geo Data
     // Base PBR Geo Data
-    PixelGeometryData geoData = EvaluatePixelGeometry_BasePBR(params, positionWS, normalWS, tangentWS, bitangentWS, uvs, isFrontFace);
+    PixelGeometryData geoData = EvaluatePixelGeometry_BasePBR(SV, params, positionWS, normalWS, tangentWS, bitangentWS, uvs, isFrontFace);
 
 
     // Skin specifics
     // Skin specifics
-    geoData.detailUv = detailUv;
+    // skin only has one detail UV channel
+    geoData.detailUv = detailUvs[0];
     geoData.wrinkleBlendFactors = wrinkleBlendFactors;
     geoData.wrinkleBlendFactors = wrinkleBlendFactors;
 
 
     return geoData;
     return geoData;
 }
 }
 
 
-PixelGeometryData EvaluatePixelGeometry_Skin(VsOutput IN, bool isFrontFace, const MaterialParameters params)
+PixelGeometryData EvaluatePixelGeometry_Skin(VsOutput IN, VsSystemValues SV, bool isFrontFace, const MaterialParameters params)
 {
 {
-    real4x4 objectToWorld = real4x4(GetObjectToWorldMatrix(IN.m_instanceId));
-    real3x3 objectToWorldIT = real3x3(GetObjectToWorldMatrixInverseTranspose(IN.m_instanceId));
+    real4x4 objectToWorld = real4x4(GetObjectToWorldMatrix(SV));
+    real3x3 objectToWorldIT = real3x3(GetObjectToWorldMatrixInverseTranspose(SV));
 
 
     real3 normalWS, tangentWS, bitangentWS;
     real3 normalWS, tangentWS, bitangentWS;
     ConstructTBN(real3(IN.normal), real4(IN.tangent), objectToWorld, objectToWorldIT, normalWS, tangentWS, bitangentWS);
     ConstructTBN(real3(IN.normal), real4(IN.tangent), objectToWorld, objectToWorldIT, normalWS, tangentWS, bitangentWS);
 
 
     return EvaluatePixelGeometry_Skin(
     return EvaluatePixelGeometry_Skin(
+        SV,
         params,
         params,
         IN.worldPosition,
         IN.worldPosition,
         normalWS,
         normalWS,
         tangentWS,
         tangentWS,
         bitangentWS,
         bitangentWS,
         IN.uvs,
         IN.uvs,
-        IN.detailUv,
-        real4(IN.wrinkleBlendFactors),
+        IN.detailUvs,
+        real4(IN.blendFactors),
         isFrontFace);
         isFrontFace);
 }
 }

+ 14 - 14
Gems/Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_SurfaceEval.azsli

@@ -115,30 +115,30 @@ Surface EvaluateSurface_Skin(
 
 
     if(o_wrinkleLayers_enabled)
     if(o_wrinkleLayers_enabled)
     {
     {
+#if PIPELINE_HAS_OBJECT_SRG
         real4 wrinkleMaskBlendFactors = real4(0.0, 0.0, 0.0, 0.0);
         real4 wrinkleMaskBlendFactors = real4(0.0, 0.0, 0.0, 0.0);
 
 
+        // TODO: get the VsSystemValues as a parameter.
+        // This is okay for now since the wrinkle-mask functions don't really use the SV - parameter yet.
+        VsSystemValues SV = (VsSystemValues)(0);
+
         // Combine the optional per-morph target wrinkle masks
         // Combine the optional per-morph target wrinkle masks
-        for(uint wrinkleMaskIndex = 0; wrinkleMaskIndex < ObjectSrg::m_wrinkle_mask_count; ++wrinkleMaskIndex)
+        for(uint wrinkleMaskIndex = 0; wrinkleMaskIndex < GetWrinkleMaskCount(SV); ++wrinkleMaskIndex)
         {
         {
-            if (customDerivatives)
-            {
-                wrinkleMaskBlendFactors += real4(ObjectSrg::m_wrinkle_masks[wrinkleMaskIndex].SampleGrad(GetMaterialTextureSampler(), normalUv, uvDxDy.xy, uvDxDy.zw) * ObjectSrg::GetWrinkleMaskWeight(wrinkleMaskIndex));
-            }
-            else
-            {
-                #ifdef CS_SAMPLERS
-                wrinkleMaskBlendFactors += real4(ObjectSrg::m_wrinkle_masks[wrinkleMaskIndex].SampleLevel(GetMaterialTextureSampler(), normalUv, 0) * ObjectSrg::GetWrinkleMaskWeight(wrinkleMaskIndex));
-                #else
-                wrinkleMaskBlendFactors += real4(ObjectSrg::m_wrinkle_masks[wrinkleMaskIndex].Sample(GetMaterialTextureSampler(), normalUv) * ObjectSrg::GetWrinkleMaskWeight(wrinkleMaskIndex));
-                #endif
-            }
+            wrinkleMaskBlendFactors += SampleWrinkleMask(SV, GetMaterialTextureSampler(), wrinkleMaskIndex, normalUv, uvDxDy, customDerivatives) * GetWrinkleMaskWeight(SV, wrinkleMaskIndex);
         }
         }
 
 
         // If texture based morph target driven masks are being used, use those values instead of the per-vertex colors
         // If texture based morph target driven masks are being used, use those values instead of the per-vertex colors
-        if(ObjectSrg::m_wrinkle_mask_count)
+        if(GetWrinkleMaskCount(SV) > 0)
         {
         {
             wrinkleBlendFactors = saturate(wrinkleMaskBlendFactors);
             wrinkleBlendFactors = saturate(wrinkleMaskBlendFactors);
         }
         }
+        else {
+            wrinkleBlendFactors = real4(0.0, 0.0, 0.0, 0.0);
+        }
+#else 
+        wrinkleBlendFactors = real4(0.0, 0.0, 0.0, 0.0);
+#endif // PIPELINE_HAS_OBJECT_SRG
     }
     }
 
 
     // ------- Normal -------
     // ------- Normal -------

+ 9 - 56
Gems/Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_VertexData.azsli

@@ -8,59 +8,12 @@
 
 
 #pragma once
 #pragma once
 
 
-// This #define magic lets you use the VsInput & VsOutput classes in this file without making it the final VsInput & VsOutput
-// used in your shader. Simply #define VsInput & VsOutput to your custom definitions before including this file
-//
-#ifndef VsInput
-#define VsInput         VsInput_Skin
-#endif
-
-#ifndef VsSystemValues
-#define VsSystemValues  VsSystemValues_Skin
-#endif
-
-#ifndef VsOutput
-#define VsOutput        VsOutput_Skin
-#endif
-
-#include "../BasePBR/BasePBR_VertexData.azsli"
-
-struct VsInput_Skin
-{
-    // Base fields (required by the template azsli file)...
-    float3 position : POSITION;
-    float3 normal : NORMAL;
-    float4 tangent : TANGENT;
- 
-    // Extended fields (only referenced in this azsl file)...
-    float2 uv0_tiled : UV0;
-    float2 uv1_unwrapped : UV1;
-    
-    // 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).
-    // [GFX TODO][ATOM-14475]: Come up with a more elegant way to associate the isBound flag with the input stream.
-    float4 m_optional_blendMask : COLOR0;
-};
-
-struct VsSystemValues_Skin
-{
-    uint m_instanceId;
-};
-
-struct VsOutput_Skin
-{
-    // Base fields (required by the template azsli file)...
-    precise linear centroid
-    float4 position : SV_Position;
-    float3 normal: NORMAL;
-    float4 tangent : TANGENT;
-    float3 worldPosition : UV0;
-    uint m_instanceId : SV_InstanceID;
-
-    // Extended fields (only referenced in this azsl file)...
-    float2 uvs[UvSetCount] : UV1;
-    float2 detailUv : UV3;
-    
-    float4 wrinkleBlendFactors : UV8;
-};
+// by default the Vertex-Data is empty, so enable the parts we need
+#define MATERIAL_USES_VERTEX_POSITION 1
+#define MATERIAL_USES_VERTEX_POSITIONWS 1
+#define MATERIAL_USES_VERTEX_NORMAL 1
+#define MATERIAL_USES_VERTEX_TANGENT 1
+#define MATERIAL_USES_VERTEX_BITANGENT 1
+#define MATERIAL_USES_VERTEX_UV 1
+#define MATERIAL_USES_VERTEX_DETAIL_UV 1  // we have detail UV for skin
+#define MATERIAL_USES_VERTEX_BLENDMASK 1  // used as the wrinkle mask

+ 40 - 24
Gems/Atom/Feature/Common/Assets/Shaders/Materials/Skin/Skin_VertexEval.azsli

@@ -15,13 +15,9 @@
 #define EvaluateVertexGeometry EvaluateVertexGeometry_Skin
 #define EvaluateVertexGeometry EvaluateVertexGeometry_Skin
 #endif
 #endif
 
 
-#include <Atom/Features/InstancedTransforms.azsli>
-
-// Indicates whether the vertex input struct's "m_optional_blendMask" is bound. If false, it is not safe to read from m_optional_blendMask.
-// This option gets set automatically by the system at runtime; there is a soft naming convention that associates it with m_optional_blendMask.
-// (search "m_optional_" in ShaderVariantAssetBuilder for details on the naming convention).
-// [GFX TODO][ATOM-14475]: Come up with a more elegant way to associate the isBound flag with the input stream.
-option bool o_blendMask_isBound;
+#if MATERIAL_USES_VERTEX_DETAIL_UV
+#include "../MaterialFunctions/StandardTransformDetailUvs.azsli"
+#endif
 
 
 VsOutput EvaluateVertexGeometry_Skin(
 VsOutput EvaluateVertexGeometry_Skin(
     const MaterialParameters params,
     const MaterialParameters params,
@@ -31,15 +27,23 @@ VsOutput EvaluateVertexGeometry_Skin(
     float2 uv0_tiled,
     float2 uv0_tiled,
     float2 uv1_unwrapped,
     float2 uv1_unwrapped,
     float4 optionalBlendMask,
     float4 optionalBlendMask,
-    uint instanceId)
+    VsSystemValues SV)
 {
 {
     VsOutput output;
     VsOutput output;
 
 
-    float4x4 objectToWorld = GetObjectToWorldMatrix(instanceId);
+#if MATERIAL_USES_VERTEX_POSITION
+    float4x4 objectToWorld = GetObjectToWorldMatrix(SV);
     float4 worldPosition = mul(objectToWorld, float4(position, 1.0));
     float4 worldPosition = mul(objectToWorld, float4(position, 1.0));
     output.worldPosition = worldPosition.xyz;
     output.worldPosition = worldPosition.xyz;
-    output.position = mul(ViewSrg::m_viewProjectionMatrix, worldPosition);
 
 
+#if MATERIAL_USES_VERTEX_POSITIONWS
+    float4x4 viewProjectionMatrix = GetViewProjectionMatrix(SV);
+    output.position = mul(viewProjectionMatrix, worldPosition);
+#endif // MATERIAL_USES_VERTEX_POSITIONWS
+
+#endif // MATERIAL_USES_VERTEX_POSITION
+
+#if MATERIAL_USES_VERTEX_UV  
     // UV0 is for tiled UVs. This will almost always be used exclusively with the detail layer, but it is still available
     // UV0 is for tiled UVs. This will almost always be used exclusively with the detail layer, but it is still available
     // for the main layer to use if needed. Unlike StandardPBR etc, we don't provide a transform for this stream on the main layer, 
     // for the main layer to use if needed. Unlike StandardPBR etc, we don't provide a transform for this stream on the main layer, 
     // because it will usually be used for the detail layer which has its own dedicated transform. If a use does case come up, we 
     // because it will usually be used for the detail layer which has its own dedicated transform. If a use does case come up, we 
@@ -48,30 +52,40 @@ VsOutput EvaluateVertexGeometry_Skin(
     // still use UV0 for "tiled" because UV0 has pre-generated tangent vectors which is important for detail maps, which usually
     // still use UV0 for "tiled" because UV0 has pre-generated tangent vectors which is important for detail maps, which usually
     // use the "tiled" stream, and need better quality tangents because of the high frequency.
     // use the "tiled" stream, and need better quality tangents because of the high frequency.
     output.uvs[0] = uv0_tiled;
     output.uvs[0] = uv0_tiled;
-
     // UV1 is for unwrapped UVs. The main textures in a skin material will almost always use this UV set.
     // UV1 is for unwrapped UVs. The main textures in a skin material will almost always use this UV set.
     output.uvs[1] = uv1_unwrapped;
     output.uvs[1] = uv1_unwrapped;
     
     
+    
+#endif
+
+#if MATERIAL_USES_VERTEX_DETAIL_UV    
+    // Detail UVs
     // The detail layer has a dedicated UV transform which we apply here. The detail layer does have the option of using
     // The detail layer has a dedicated UV transform which we apply here. The detail layer does have the option of using
     // either UV0 or UV1, in either case we apply the transform.
     // either UV0 or UV1, in either case we apply the transform.
-    output.detailUv = params.m_detail_allMapsUvIndex == 0 ? uv0_tiled : uv1_unwrapped;
-    output.detailUv = mul(params.m_detailUvMatrix, float3(output.detailUv, 1.0)).xy;
-    
+    output.detailUvs[0] = params.m_detail_allMapsUvIndex == 0 ? uv0_tiled : uv1_unwrapped;
+    output.detailUvs[0] = mul(params.m_detailUvMatrix, float3(output.detailUvs[0], 1.0)).xy;
+    output.detailUvs[1] = output.detailUvs[0];
+
+#endif // MATERIAL_USES_VERTEX_DETAIL_UV
+
+#if MATERIAL_USES_VERTEX_BLENDMASK
     if(o_blendMask_isBound)
     if(o_blendMask_isBound)
     {
     {
-        output.wrinkleBlendFactors = optionalBlendMask;
+        output.blendFactors = optionalBlendMask;
     }
     }
     else
     else
     {
     {
-        output.wrinkleBlendFactors = float4(0,0,0,0);
+        output.blendFactors = float4(0,0,0,0);
     }
     }
+#endif // MATERIAL_USES_VERTEX_BLENDMASK
 
 
+#if MATERIAL_USES_VERTEX_NORMAL
     output.normal = normal;
     output.normal = normal;
-    output.tangent = tangent;
+#endif // MATERIAL_USES_VERTEX_NORMAL
 
 
-    // Set the instanceId on the output so the pixel shader can use it
-    // since you can't use SV_InstanceID for both a vertex and a pixel shader at the same time
-    output.m_instanceId = instanceId;
+#if MATERIAL_USES_VERTEX_TANGENT
+    output.tangent = tangent;
+#endif // MATERIAL_USES_VERTEX_TANGENT
     
     
     return output;
     return output;
 }
 }
@@ -88,7 +102,9 @@ VsOutput EvaluateVertexGeometry_Skin(
     float2 uv1_unwrapped,
     float2 uv1_unwrapped,
     uint instanceId)
     uint instanceId)
 {
 {
-    return EvaluateVertexGeometry_Skin(params, position, normal, tangent, uv0_tiled, uv1_unwrapped, float4(0, 0, 0, 0), instanceId);
+    VsSystemValues SV;
+    SV.m_instanceId = instanceId;
+    return EvaluateVertexGeometry_Skin(params, position, normal, tangent, uv0_tiled, uv1_unwrapped, float4(0, 0, 0, 0), SV);
 }
 }
 
 
 VsOutput EvaluateVertexGeometry_Skin(VsInput IN, VsSystemValues SV, const MaterialParameters params)
 VsOutput EvaluateVertexGeometry_Skin(VsInput IN, VsSystemValues SV, const MaterialParameters params)
@@ -98,8 +114,8 @@ VsOutput EvaluateVertexGeometry_Skin(VsInput IN, VsSystemValues SV, const Materi
         IN.position,
         IN.position,
         IN.normal,
         IN.normal,
         IN.tangent,
         IN.tangent,
-        IN.uv0_tiled,
-        IN.uv1_unwrapped,
+        IN.uv0,
+        IN.uv1,
         IN.m_optional_blendMask,
         IN.m_optional_blendMask,
-        SV.m_instanceId);
+        SV);
 }
 }

+ 3 - 28
Gems/Atom/Feature/Common/Assets/Shaders/Materials/MultilayerPBR/StandardMultilayerPBR_Common.azsli → Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_Common.azsli

@@ -8,25 +8,8 @@
 
 
 #pragma once 
 #pragma once 
 
 
-#include <Atom/Features/SrgSemantics.azsli>
-#include <Atom/Features/PBR/LightingOptions.azsli>
 #include <Atom/RPI/Math.azsli>
 #include <Atom/RPI/Math.azsli>
 
 
-// This file contains the definition for 'struct MaterialParameters', which is generated by the Materialpipeline
-#include MATERIAL_PARAMETERS_AZSLI_FILE_PATH
-#include <Atom/Features/Materials/MaterialSrg.azsli>
-
-#include "../MaterialInputs/BaseColorInput.azsli"
-#include "../MaterialInputs/RoughnessInput.azsli"
-#include "../MaterialInputs/MetallicInput.azsli"
-#include "../MaterialInputs/SpecularInput.azsli"
-#include "../MaterialInputs/NormalInput.azsli"
-#include "../MaterialInputs/ClearCoatInput.azsli"
-#include "../MaterialInputs/OcclusionInput.azsli"
-#include "../MaterialInputs/EmissiveInput.azsli"
-#include "../MaterialInputs/ParallaxInput.azsli"
-#include "../MaterialInputs/UvSetCount.azsli"
-
 // ------ Shader Options ----------------------------------------
 // ------ Shader Options ----------------------------------------
 
 
 option bool o_layer2_enabled;
 option bool o_layer2_enabled;
@@ -43,12 +26,6 @@ option DebugDrawMode o_debugDrawMode;
 enum class LayerBlendSource { BlendMaskTexture, BlendMaskVertexColors, Displacement, Displacement_With_BlendMaskTexture, Displacement_With_BlendMaskVertexColors, Fallback };
 enum class LayerBlendSource { BlendMaskTexture, BlendMaskVertexColors, Displacement, Displacement_With_BlendMaskTexture, Displacement_With_BlendMaskVertexColors, Fallback };
 option LayerBlendSource o_layerBlendSource;
 option LayerBlendSource o_layerBlendSource;
 
 
-// Indicates whether the vertex input struct's "m_optional_blendMask" is bound. If false, it is not safe to read from m_optional_blendMask.
-// This option gets set automatically by the system at runtime; there is a soft naming convention that associates it with m_optional_blendMask.
-// (search "m_optional_" in ShaderVariantAssetBuilder for details on the naming convention).
-// [GFX TODO][ATOM-14475]: Come up with a more elegant way to associate the isBound flag with the input stream.
-option bool o_blendMask_isBound;
-
 // ------ Blend Utilities ----------------------------------------
 // ------ Blend Utilities ----------------------------------------
 // This is mainly used to pass extra data to the GetDepth callback function during the parallax depth search.
 // This is mainly used to pass extra data to the GetDepth callback function during the parallax depth search.
 // But since we have it, we use it in some other functions as well rather than passing it around.
 // But since we have it, we use it in some other functions as well rather than passing it around.
@@ -396,14 +373,12 @@ real3 ApplyBlendMaskToDepthValues(const MaterialParameters params, real3 blendMa
 }
 }
 
 
 //! Callback function for ParallaxMapping.azsli
 //! Callback function for ParallaxMapping.azsli
-DepthResult GetDepth(Texture2D heightmap, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
+DepthResult GetDepth(const MaterialParameters params, Texture2D heightmap, sampler mapSampler, float2 uv, float2 uv_ddx, float2 uv_ddy)
 {
 {
     LayerBlendSource blendSource = GetFinalLayerBlendSource();
     LayerBlendSource blendSource = GetFinalLayerBlendSource();
 
 
-    // heightmap and mapSampler ignored here, since each layer can have it's own heightmap:
-    // we simply fetch the MaterialParameters from the SRG again and sample and blend the height from our configured layers
-    const MaterialParameters params = GetMaterialParameters();
-
+    // heightmap and mapSampler ignored here, since each layer can have it's own heightmap
+    // we sample and blend the height from our configured layers
     real3 layerDepthValues = real3(GetLayerDepthValues(params, uv, uv_ddx, uv_ddy));
     real3 layerDepthValues = real3(GetLayerDepthValues(params, uv, uv_ddx, uv_ddy));
     
     
     // Note, when the blend source uses the blend mask from the vertex colors, parallax will not be able to blend correctly between layers. It will end up using the same blend mask values
     // Note, when the blend source uses the blend mask from the vertex colors, parallax will not be able to blend correctly between layers. It will end up using the same blend mask values

+ 17 - 0
Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_MaterialInputs.azsli

@@ -0,0 +1,17 @@
+
+#pragma once
+
+
+
+#include <Atom/Features/PBR/LightingOptions.azsli>
+
+#include "../MaterialInputs/BaseColorInput.azsli"
+#include "../MaterialInputs/RoughnessInput.azsli"
+#include "../MaterialInputs/MetallicInput.azsli"
+#include "../MaterialInputs/SpecularInput.azsli"
+#include "../MaterialInputs/NormalInput.azsli"
+#include "../MaterialInputs/ClearCoatInput.azsli"
+#include "../MaterialInputs/OcclusionInput.azsli"
+#include "../MaterialInputs/EmissiveInput.azsli"
+#include "../MaterialInputs/ParallaxInput.azsli"
+#include "../MaterialInputs/UvSetCount.azsli"

+ 42 - 0
Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_PixelGeometryData.azsli

@@ -0,0 +1,42 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+// This #define magic lets you use the PixelGeometryData class in this file without making it the final PixelGeometryData
+// used in your shader. Simply #define PixelGeometryData to your custom definition before including this file
+//
+#ifndef PixelGeometryData
+#define PixelGeometryData       PixelGeometryData_StandardMultilayerPBR
+#endif
+
+#include "../StandardPBR/StandardPBR_PixelGeometryData.azsli"
+
+#define DOES_CLASS_INHERITANCE_WORK_IN_ASZL 0
+#if DOES_CLASS_INHERITANCE_WORK_IN_ASZL
+
+    class PixelGeometryData_StandardMultilayerPBR : PixelGeometryData_StandardPBR 
+    {
+        real3 m_vertexBlendMask;
+    };
+
+#else
+
+    class PixelGeometryData_StandardMultilayerPBR 
+    {
+        float3 positionWS;
+        real3 vertexNormal;
+        float2 uvs[UvSetCount];
+        float3 tangents[UvSetCount];
+        float3 bitangents[UvSetCount];
+        bool isFrontFace;
+        bool isDisplacementClipped;
+        real3 m_vertexBlendMask;
+    };
+
+#endif

+ 66 - 0
Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_PixelGeometryEval.azsli

@@ -0,0 +1,66 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+#ifndef EvaluatePixelGeometry
+#define EvaluatePixelGeometry EvaluatePixelGeometry_StandardMultilayerPBR
+#endif
+
+#include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_PixelGeometryEval.azsli>
+
+PixelGeometryData EvaluatePixelGeometry_StandardMultilayerPBR(
+    VsSystemValues SV,
+    const MaterialParameters params,
+    inout float4 positionSV,
+    float3 positionWS,
+    real3 normalWS,
+    real3 tangentWS,
+    real3 bitangentWS,
+    float2 uvs[UvSetCount],
+    bool isFrontFace,
+    real4x4 objectToWorld,
+    real3 vertexBlendMask)
+{
+    PixelGeometryData geoData = EvaluatePixelGeometry_BasePBR(SV, params, positionWS, normalWS, tangentWS, bitangentWS, uvs, isFrontFace);
+    geoData.isDisplacementClipped = false;
+    geoData.m_vertexBlendMask = vertexBlendMask;
+
+#if ENABLE_PARALLAX
+    if(ShouldHandleParallax())
+    {
+        MultilayerSetPixelDepth(params, vertexBlendMask, geoData.positionWS, geoData.vertexNormal, geoData.tangents, geoData.bitangents,
+            geoData.uvs, isFrontFace, objectToWorld, positionSV.z, positionSV.w, geoData.isDisplacementClipped);
+    }
+#endif
+    return geoData;
+}
+
+PixelGeometryData EvaluatePixelGeometry_StandardMultilayerPBR(inout VsOutput IN, VsSystemValues SV, bool isFrontFace, const MaterialParameters params)
+{
+    real4x4 objectToWorld = real4x4(GetObjectToWorldMatrix(SV));
+    real3x3 objectToWorldIT = real3x3(GetObjectToWorldMatrixInverseTranspose(SV));
+    
+    real3 normalWS, tangentWS, bitangentWS;
+    ConstructTBN(real3(IN.normal), real4(IN.tangent), objectToWorld, objectToWorldIT, normalWS, tangentWS, bitangentWS);
+    
+    return EvaluatePixelGeometry_StandardMultilayerPBR(
+        SV,
+        params,
+        IN.position,
+        IN.worldPosition,
+        normalWS,
+        tangentWS,
+        bitangentWS,
+        IN.uvs,
+        isFrontFace,
+        objectToWorld,
+        real3(IN.blendFactors.xyz));
+}
+
+

+ 414 - 0
Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_SurfaceEval.azsli

@@ -0,0 +1,414 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+#ifndef EvaluateSurface
+#define EvaluateSurface EvaluateSurface_StandardMultilayerPBR
+#endif
+
+//! Collects all the raw Standard material inputs for a single layer. See ProcessStandardMaterialInputs().
+struct StandardMaterialInputs
+{
+    COMMON_SRG_INPUTS_BASE_COLOR()
+    COMMON_SRG_INPUTS_ROUGHNESS()
+    COMMON_SRG_INPUTS_METALLIC()
+    COMMON_SRG_INPUTS_SPECULAR_F0()
+    COMMON_SRG_INPUTS_NORMAL()
+    COMMON_SRG_INPUTS_CLEAR_COAT()
+    COMMON_SRG_INPUTS_OCCLUSION()
+    COMMON_SRG_INPUTS_EMISSIVE()
+    // Note parallax is omitted here because that requires special handling.
+    bool m_normal_useTexture;
+    bool m_baseColor_useTexture;
+    bool m_metallic_useTexture;
+    bool m_specularF0_useTexture;
+    bool m_roughness_useTexture;
+    bool m_emissiveEnabled;
+    bool m_emissive_useTexture;
+    bool m_diffuseOcclusion_useTexture;
+    bool m_specularOcclusion_useTexture;
+    
+#if ENABLE_CLEAR_COAT
+    bool m_clearCoatEnabled;
+    bool m_clearCoat_factor_useTexture;
+    bool m_clearCoat_roughness_useTexture;
+    bool m_clearCoat_normal_useTexture;
+#endif
+    TextureBlendMode m_baseColorTextureBlendMode;
+    float2 m_vertexUv[UvSetCount];
+    float3x3 m_uvMatrix;
+    float3 m_normal;
+    float3 m_tangents[UvSetCount];
+    float3 m_bitangents[UvSetCount];
+    sampler m_sampler;
+    bool m_isFrontFace;
+};
+
+#if ENABLE_CLEAR_COAT
+#include <Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli>
+#endif
+//! Holds the final processed material inputs, after all flags have been checked, textures have been sampled, factors have been applied, etc.
+//! This data is ready to be copied into a Surface and/or LightingData struct for the lighting system to consume.
+class ProcessedMaterialInputs
+{
+    real3 m_normalTS;   //!< Normal in tangent-space
+    real3 m_baseColor;
+    real m_specularF0Factor;
+    real m_metallic;
+    real m_roughness;
+    real3 m_emissiveLighting;
+    real m_diffuseAmbientOcclusion;
+    real m_specularOcclusion;
+#if ENABLE_CLEAR_COAT
+    ClearCoatSurfaceData m_clearCoat;
+#endif
+
+    void InitializeToZero()
+    {
+        m_normalTS = real3(0,0,0);
+        m_baseColor = real3(0,0,0);
+        m_specularF0Factor = 0;
+        m_metallic = 0.0;
+        m_roughness = 0.0;
+        m_emissiveLighting = real3(0,0,0);
+        m_diffuseAmbientOcclusion = 0;
+        m_specularOcclusion = 0;
+#if ENABLE_CLEAR_COAT
+        m_clearCoat.InitializeToZero();
+#endif
+    }
+};
+//! Processes the set of Standard material inputs for a single layer.
+//! The FILL_STANDARD_MATERIAL_INPUTS() macro below can be used to fill the StandardMaterialInputs struct.
+ProcessedMaterialInputs ProcessStandardMaterialInputs(StandardMaterialInputs inputs, float4 uvDxDy = float4(0.0f, 0.0f, 0.0f, 0.0f), bool customDerivatives = false)
+{
+    ProcessedMaterialInputs result;
+
+    float2 transformedUv[UvSetCount];
+    transformedUv[0] = mul(inputs.m_uvMatrix, float3(inputs.m_vertexUv[0], 1.0)).xy;
+    transformedUv[1] = inputs.m_vertexUv[1];
+
+    real3x3 normalUvMatrix = inputs.m_normalMapUvIndex == 0 ? real3x3(inputs.m_uvMatrix) : real3x3(CreateIdentity3x3());
+    result.m_normalTS = GetNormalInputTS(inputs.m_normalMap, inputs.m_sampler, transformedUv[inputs.m_normalMapUvIndex], inputs.m_flipNormalX, inputs.m_flipNormalY, normalUvMatrix, inputs.m_normal_useTexture, real(inputs.m_normalFactor), uvDxDy, customDerivatives);
+
+    real3 sampledBaseColor = GetBaseColorInput(inputs.m_baseColorMap, inputs.m_sampler, transformedUv[inputs.m_baseColorMapUvIndex], real3(inputs.m_baseColor.rgb), inputs.m_baseColor_useTexture, uvDxDy, customDerivatives);
+    result.m_baseColor = BlendBaseColor(sampledBaseColor, real3(inputs.m_baseColor.rgb), real(inputs.m_baseColorFactor), inputs.m_baseColorTextureBlendMode, inputs.m_baseColor_useTexture);
+    result.m_specularF0Factor = GetSpecularInput(inputs.m_specularF0Map, inputs.m_sampler, transformedUv[inputs.m_specularF0MapUvIndex], real(inputs.m_specularF0Factor), inputs.m_specularF0_useTexture, uvDxDy, customDerivatives);
+    result.m_metallic = GetMetallicInput(inputs.m_metallicMap, inputs.m_sampler, transformedUv[inputs.m_metallicMapUvIndex], real(inputs.m_metallicFactor), inputs.m_metallic_useTexture, uvDxDy, customDerivatives);
+    result.m_roughness = GetRoughnessInput(inputs.m_roughnessMap, GetMaterialTextureSampler(), transformedUv[inputs.m_roughnessMapUvIndex], real(inputs.m_roughnessFactor), real(inputs.m_roughnessLowerBound), real(inputs.m_roughnessUpperBound), inputs.m_roughness_useTexture, uvDxDy, customDerivatives);
+    result.m_emissiveLighting = GetEmissiveInput(inputs.m_emissiveMap, inputs.m_sampler, transformedUv[inputs.m_emissiveMapUvIndex], real(inputs.m_emissiveIntensity), real3(inputs.m_emissiveColor.rgb), 0.0, 1.0, inputs.m_emissiveEnabled, inputs.m_emissive_useTexture, uvDxDy, customDerivatives);
+    result.m_diffuseAmbientOcclusion = GetOcclusionInput(inputs.m_diffuseOcclusionMap, inputs.m_sampler, transformedUv[inputs.m_diffuseOcclusionMapUvIndex], real(inputs.m_diffuseOcclusionFactor), inputs.m_diffuseOcclusion_useTexture, uvDxDy, customDerivatives);
+    result.m_specularOcclusion = GetOcclusionInput(inputs.m_specularOcclusionMap, GetMaterialTextureSampler(), transformedUv[inputs.m_specularOcclusionMapUvIndex], real(inputs.m_specularOcclusionFactor), inputs.m_specularOcclusion_useTexture, uvDxDy, customDerivatives);
+
+#if ENABLE_CLEAR_COAT
+    result.m_clearCoat.InitializeToZero();
+    if(inputs.m_clearCoatEnabled)
+    {
+        real3x3 clearCoatUvMatrix = inputs.m_clearCoatNormalMapUvIndex == 0 ? real3x3(inputs.m_uvMatrix) : real3x3(CreateIdentity3x3());
+        GetClearCoatInputs(inputs.m_clearCoatInfluenceMap, transformedUv[inputs.m_clearCoatInfluenceMapUvIndex], real(inputs.m_clearCoatFactor), inputs.m_clearCoat_factor_useTexture,
+                            inputs.m_clearCoatRoughnessMap, transformedUv[inputs.m_clearCoatRoughnessMapUvIndex], real(inputs.m_clearCoatRoughness), inputs.m_clearCoat_roughness_useTexture,
+                            inputs.m_clearCoatNormalMap,    transformedUv[inputs.m_clearCoatNormalMapUvIndex], inputs.m_normal, inputs.m_clearCoat_normal_useTexture, real(inputs.m_clearCoatNormalStrength),
+                            clearCoatUvMatrix, inputs.m_tangents[inputs.m_clearCoatNormalMapUvIndex], inputs.m_bitangents[inputs.m_clearCoatNormalMapUvIndex],
+                            inputs.m_sampler, inputs.m_isFrontFace,
+                            result.m_clearCoat.factor, result.m_clearCoat.roughness, result.m_clearCoat.normal, uvDxDy, customDerivatives);
+    }
+#endif
+    return result;
+}
+//! Fills a StandardMaterialInputs struct with data from the MaterialSrg, shader options, and local vertex data.
+#define FILL_STANDARD_MATERIAL_INPUTS(inputs, srgLayerPrefix, optionsLayerPrefix, blendWeight)                     \
+    inputs.m_sampler = GetMaterialTextureSampler();                                                                \
+    inputs.m_vertexUv = uvs;                                                                                       \
+    inputs.m_uvMatrix = srgLayerPrefix##m_uvMatrix;                                                                \
+    inputs.m_normal = normalWS;                                                                                    \
+    inputs.m_tangents = tangents;                                                                                  \
+    inputs.m_bitangents = bitangents;                                                                              \
+    inputs.m_isFrontFace = isFrontFace;                                                                            \
+                                                                                                                   \
+    inputs.m_normalMapUvIndex = srgLayerPrefix##m_normalMapUvIndex;                                                \
+    inputs.m_normalMap = GetMaterialTexture(srgLayerPrefix##m_normalMap);                                          \
+    inputs.m_flipNormalX = srgLayerPrefix##m_flipNormalX;                                                          \
+    inputs.m_flipNormalY = srgLayerPrefix##m_flipNormalY;                                                          \
+    inputs.m_normal_useTexture = optionsLayerPrefix##o_normal_useTexture;                                          \
+    inputs.m_normalFactor = srgLayerPrefix##m_normalFactor * blendWeight;                                          \
+    inputs.m_baseColorMap = GetMaterialTexture(srgLayerPrefix##m_baseColorMap);                                    \
+    inputs.m_baseColorMapUvIndex = srgLayerPrefix##m_baseColorMapUvIndex;                                          \
+    inputs.m_baseColor = srgLayerPrefix##m_baseColor.rgb;                                                              \
+    inputs.m_baseColor_useTexture = optionsLayerPrefix##o_baseColor_useTexture;                                    \
+    inputs.m_baseColorFactor = srgLayerPrefix##m_baseColorFactor;                                                  \
+    inputs.m_baseColorTextureBlendMode = optionsLayerPrefix##o_baseColorTextureBlendMode;                          \
+    inputs.m_metallicMap = GetMaterialTexture(srgLayerPrefix##m_metallicMap);                                      \
+    inputs.m_metallicMapUvIndex = srgLayerPrefix##m_metallicMapUvIndex;                                            \
+    inputs.m_metallicFactor = srgLayerPrefix##m_metallicFactor;                                                    \
+    inputs.m_metallic_useTexture = optionsLayerPrefix##o_metallic_useTexture;                                      \
+    inputs.m_specularF0Map = GetMaterialTexture(srgLayerPrefix##m_specularF0Map);                                  \
+    inputs.m_specularF0MapUvIndex = srgLayerPrefix##m_specularF0MapUvIndex;                                        \
+    inputs.m_specularF0Factor = srgLayerPrefix##m_specularF0Factor;                                                \
+    inputs.m_specularF0_useTexture = optionsLayerPrefix##o_specularF0_useTexture;                                  \
+    inputs.m_roughnessMap = GetMaterialTexture(srgLayerPrefix##m_roughnessMap);                                    \
+    inputs.m_roughnessMapUvIndex = srgLayerPrefix##m_roughnessMapUvIndex;                                          \
+    inputs.m_roughnessFactor = srgLayerPrefix##m_roughnessFactor;                                                  \
+    inputs.m_roughnessLowerBound = srgLayerPrefix##m_roughnessLowerBound;                                          \
+    inputs.m_roughnessUpperBound = srgLayerPrefix##m_roughnessUpperBound;                                          \
+    inputs.m_roughness_useTexture = optionsLayerPrefix##o_roughness_useTexture;                                    \
+                                                                                                                   \
+    inputs.m_emissiveMap = GetMaterialTexture(srgLayerPrefix##m_emissiveMap);                                      \
+    inputs.m_emissiveMapUvIndex = srgLayerPrefix##m_emissiveMapUvIndex;                                            \
+    inputs.m_emissiveIntensity = srgLayerPrefix##m_emissiveIntensity;                                              \
+    inputs.m_emissiveColor = srgLayerPrefix##m_emissiveColor.rgb;                                                  \
+    inputs.m_emissiveAffectedByAlpha = srgLayerPrefix##m_emissiveAffectedByAlpha;                                  \
+    inputs.m_emissiveEnabled = optionsLayerPrefix##o_emissiveEnabled;                                              \
+    inputs.m_emissive_useTexture = optionsLayerPrefix##o_emissive_useTexture;                                      \
+                                                                                                                   \
+    inputs.m_diffuseOcclusionMap = GetMaterialTexture(srgLayerPrefix##m_diffuseOcclusionMap);                      \
+    inputs.m_diffuseOcclusionMapUvIndex = srgLayerPrefix##m_diffuseOcclusionMapUvIndex;                            \
+    inputs.m_diffuseOcclusionFactor = srgLayerPrefix##m_diffuseOcclusionFactor;                                    \
+    inputs.m_diffuseOcclusion_useTexture = optionsLayerPrefix##o_diffuseOcclusion_useTexture;                      \
+                                                                                                                   \
+    inputs.m_specularOcclusionMap = GetMaterialTexture(srgLayerPrefix##m_specularOcclusionMap);                    \
+    inputs.m_specularOcclusionMapUvIndex = srgLayerPrefix##m_specularOcclusionMapUvIndex;                          \
+    inputs.m_specularOcclusionFactor = srgLayerPrefix##m_specularOcclusionFactor;                                  \
+    inputs.m_specularOcclusion_useTexture = optionsLayerPrefix##o_specularOcclusion_useTexture;                    
+                                                                                                                   
+         
+#if ENABLE_CLEAR_COAT
+#define FILL_STANDARD_MATERIAL_INPUTS_CLEAR_COAT(inputs, srgLayerPrefix, optionsLayerPrefix, blendWeight)        \
+    inputs.m_clearCoatEnabled = o_clearCoat_feature_enabled && optionsLayerPrefix##o_clearCoat_enabled;          \
+    inputs.m_clearCoatInfluenceMap = GetMaterialTexture(srgLayerPrefix##m_clearCoatInfluenceMap);                \
+    inputs.m_clearCoatInfluenceMapUvIndex = srgLayerPrefix##m_clearCoatInfluenceMapUvIndex;                      \
+    inputs.m_clearCoatFactor = srgLayerPrefix##m_clearCoatFactor;                                                \
+    inputs.m_clearCoat_factor_useTexture = optionsLayerPrefix##o_clearCoat_factor_useTexture;                    \
+    inputs.m_clearCoatRoughnessMap = GetMaterialTexture(srgLayerPrefix##m_clearCoatRoughnessMap);                \
+    inputs.m_clearCoatRoughnessMapUvIndex = srgLayerPrefix##m_clearCoatRoughnessMapUvIndex;                      \
+    inputs.m_clearCoatRoughness = srgLayerPrefix##m_clearCoatRoughness;                                          \
+    inputs.m_clearCoat_roughness_useTexture = optionsLayerPrefix##o_clearCoat_roughness_useTexture;              \
+    inputs.m_clearCoatNormalMap = GetMaterialTexture(srgLayerPrefix##m_clearCoatNormalMap);                      \
+    inputs.m_clearCoatNormalMapUvIndex = srgLayerPrefix##m_clearCoatNormalMapUvIndex;                            \
+    inputs.m_clearCoat_normal_useTexture = optionsLayerPrefix##o_clearCoat_normal_useTexture;                    \
+    inputs.m_clearCoatNormalStrength = srgLayerPrefix##m_clearCoatNormalStrength;
+#else
+#define FILL_STANDARD_MATERIAL_INPUTS_CLEAR_COAT(inputs, srgLayerPrefix, optionsLayerPrefix, blendWeight)
+#endif
+
+
+
+Surface EvaluateSurface_StandardMultilayerPBR(
+    const MaterialParameters params,
+    float3 positionWS,
+    float3 normalWS,
+    float3 tangents[UvSetCount],
+    float3 bitangents[UvSetCount],
+    float2 uvs[UvSetCount],
+    bool isFrontFace,
+    bool isDisplacementClipped,
+    real3 vertexBlendMask,
+    float4 uvDxDy,
+    bool customDerivatives)
+{
+    LayerBlendSource blendSource = GetFinalLayerBlendSource();
+    
+    // ------- Debug Modes -------
+    if(o_debugDrawMode == DebugDrawMode::BlendMask)
+    {
+        real3 blendMaskValues = GetApplicableBlendMaskValues(params, blendSource, uvs[params.m_blendMaskUvIndex], vertexBlendMask, uvDxDy, customDerivatives);
+        return MakeDebugSurface(positionWS, normalWS, real3(blendMaskValues));
+    }
+
+    if(o_debugDrawMode == DebugDrawMode::Displacement)
+    {
+        real startDepth = real(-params.m_displacementMax);
+        real stopDepth = real(-params.m_displacementMin);
+        real depth = GetNormalizedDepth(params, GetMaterialTexture(params.m_layer1_m_heightmap), GetMaterialTextureSampler(), startDepth, stopDepth, uvs[params.m_parallaxUvIndex], real2(0,0), real2(0,0));
+        real height = 1 - saturate(depth);
+        return MakeDebugSurface(positionWS, normalWS, real3(height,height,height));
+    }
+
+    if(o_debugDrawMode == DebugDrawMode::FinalBlendWeights)
+    {
+        real3 blendWeights;
+        if (customDerivatives)
+        {
+            blendWeights = GetBlendWeights(params, blendSource, uvs[params.m_blendMaskUvIndex], vertexBlendMask, uvDxDy, customDerivatives);
+        }
+        else
+        {
+            blendWeights = GetBlendWeights(params, blendSource, uvs[params.m_blendMaskUvIndex], vertexBlendMask, float4(0.0f, 0.0f, 0.0f, 0.0f), false);
+        }
+        return MakeDebugSurface(positionWS, normalWS, real3(blendWeights));
+    }
+    // ------- Calculate Layer Blend Mask Values -------
+
+    // Now that any parallax has been calculated, we calculate the blend factors for any layers that are impacted by the parallax.
+    real3 blendWeights;
+    if (customDerivatives)
+    {
+        blendWeights = real3(GetBlendWeights(params, blendSource, uvs[params.m_blendMaskUvIndex], vertexBlendMask, uvDxDy, customDerivatives));
+    }
+    else
+    {
+        blendWeights = real3(GetBlendWeights(params, blendSource, uvs[params.m_blendMaskUvIndex], vertexBlendMask, float4(0.0f, 0.0f, 0.0f, 0.0f), false));
+    }
+    
+    
+    // ------- Layer 1 (base layer) -----------
+    ProcessedMaterialInputs lightingInputLayer1;
+    if(blendWeights.r > 0)
+    {
+        StandardMaterialInputs inputs;
+        FILL_STANDARD_MATERIAL_INPUTS(inputs, params.m_layer1_, o_layer1_, blendWeights.r)
+        FILL_STANDARD_MATERIAL_INPUTS_CLEAR_COAT(inputs, params.m_layer1_, o_layer1_, blendWeights.r)
+        lightingInputLayer1 = ProcessStandardMaterialInputs(inputs, uvDxDy, customDerivatives);
+    }
+    else
+    {
+        lightingInputLayer1.InitializeToZero();
+        blendWeights.r = 0;
+    }
+
+    // ----------- Layer 2 -----------
+    ProcessedMaterialInputs lightingInputLayer2; 
+    if(o_layer2_enabled && blendWeights.g > 0)
+    {
+        StandardMaterialInputs inputs;
+        FILL_STANDARD_MATERIAL_INPUTS(inputs, params.m_layer2_, o_layer2_, blendWeights.g)
+        FILL_STANDARD_MATERIAL_INPUTS_CLEAR_COAT(inputs, params.m_layer2_, o_layer2_, blendWeights.g)
+        lightingInputLayer2 = ProcessStandardMaterialInputs(inputs, uvDxDy, customDerivatives);
+    }
+    else
+    {
+        lightingInputLayer2.InitializeToZero();
+        blendWeights.g = 0;
+    }
+
+    // ----------- Layer 3 -----------
+    ProcessedMaterialInputs lightingInputLayer3;
+    if(o_layer3_enabled && blendWeights.b > 0)
+    {
+        StandardMaterialInputs inputs;
+        FILL_STANDARD_MATERIAL_INPUTS(inputs, params.m_layer3_, o_layer3_, blendWeights.b)
+        FILL_STANDARD_MATERIAL_INPUTS_CLEAR_COAT(inputs, params.m_layer3_, o_layer3_, blendWeights.b)
+        lightingInputLayer3 = ProcessStandardMaterialInputs(inputs, uvDxDy, customDerivatives);
+    }
+    else
+    {
+        lightingInputLayer3.InitializeToZero();
+        blendWeights.b = 0;
+    }
+    // ------- Combine all layers ---------
+
+    Surface surface;
+    surface.position = positionWS;
+    // ------- Combine Normals ---------
+    real3 normalTS = real3(0,0,1);
+    if(blendWeights.r > 0)
+    {
+        normalTS = lightingInputLayer1.m_normalTS;
+    }
+    if(o_layer2_enabled && blendWeights.g > 0)
+    {
+        normalTS = ReorientTangentSpaceNormal(normalTS, lightingInputLayer2.m_normalTS);
+    }
+    if(o_layer3_enabled && blendWeights.b > 0)
+    {
+        normalTS = ReorientTangentSpaceNormal(normalTS, lightingInputLayer3.m_normalTS);
+    }
+    // [GFX TODO][ATOM-14591]: This will only work if the normal maps all use the same UV stream. We would need to add support for having them in different UV streams.
+    surface.vertexNormal = normalWS;
+    surface.normal = normalize(TangentSpaceToWorld(normalTS, normalWS, tangents[params.m_parallaxUvIndex], bitangents[params.m_parallaxUvIndex]));
+    
+    // ------- Combine Albedo, roughness, specular, roughness ---------
+    real3 baseColor = BlendLayers(lightingInputLayer1.m_baseColor, lightingInputLayer2.m_baseColor, lightingInputLayer3.m_baseColor, blendWeights);
+    real specularF0Factor = BlendLayers(lightingInputLayer1.m_specularF0Factor, lightingInputLayer2.m_specularF0Factor, lightingInputLayer3.m_specularF0Factor, blendWeights);
+    real metallic = BlendLayers(lightingInputLayer1.m_metallic, lightingInputLayer2.m_metallic, lightingInputLayer3.m_metallic, blendWeights);
+
+    if(o_parallax_highlightClipping && isDisplacementClipped)
+    {
+        ApplyParallaxClippingHighlight(baseColor);
+    }
+    surface.SetAlbedoAndSpecularF0(baseColor, specularF0Factor, metallic);
+    surface.roughnessLinear = BlendLayers(lightingInputLayer1.m_roughness, lightingInputLayer2.m_roughness, lightingInputLayer3.m_roughness, blendWeights);
+    surface.CalculateRoughnessA();
+
+    // ------- Init and Combine Lighting Data -------
+    surface.emissiveLighting = BlendLayers(lightingInputLayer1.m_emissiveLighting, lightingInputLayer2.m_emissiveLighting, lightingInputLayer3.m_emissiveLighting, blendWeights);
+    surface.specularOcclusion = BlendLayers(lightingInputLayer1.m_specularOcclusion, lightingInputLayer2.m_specularOcclusion, lightingInputLayer3.m_specularOcclusion, blendWeights);
+    surface.diffuseAmbientOcclusion = BlendLayers(lightingInputLayer1.m_diffuseAmbientOcclusion, lightingInputLayer2.m_diffuseAmbientOcclusion, lightingInputLayer3.m_diffuseAmbientOcclusion, blendWeights);
+    // ------- Combine Clearcoat -------
+#if ENABLE_CLEAR_COAT
+    if(o_clearCoat_feature_enabled)
+    {
+        surface.clearCoat.factor = BlendLayers(lightingInputLayer1.m_clearCoat.factor, lightingInputLayer2.m_clearCoat.factor, lightingInputLayer3.m_clearCoat.factor, blendWeights);
+        surface.clearCoat.roughness = BlendLayers(lightingInputLayer1.m_clearCoat.roughness, lightingInputLayer2.m_clearCoat.roughness, lightingInputLayer3.m_clearCoat.roughness, blendWeights);
+        // [GFX TODO][ATOM-14592] This is not the right way to blend the normals. We need to use ReorientTangentSpaceNormal(), and that requires GetClearCoatInputs() to return the normal in TS instead of WS.
+        surface.clearCoat.normal = BlendLayers(lightingInputLayer1.m_clearCoat.normal, lightingInputLayer2.m_clearCoat.normal, lightingInputLayer3.m_clearCoat.normal, blendWeights);
+        surface.clearCoat.normal = normalize(surface.clearCoat.normal);
+    
+        ApplyClearCoatToSpecularF0(surface.specularF0, surface.clearCoat.factor);
+    }
+#endif
+    return surface;
+}
+// helper function to keep compatible with the previous version
+// because dxc compiler doesn't allow default parameters on functions with overloads
+Surface EvaluateSurface_StandardMultilayerPBR(
+    const MaterialParameters params,
+    float3 positionWS,
+    real3 normalWS,
+    float3 tangents[UvSetCount],
+    float3 bitangents[UvSetCount],
+    float2 uvs[UvSetCount],
+    bool isFrontFace,
+    bool isDisplacementClipped,
+    real3 vertexBlendMask)
+{
+    return EvaluateSurface_StandardMultilayerPBR(
+        params,
+        positionWS,
+        normalWS,
+        tangents,
+        bitangents,
+        uvs,
+        isFrontFace,
+        isDisplacementClipped,
+        vertexBlendMask,
+        float4(0.0f, 0.0f, 0.0f, 0.0f),
+        false);
+}
+
+Surface EvaluateSurface_StandardMultilayerPBR(VsOutput IN, PixelGeometryData geoData, const MaterialParameters params, float4 uvDxDy, bool customDerivatives)
+{
+    return EvaluateSurface_StandardMultilayerPBR(
+        params,
+        geoData.positionWS,
+        geoData.vertexNormal,
+        geoData.tangents,
+        geoData.bitangents,
+        geoData.uvs,
+        geoData.isFrontFace,
+        geoData.isDisplacementClipped,
+        geoData.m_vertexBlendMask,
+        uvDxDy,
+        customDerivatives);
+}
+
+Surface EvaluateSurface_StandardMultilayerPBR(VsOutput IN, PixelGeometryData geoData, const MaterialParameters params)
+{
+    return EvaluateSurface_StandardMultilayerPBR(
+        params,
+        geoData.positionWS,
+        geoData.vertexNormal,
+        geoData.tangents,
+        geoData.bitangents,
+        geoData.uvs,
+        geoData.isFrontFace,
+        geoData.isDisplacementClipped,
+        geoData.m_vertexBlendMask,
+        float4(0.0f, 0.0f, 0.0f, 0.0f),
+        false);
+}

+ 17 - 0
Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_VertexData.azsli

@@ -0,0 +1,17 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+// by default the Vertex-Data is empty, so enable the parts we need
+#define MATERIAL_USES_VERTEX_POSITION 1
+#define MATERIAL_USES_VERTEX_POSITIONWS 1
+#define MATERIAL_USES_VERTEX_NORMAL 1
+#define MATERIAL_USES_VERTEX_TANGENT 1
+#define MATERIAL_USES_VERTEX_UV 1
+#define MATERIAL_USES_VERTEX_BLENDMASK 1  // multilayer PBR needs a blend Mask

+ 58 - 0
Gems/Atom/Feature/Common/Assets/Shaders/Materials/StandardMultilayerPBR/StandardMultilayerPBR_VertexEval.azsli

@@ -0,0 +1,58 @@
+/*
+ * 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
+ *
+ */
+
+#pragma once
+
+#ifndef EvaluateVertexGeometry
+#define EvaluateVertexGeometry  EvaluateVertexGeometry_StandardMultilayerPBR
+#endif
+
+#include <Atom/Feature/Common/Assets/Shaders/Materials/BasePBR/BasePBR_VertexEval.azsli>
+    
+VsOutput EvaluateVertexGeometry_StandardMultilayerPBR(
+    const MaterialParameters params,
+    float3 position,
+    float3 normal,
+    float4 tangent,
+    float2 uv0,
+    float2 uv1,
+    float3 vertexBlendMask,
+    VsSystemValues SV)
+{
+    VsOutput output = EvaluateVertexGeometry_BasePBR(params, position, normal, tangent, uv0, uv1, SV, false, float4(1.0f, 1.0f, 1.0f, 1.0f));
+
+#if MATERIAL_USES_VERTEX_BLENDMASK
+    if(o_blendMask_isBound)
+    {
+        output.blendFactors = float4(vertexBlendMask, 0);
+    }
+    else
+    {
+        output.blendFactors = float4(0,0,0,0);
+    }
+#endif // MATERIAL_USES_VERTEX_BLENDMASK
+
+    return output;
+}
+
+VsOutput EvaluateVertexGeometry_StandardMultilayerPBR(VsInput IN, VsSystemValues SV, const MaterialParameters params)
+{
+    return EvaluateVertexGeometry_StandardMultilayerPBR(
+        params,
+        IN.position,
+        IN.normal,
+        IN.tangent,
+        IN.uv0,
+        IN.uv1,
+#if MATERIAL_USES_VERTEX_BLENDMASK
+        IN.m_optional_blendMask.rgb,
+#else
+        float3(0, 0, 0),
+#endif
+        SV);
+}

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.