New forward subsurface pass

This commit is contained in:
antonmic
2021-04-18 03:09:20 -07:00
parent 0d412abe52
commit b6c4c07fc5
16 changed files with 318 additions and 111 deletions
@@ -17,7 +17,7 @@
#include <Atom/Features/PBR/ForwardPassSrg.azsli>
// Pass Output
#include <Atom/Features/PBR/ForwardPassOutput.azsli>
#include <Atom/Features/PBR/ForwardSubsurfacePassOutput.azsli>
// Utility
#include <Atom/Features/ColorManagement/TransformColor.azsli>
@@ -50,5 +50,5 @@
]
},
"DrawList" : "forward"
"DrawList" : "forwardWithSubsurfaceOutput"
}
@@ -17,7 +17,7 @@
#include <Atom/Features/PBR/ForwardPassSrg.azsli>
// Pass Output
#include <Atom/Features/PBR/ForwardPassOutput.azsli>
#include <Atom/Features/PBR/ForwardSubsurfacePassOutput.azsli>
// Utility
#include <Atom/Features/ColorManagement/TransformColor.azsli>
@@ -320,15 +320,6 @@ PbrLightingOutput SkinPS_Common(VSOutput IN)
surface.transmission.thickness = transmissionTintThickness.w;
surface.transmission.transmissionParams = MaterialSrg::m_transmissionParams;
// ------- Anisotropy -------
if (o_enableAnisotropy)
{
const float anisotropyAngle = 0.0f;
const float anisotropyFactor = 0.0f;
surface.anisotropy.Init(surface.normal, tangents[0], bitangents[0], anisotropyAngle, anisotropyFactor, surface.roughnessA);
}
// ------- Lighting Data -------
LightingData lightingData;
@@ -42,5 +42,5 @@
]
},
"DrawList" : "forward"
"DrawList" : "forwardWithSubsurfaceOutput"
}
@@ -296,15 +296,6 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
surface.transmission.thickness = transmissionTintThickness.w;
surface.transmission.transmissionParams = MaterialSrg::m_transmissionParams;
// ------- Anisotropy -------
if (o_enableAnisotropy)
{
const float anisotropyAngle = 0.0f;
const float anisotropyFactor = 0.0f;
surface.anisotropy.Init(surface.normal, tangents[0], bitangents[0], anisotropyAngle, anisotropyFactor, surface.roughnessA);
}
// ------- Lighting Data -------
LightingData lightingData;
@@ -456,7 +447,6 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
// Pack factor and quality, drawback: because of precision limit of float16 cannot represent exact 1, maximum representable value is 0.9961
uint factorAndQuality = dot(round(float2(saturate(surfaceScatteringFactor), MaterialSrg::m_subsurfaceScatteringQuality) * 255), float2(256, 1));
lightingOutput.m_diffuseColor.w = factorAndQuality * (o_enableSubsurfaceScattering ? 1.0 : -1.0);
lightingOutput.m_scatterDistance = MaterialSrg::m_scatterDistance;
}
@@ -476,7 +466,6 @@ ForwardPassOutputWithDepth ForwardPassPS(VSOutput IN, bool isFrontFace : SV_IsFr
OUT.m_albedo = lightingOutput.m_albedo;
OUT.m_normal = lightingOutput.m_normal;
OUT.m_clearCoatNormal = lightingOutput.m_clearCoatNormal;
OUT.m_scatterDistance = lightingOutput.m_scatterDistance;
OUT.m_depth = depth;
return OUT;
}
@@ -495,7 +484,6 @@ ForwardPassOutput ForwardPassPS_EDS(VSOutput IN, bool isFrontFace : SV_IsFrontFa
OUT.m_albedo = lightingOutput.m_albedo;
OUT.m_normal = lightingOutput.m_normal;
OUT.m_clearCoatNormal = lightingOutput.m_clearCoatNormal;
OUT.m_scatterDistance = lightingOutput.m_scatterDistance;
return OUT;
}
@@ -202,15 +202,6 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
surface.transmission.thickness = transmissionTintThickness.w;
surface.transmission.transmissionParams = MaterialSrg::m_transmissionParams;
// ------- Anisotropy -------
if (o_enableAnisotropy)
{
const float anisotropyAngle = 0.0f;
const float anisotropyFactor = 0.0f;
surface.anisotropy.Init(surface.normal, tangents[0], bitangents[0], anisotropyAngle, anisotropyFactor, surface.roughnessA);
}
// ------- Lighting Data -------
LightingData lightingData;
@@ -329,7 +320,6 @@ ForwardPassOutputWithDepth StandardPbr_ForwardPassPS(VSOutput IN, bool isFrontFa
OUT.m_albedo = lightingOutput.m_albedo;
OUT.m_normal = lightingOutput.m_normal;
OUT.m_clearCoatNormal = lightingOutput.m_clearCoatNormal;
OUT.m_scatterDistance = lightingOutput.m_scatterDistance;
OUT.m_depth = depth;
return OUT;
}
@@ -348,7 +338,6 @@ ForwardPassOutput StandardPbr_ForwardPassPS_EDS(VSOutput IN, bool isFrontFace :
OUT.m_albedo = lightingOutput.m_albedo;
OUT.m_normal = lightingOutput.m_normal;
OUT.m_clearCoatNormal = lightingOutput.m_clearCoatNormal;
OUT.m_scatterDistance = lightingOutput.m_scatterDistance;
return OUT;
}
@@ -164,22 +164,6 @@
},
"LoadAction": "Clear"
}
},
{
"Name": "ScatterDistanceOutput",
"SlotType": "Output",
"ScopeAttachmentUsage": "RenderTarget",
"LoadStoreAction": {
"ClearValue": {
"Value": [
0.0,
0.0,
0.0,
0.0
]
},
"LoadAction": "Clear"
}
}
],
"ImageAttachments": [
@@ -291,23 +275,6 @@
"Format": "R16G16B16A16_FLOAT",
"SharedQueueMask": "Graphics"
}
},
{
"Name": "ScatterDistanceImage",
"SizeSource": {
"Source": {
"Pass": "Parent",
"Attachment": "SwapChainOutput"
}
},
"MultisampleSource": {
"Pass": "This",
"Attachment": "DepthStencilInputOutput"
},
"ImageDescriptor": {
"Format": "R11G11B10_FLOAT",
"SharedQueueMask": "Graphics"
}
}
],
"Connections": [
@@ -359,13 +326,6 @@
"Pass": "This",
"Attachment": "ClearCoatNormalImage"
}
},
{
"LocalSlot": "ScatterDistanceOutput",
"AttachmentRef": {
"Pass": "This",
"Attachment": "ScatterDistanceImage"
}
}
]
}
@@ -0,0 +1,163 @@
{
"Type": "JsonSerialization",
"Version": 1,
"ClassName": "PassAsset",
"ClassData": {
"PassTemplate": {
"Name": "ForwardSubsurfaceMSAAPassTemplate",
"PassClass": "RasterPass",
"Slots": [
// Inputs...
{
"Name": "BRDFTextureInput",
"ShaderInputName": "m_brdfMap",
"SlotType": "Input",
"ScopeAttachmentUsage": "Shader"
},
{
"Name": "DirectionalLightShadowmap",
"ShaderInputName": "m_directionalLightShadowmap",
"SlotType": "Input",
"ScopeAttachmentUsage": "Shader",
"ImageViewDesc": {
"IsArray": 1
}
},
{
"Name": "ExponentialShadowmapDirectional",
"ShaderInputName": "m_directionalLightExponentialShadowmap",
"SlotType": "Input",
"ScopeAttachmentUsage": "Shader",
"ImageViewDesc": {
"IsArray": 1
}
},
{
"Name": "ProjectedShadowmap",
"ShaderInputName": "m_projectedShadowmaps",
"SlotType": "Input",
"ScopeAttachmentUsage": "Shader",
"ImageViewDesc": {
"IsArray": 1
}
},
{
"Name": "ExponentialShadowmapProjected",
"ShaderInputName": "m_projectedExponentialShadowmap",
"SlotType": "Input",
"ScopeAttachmentUsage": "Shader",
"ImageViewDesc": {
"IsArray": 1
}
},
{
"Name": "TileLightData",
"SlotType": "Input",
"ShaderInputName": "m_tileLightData",
"ScopeAttachmentUsage": "Shader"
},
{
"Name": "LightListRemapped",
"SlotType": "Input",
"ShaderInputName": "m_lightListRemapped",
"ScopeAttachmentUsage": "Shader"
},
// Input/Outputs...
{
"Name": "DepthStencilInputOutput",
"SlotType": "InputOutput",
"ScopeAttachmentUsage": "DepthStencil"
},
{
"Name": "DiffuseOutput",
"SlotType": "InputOutput",
"ScopeAttachmentUsage": "RenderTarget"
},
{
"Name": "SpecularOutput",
"SlotType": "InputOutput",
"ScopeAttachmentUsage": "RenderTarget"
},
{
"Name": "AlbedoOutput",
"SlotType": "InputOutput",
"ScopeAttachmentUsage": "RenderTarget"
},
{
"Name": "SpecularF0Output",
"SlotType": "InputOutput",
"ScopeAttachmentUsage": "RenderTarget"
},
{
"Name": "NormalOutput",
"SlotType": "InputOutput",
"ScopeAttachmentUsage": "RenderTarget"
},
{
"Name": "ClearCoatNormalOutput",
"SlotType": "InputOutput",
"ScopeAttachmentUsage": "RenderTarget"
},
// Outputs...
{
"Name": "ScatterDistanceOutput",
"SlotType": "Output",
"ScopeAttachmentUsage": "RenderTarget",
"LoadStoreAction": {
"ClearValue": {
"Value": [
0.0,
0.0,
0.0,
0.0
]
},
"LoadAction": "Clear"
}
}
],
"ImageAttachments": [
{
"Name": "BRDFTexture",
"Lifetime": "Imported",
"AssetRef": {
"FilePath": "Textures/BRDFTexture.attimage"
}
},
{
"Name": "ScatterDistanceImage",
"SizeSource": {
"Source": {
"Pass": "Parent",
"Attachment": "SwapChainOutput"
}
},
"MultisampleSource": {
"Pass": "This",
"Attachment": "DepthStencilInputOutput"
},
"ImageDescriptor": {
"Format": "R11G11B10_FLOAT",
"SharedQueueMask": "Graphics"
}
}
],
"Connections": [
{
"LocalSlot": "BRDFTextureInput",
"AttachmentRef": {
"Pass": "This",
"Attachment": "BRDFTexture"
}
},
{
"LocalSlot": "ScatterDistanceOutput",
"AttachmentRef": {
"Pass": "This",
"Attachment": "ScatterDistanceImage"
}
}
]
}
}
}
@@ -127,6 +127,113 @@
}
}
},
{
"Name": "ForwardSubsurfaceMSAAPass",
"TemplateName": "ForwardSubsurfaceMSAAPassTemplate",
"Connections": [
// Inputs...
{
"LocalSlot": "DirectionalLightShadowmap",
"AttachmentRef": {
"Pass": "Parent",
"Attachment": "DirectionalShadowmap"
}
},
{
"LocalSlot": "ExponentialShadowmapDirectional",
"AttachmentRef": {
"Pass": "Parent",
"Attachment": "DirectionalESM"
}
},
{
"LocalSlot": "ProjectedShadowmap",
"AttachmentRef": {
"Pass": "Parent",
"Attachment": "ProjectedShadowmap"
}
},
{
"LocalSlot": "ExponentialShadowmapProjected",
"AttachmentRef": {
"Pass": "Parent",
"Attachment": "ProjectedESM"
}
},
{
"LocalSlot": "TileLightData",
"AttachmentRef": {
"Pass": "Parent",
"Attachment": "TileLightData"
}
},
{
"LocalSlot": "LightListRemapped",
"AttachmentRef": {
"Pass": "Parent",
"Attachment": "LightListRemapped"
}
},
// Input/Outputs...
{
"LocalSlot": "DepthStencilInputOutput",
"AttachmentRef": {
"Pass": "Parent",
"Attachment": "DepthStencil"
}
},
{
"LocalSlot": "DiffuseOutput",
"AttachmentRef": {
"Pass": "ForwardMSAAPass",
"Attachment": "DiffuseOutput"
}
},
{
"LocalSlot": "SpecularOutput",
"AttachmentRef": {
"Pass": "ForwardMSAAPass",
"Attachment": "SpecularOutput"
}
},
{
"LocalSlot": "AlbedoOutput",
"AttachmentRef": {
"Pass": "ForwardMSAAPass",
"Attachment": "AlbedoOutput"
}
},
{
"LocalSlot": "SpecularF0Output",
"AttachmentRef": {
"Pass": "ForwardMSAAPass",
"Attachment": "SpecularF0Output"
}
},
{
"LocalSlot": "NormalOutput",
"AttachmentRef": {
"Pass": "ForwardMSAAPass",
"Attachment": "NormalOutput"
}
},
{
"LocalSlot": "ClearCoatNormalOutput",
"AttachmentRef": {
"Pass": "ForwardMSAAPass",
"Attachment": "ClearCoatNormalOutput"
}
}
],
"PassData": {
"$type": "RasterPassData",
"DrawListTag": "forwardWithSubsurfaceOutput",
"PipelineViewTag": "MainCamera",
"PassSrgAsset": {
"FilePath": "shaderlib/atom/features/pbr/forwardpasssrg.azsli:PassSrg"
}
}
},
{
"Name": "DiffuseGlobalIlluminationPass",
"TemplateName": "DiffuseGlobalIlluminationPassTemplate",
@@ -320,7 +427,7 @@
{
"LocalSlot": "Input",
"AttachmentRef": {
"Pass": "ForwardMSAAPass",
"Pass": "ForwardSubsurfaceMSAAPass",
"Attachment": "ScatterDistanceOutput"
}
}
@@ -48,6 +48,10 @@
"Name": "ForwardMSAAPassTemplate",
"Path": "Passes/ForwardMSAA.pass"
},
{
"Name": "ForwardSubsurfaceMSAAPassTemplate",
"Path": "Passes/ForwardSubsurfaceMSAA.pass"
},
{
"Name": "MainPipeline",
"Path": "Passes/MainPipeline.pass"
@@ -19,7 +19,6 @@ struct ForwardPassOutput
float4 m_specularF0 : SV_Target3;
float4 m_normal : SV_Target4;
float4 m_clearCoatNormal : SV_Target5;
float3 m_scatterDistance : SV_Target6;
};
struct ForwardPassOutputWithDepth
@@ -31,6 +30,5 @@ struct ForwardPassOutputWithDepth
float4 m_specularF0 : SV_Target3;
float4 m_normal : SV_Target4;
float4 m_clearCoatNormal : SV_Target5;
float3 m_scatterDistance : SV_Target6;
float m_depth : SV_Depth;
};
@@ -0,0 +1,36 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
struct ForwardPassOutput
{
// m_diffuseColor.a should be encoded with subsurface scattering's strength factor and quality factor if enabled
float4 m_diffuseColor : SV_Target0;
float4 m_specularColor : SV_Target1;
float4 m_albedo : SV_Target2;
float4 m_specularF0 : SV_Target3;
float4 m_normal : SV_Target4;
float4 m_clearCoatNormal : SV_Target5;
float3 m_scatterDistance : SV_Target6;
};
struct ForwardPassOutputWithDepth
{
// m_diffuseColor.a should be encoded with subsurface scattering's strength factor and quality factor if enabled
float4 m_diffuseColor : SV_Target0;
float4 m_specularColor : SV_Target1;
float4 m_albedo : SV_Target2;
float4 m_specularF0 : SV_Target3;
float4 m_normal : SV_Target4;
float4 m_clearCoatNormal : SV_Target5;
float3 m_scatterDistance : SV_Target6;
float m_depth : SV_Depth;
};
@@ -49,16 +49,7 @@ float3 GetDiffuseLighting(Surface surface, LightingData lightingData, float3 lig
float3 GetSpecularLighting(Surface surface, LightingData lightingData, const float3 lightIntensity, const float3 dirToLight)
{
float3 specular;
if (o_enableAnisotropy)
{
specular = AnisotropicGGX( lightingData.dirToCamera, dirToLight, surface.normal, surface.anisotropy.tangent, surface.anisotropy.bitangent, surface.anisotropy.anisotropyFactors,
surface.specularF0, lightingData.NdotV, lightingData.multiScatterCompensation );
}
else
{
specular = SpecularGGX(lightingData.dirToCamera, dirToLight, surface.normal, surface.specularF0, lightingData.NdotV, surface.roughnessA2, lightingData.multiScatterCompensation);
}
float3 specular = SpecularGGX(lightingData.dirToCamera, dirToLight, surface.normal, surface.specularF0, lightingData.NdotV, surface.roughnessA2, lightingData.multiScatterCompensation);
if(o_clearCoat_feature_enabled)
{
@@ -25,16 +25,7 @@
// Then define the Diffuse and Specular lighting functions
float3 GetDiffuseLighting(Surface surface, LightingData lightingData, float3 lightIntensity, float3 dirToLight)
{
float3 diffuse;
if(o_enableSubsurfaceScattering)
{
// Use diffuse brdf contains double Fresnel (enter/exit surface) terms if subsurface scattering is enabled
diffuse = NormalizedDisneyDiffuse(surface.albedo, surface.normal, lightingData.dirToCamera, dirToLight, surface.roughnessLinear);
}
else
{
diffuse = DiffuseLambertian(surface.albedo, surface.normal, dirToLight);
}
float3 diffuse = DiffuseLambertian(surface.albedo, surface.normal, dirToLight);
if(o_clearCoat_feature_enabled)
{
@@ -49,16 +40,7 @@ float3 GetDiffuseLighting(Surface surface, LightingData lightingData, float3 lig
float3 GetSpecularLighting(Surface surface, LightingData lightingData, const float3 lightIntensity, const float3 dirToLight)
{
float3 specular;
if (o_enableAnisotropy)
{
specular = AnisotropicGGX( lightingData.dirToCamera, dirToLight, surface.normal, surface.anisotropy.tangent, surface.anisotropy.bitangent, surface.anisotropy.anisotropyFactors,
surface.specularF0, lightingData.NdotV, lightingData.multiScatterCompensation );
}
else
{
specular = SpecularGGX(lightingData.dirToCamera, dirToLight, surface.normal, surface.specularF0, lightingData.NdotV, surface.roughnessA2, lightingData.multiScatterCompensation);
}
float3 specular = SpecularGGX(lightingData.dirToCamera, dirToLight, surface.normal, surface.specularF0, lightingData.NdotV, surface.roughnessA2, lightingData.multiScatterCompensation);
if(o_clearCoat_feature_enabled)
{
@@ -20,7 +20,6 @@
class Surface //: BasePbrSurfaceData
{
//BasePbrSurfaceData pbr;
AnisotropicSurfaceData anisotropy;
ClearCoatSurfaceData clearCoat;
TransmissionSurfaceData transmission;
@@ -20,7 +20,6 @@
class Surface //: BasePbrSurfaceData
{
//BasePbrSurfaceData pbr;
AnisotropicSurfaceData anisotropy;
ClearCoatSurfaceData clearCoat;
TransmissionSurfaceData transmission;