Browse Source

Got the deferred prototype working again with latest dev and latest material pipeline implementation.
I also updated the appearance of the deferred lighting watermark so it will show up better over surfaces that are already somewhat pink.

Signed-off-by: santorac <[email protected]>

santorac 2 years ago
parent
commit
52ec05ae39

+ 14 - 7
Materials/Pipelines/PrototypeDeferredPipeline/DeferredMaterialPass.azsli

@@ -7,6 +7,7 @@
  */
 
 #include <viewsrg.srgi>
+#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
 #include <Atom/Features/PBR/DefaultObjectSrg.azsli>
 //#include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
 //#include <Atom/Features/Pipeline/Forward/ForwardPassOutput.azsli>
@@ -33,7 +34,7 @@ struct VSOutput
     float3 m_worldPosition : UV0;
 };
 
-#include <Atom/Features/Vertex/VertexHelper.azsli>
+//#include <Atom/Features/Vertex/VertexHelper.azsli>
 
 void MaterialFunction_AdjustLocalPosition(inout float3 localPosition);
 void MaterialFunction_AdjustWorldPosition(inout float3 worldPosition);
@@ -41,7 +42,7 @@ void MaterialFunction_AdjustSurface(inout Surface outSurface);
 
 VSOutput MaterialVS(VSInput IN)
 {
-    VSOutput OUT;
+    VSOutput output;
  
     MaterialFunction_AdjustLocalPosition(IN.m_position);
 
@@ -49,9 +50,14 @@ VSOutput MaterialVS(VSInput IN)
  
     MaterialFunction_AdjustWorldPosition(worldPosition);
 
-    VertexHelper(IN, OUT, worldPosition);
+    output.m_worldPosition = worldPosition;
+    output.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(worldPosition, 1.0));
+    
+    output.m_tangent = IN.m_tangent.xyz;
+    output.m_bitangent = IN.m_bitangent;
+    output.m_normal = IN.m_normal;
 
-    return OUT;
+    return output;
 }
 
 struct DeferredMaterialOutput
@@ -61,6 +67,9 @@ struct DeferredMaterialOutput
     float4 m_normal : SV_Target2;
 };
 
+option bool o_enableIBL = true;
+option bool o_specularF0_enableMultiScatterCompensation = true;
+
 #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
 
 DeferredMaterialOutput MaterialPS(VSOutput IN)
@@ -95,9 +104,7 @@ DeferredMaterialOutput MaterialPS(VSOutput IN)
     OUT.m_roughnessMetal = float4(surface.roughnessLinear, surface.metallic, 0, 0);
     OUT.m_normal.rgb = EncodeNormalSignedOctahedron(surface.normal);
     
-    //TODO: switch this after o_enableIBL is hooked up
-    //OUT.m_normal.a = EncodeUnorm2BitFlags(o_enableIBL, o_specularF0_enableMultiScatterCompensation);
-    OUT.m_normal.a = EncodeUnorm2BitFlags(true, o_specularF0_enableMultiScatterCompensation);
+    OUT.m_normal.a = EncodeUnorm2BitFlags(o_enableIBL, o_specularF0_enableMultiScatterCompensation);
 
     return OUT;
 }

+ 4 - 4
Materials/Pipelines/PrototypeDeferredPipeline/DeferredPipeline.materialpipeline

@@ -5,12 +5,12 @@
             "azsli": "Materials/Pipelines/PrototypeDeferredPipeline/DeferredMaterialPass.azsli"
         },
         {
-            "shader": "./DepthPass.shader.template",
-            "azsli": "Materials/Pipelines/PrototypeDeferredPipeline/DepthPass.azsli"
+            "shader": "Materials/Pipelines/Common/DepthPass.shader.template",
+            "azsli": "Materials/Pipelines/Common/DepthPass.azsli"
         },
         {
-            "shader": "./ShadowmapPass.shader.template",
-            "azsli": "Materials/Pipelines/PrototypeDeferredPipeline/ShadowmapPass.azsli"
+            "shader": "Materials/Pipelines/Common/ShadowmapPass.shader.template",
+            "azsli": "Materials/Pipelines/Common/ShadowmapPass.azsli"
         }
     ]
 }

+ 0 - 41
Materials/Pipelines/PrototypeDeferredPipeline/DepthPass.azsli

@@ -1,41 +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 <Atom/Features/PBR/DefaultObjectSrg.azsli>
-#include <viewsrg.srgi>
-
-struct VSInput
-{
-    float3 m_position : POSITION;
-};
- 
-struct VSDepthOutput
-{
-    precise float4 m_position : SV_Position;
-};
-
-void MaterialFunction_AdjustLocalPosition(inout float3 localPosition);
-void MaterialFunction_AdjustWorldPosition(inout float3 worldPosition);
-
-VSDepthOutput DepthPassVS(VSInput IN)
-{
-    VSDepthOutput OUT;
- 
-    MaterialFunction_AdjustLocalPosition(IN.m_position);
-
-    float4x4 objectToWorld = ObjectSrg::GetWorldMatrix();
-    float3 worldPosition = mul(objectToWorld, float4(IN.m_position, 1.0)).xyz;
-    
-    MaterialFunction_AdjustWorldPosition(worldPosition);
-
-    OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(worldPosition, 1.0));
-
-    return OUT;
-}
-
-

+ 0 - 20
Materials/Pipelines/PrototypeDeferredPipeline/DepthPass.shader.template

@@ -1,20 +0,0 @@
-{
-    "Source" : "INSERT_AZSL_HERE",
-
-    "DepthStencilState" : { 
-        "Depth" : { "Enable" : true, "CompareFunc" : "GreaterEqual" }
-    },
-
-    "ProgramSettings" : 
-    {
-        "EntryPoints":
-        [
-            {
-                "name": "DepthPassVS",
-                "type" : "Vertex"
-            }
-        ] 
-    },
-
-    "DrawList" : "depth"
-}

+ 0 - 40
Materials/Pipelines/PrototypeDeferredPipeline/ShadowmapPass.azsli

@@ -1,40 +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 <Atom/Features/PBR/DefaultObjectSrg.azsli>
-#include <scenesrg.srgi>
-#include <viewsrg.srgi>
-
-struct VertexInput
-{
-    float3 m_position : POSITION;
-};
-
-struct VertexOutput
-{
-    float4 m_position : SV_Position;
-};
-
-void MaterialFunction_AdjustLocalPosition(inout float3 localPosition);
-void MaterialFunction_AdjustWorldPosition(inout float3 worldPosition);
-
-VertexOutput MainVS(VertexInput input)
-{
-    const float4x4 worldMatrix = ObjectSrg::GetWorldMatrix();
-    VertexOutput output;
-    
-    MaterialFunction_AdjustLocalPosition(input.m_position);
-
-    float3 worldPosition = mul(worldMatrix, float4(input.m_position, 1.0)).xyz;
-    
-    MaterialFunction_AdjustWorldPosition(worldPosition);
-
-    output.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(worldPosition, 1.0));
-
-    return output;
-}

+ 0 - 28
Materials/Pipelines/PrototypeDeferredPipeline/ShadowmapPass.shader.template

@@ -1,28 +0,0 @@
-{
-    "Source" : "INSERT_AZSL_HERE",
-
-    "DepthStencilState" : { 
-        "Depth" : { "Enable" : true, "CompareFunc" : "LessEqual" }
-    },
-
-    "DrawList" : "shadow",
-
-    // Note that lights now expose their own bias controls.
-    // It may be worth increasing their default values in the future and reducing the depthBias values encoded here.
-    "RasterState" :
-    {
-        "depthBias" : "10",
-        "depthBiasSlopeScale" : "4"        
-    },
-
-    "ProgramSettings":
-    {
-      "EntryPoints":
-      [
-        {
-          "name": "MainVS",
-          "type": "Vertex"
-        }
-      ]
-    }
-}

+ 21 - 3
Passes/PrototypeDeferredPipeline/DeferredLighting.azsl

@@ -31,6 +31,16 @@ ShaderResourceGroup PassSrg : SRG_PerPass
         AddressW = Clamp;
     };
     
+    Sampler PointSampler
+    {
+        MinFilter = Point;
+        MagFilter = Point;
+        MipFilter = Point;
+        AddressU = Clamp;
+        AddressV = Clamp;
+        AddressW = Clamp;
+    };
+
     Texture2D<uint4> m_tileLightData;
     StructuredBuffer<uint> m_lightListRemapped;
     //Texture2D<float> m_linearDepthTexture;
@@ -60,6 +70,11 @@ struct PSOutput
     //float4 m_normal : SV_Target4;            //!< RGB10 = EncodeNormalSignedOctahedron(worldNormal), A2 = Flags (IBL/Multiscatter enabled)
 };
 
+// Since the visual results of the deferred pipeline are (in theory) identical to the results
+// of the main pipeline, this option can be enabled to draw a watermark that confirms what
+// you are seeing is actually the deferred pipeline.
+option bool o_deferredPipelineWatermark = true;
+
 PSOutput MainPS(VSOutput IN, in uint sampleIndex : SV_SampleIndex)
 {
     uint2 screenCoords = IN.m_position.xy;
@@ -73,10 +88,13 @@ PSOutput MainPS(VSOutput IN, in uint sampleIndex : SV_SampleIndex)
     float2 roughnessMetallic = PassSrg::m_roughnessMetal.Load(screenCoords, sampleIndex).rg;
     float3 baseColor = PassSrg::m_baseColor.Load(screenCoords, sampleIndex).rgb;
     
-    // TODO: Remove this, it's temporary to help confirm the deferred pipeline is running.
-    if(abs(IN.m_texCoord.x-0.5) < 0.01 || abs(IN.m_texCoord.y-0.5) < 0.01) 
+    if(o_deferredPipelineWatermark)
     {
-        baseColor *= float3(1,0,1); 
+        if(abs(IN.m_texCoord.x-0.5) < 0.01 || abs(IN.m_texCoord.y-0.5) < 0.01) 
+        {
+            float t = sin(50 * (IN.m_texCoord.x + IN.m_texCoord.y)) * 0.5 + 0.5;
+            baseColor *= lerp(float3(1,0.2,1), float3(0.5,1,1), t); 
+        }
     }
 
     // Copied from Gems\Atom\Feature\Common\Assets\Materials\Pipelines\MainPipeline\ForwardPass.azsli

+ 0 - 1
Registry/material_pipelines.setreg

@@ -5,7 +5,6 @@
                 "MaterialPipelineFiles": [
                     "@gemroot:Atom_Feature_Common@/Assets/Materials/Pipelines/MainPipeline/MainPipeline.materialpipeline",
                     "@gemroot:Atom_Feature_Common@/Assets/Materials/Pipelines/LowEndPipeline/LowEndPipeline.materialpipeline",
-                    // TODO: Figure out how to better support relative paths
                     "@projectroot@/Materials/Pipelines/PrototypeDeferredPipeline/DeferredPipeline.materialpipeline"
                 ]
             }