Merge branch 'main' into ATOM/tonypeng/ATOM-14947
commit
76423a1cc8
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,158 @@
|
||||
{
|
||||
"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"
|
||||
},
|
||||
// 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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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;
|
||||
float3 m_scatterDistance : SV_Target5;
|
||||
};
|
||||
|
||||
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;
|
||||
float3 m_scatterDistance : SV_Target5;
|
||||
float m_depth : SV_Depth;
|
||||
};
|
||||
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Include options first
|
||||
#include <Atom/Features/PBR/LightingOptions.azsli>
|
||||
|
||||
// Then include custom surface and lighting data types
|
||||
#include <Atom/Features/PBR/Lighting/LightingData.azsli>
|
||||
#include <Atom/Features/PBR/Surfaces/EnhancedSurface.azsli>
|
||||
|
||||
#include <Atom/Features/PBR/LightingUtils.azsli>
|
||||
#include <Atom/Features/PBR/Microfacet/Brdf.azsli>
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
if(o_clearCoat_feature_enabled)
|
||||
{
|
||||
// Attenuate diffuse term by clear coat's fresnel term to account for energy loss
|
||||
float HdotV = saturate(dot(normalize(dirToLight + lightingData.dirToCamera), lightingData.dirToCamera));
|
||||
diffuse *= 1.0 - (FresnelSchlick(HdotV, 0.04) * surface.clearCoat.factor);
|
||||
}
|
||||
|
||||
diffuse *= lightIntensity;
|
||||
return diffuse;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if(o_clearCoat_feature_enabled)
|
||||
{
|
||||
float3 halfVector = normalize(dirToLight + lightingData.dirToCamera);
|
||||
float NdotH = saturate(dot(surface.clearCoat.normal, halfVector));
|
||||
float NdotL = saturate(dot(surface.clearCoat.normal, dirToLight));
|
||||
float HdotL = saturate(dot(halfVector, dirToLight));
|
||||
|
||||
// HdotV = HdotL due to the definition of half vector
|
||||
float3 clearCoatF = FresnelSchlick(HdotL, 0.04) * surface.clearCoat.factor;
|
||||
float clearCoatRoughness = max(surface.clearCoat.roughness * surface.clearCoat.roughness, 0.0005f);
|
||||
float3 clearCoatSpecular = ClearCoatGGX(NdotH, HdotL, NdotL, surface.clearCoat.normal, clearCoatRoughness, clearCoatF );
|
||||
|
||||
specular = specular * (1.0 - clearCoatF) * (1.0 - clearCoatF) + clearCoatSpecular;
|
||||
}
|
||||
|
||||
specular *= lightIntensity;
|
||||
|
||||
return specular;
|
||||
}
|
||||
|
||||
|
||||
// Then include everything else
|
||||
#include <Atom/Features/PBR/Lights/Lights.azsli>
|
||||
#include <Atom/Features/PBR/Lights/Ibl.azsli>
|
||||
|
||||
|
||||
struct PbrLightingOutput
|
||||
{
|
||||
float4 m_diffuseColor;
|
||||
float4 m_specularColor;
|
||||
float4 m_albedo;
|
||||
float4 m_specularF0;
|
||||
float4 m_normal;
|
||||
float3 m_scatterDistance;
|
||||
};
|
||||
|
||||
|
||||
PbrLightingOutput GetPbrLightingOutput(Surface surface, LightingData lightingData, float alpha)
|
||||
{
|
||||
PbrLightingOutput lightingOutput;
|
||||
|
||||
lightingOutput.m_diffuseColor = float4(lightingData.diffuseLighting, alpha);
|
||||
lightingOutput.m_specularColor = float4(lightingData.specularLighting, 1.0);
|
||||
|
||||
// albedo, specularF0, roughness, and normals for later passes (specular IBL, Diffuse GI, SSR, AO, etc)
|
||||
lightingOutput.m_specularF0 = float4(surface.specularF0, surface.roughnessLinear);
|
||||
lightingOutput.m_albedo.rgb = surface.albedo * lightingData.diffuseResponse * lightingData.diffuseAmbientOcclusion;
|
||||
lightingOutput.m_albedo.a = lightingData.specularOcclusion;
|
||||
lightingOutput.m_normal.rgb = EncodeNormalSignedOctahedron(surface.normal);
|
||||
lightingOutput.m_normal.a = o_specularF0_enableMultiScatterCompensation ? 1.0f : 0.0f;
|
||||
|
||||
return lightingOutput;
|
||||
}
|
||||
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Include options first
|
||||
#include <Atom/Features/PBR/LightingOptions.azsli>
|
||||
|
||||
// Then include custom surface and lighting data types
|
||||
#include <Atom/Features/PBR/Lighting/LightingData.azsli>
|
||||
#include <Atom/Features/PBR/Surfaces/SkinSurface.azsli>
|
||||
|
||||
#include <Atom/Features/PBR/LightingUtils.azsli>
|
||||
#include <Atom/Features/PBR/Microfacet/Brdf.azsli>
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
if(o_clearCoat_feature_enabled)
|
||||
{
|
||||
// Attenuate diffuse term by clear coat's fresnel term to account for energy loss
|
||||
float HdotV = saturate(dot(normalize(dirToLight + lightingData.dirToCamera), lightingData.dirToCamera));
|
||||
diffuse *= 1.0 - (FresnelSchlick(HdotV, 0.04) * surface.clearCoat.factor);
|
||||
}
|
||||
|
||||
diffuse *= lightIntensity;
|
||||
return diffuse;
|
||||
}
|
||||
|
||||
float3 GetSpecularLighting(Surface surface, LightingData lightingData, const float3 lightIntensity, const float3 dirToLight)
|
||||
{
|
||||
float3 specular = SpecularGGX(lightingData.dirToCamera, dirToLight, surface.normal, surface.specularF0, lightingData.NdotV, surface.roughnessA2, lightingData.multiScatterCompensation);
|
||||
|
||||
if(o_clearCoat_feature_enabled)
|
||||
{
|
||||
float3 halfVector = normalize(dirToLight + lightingData.dirToCamera);
|
||||
float NdotH = saturate(dot(surface.clearCoat.normal, halfVector));
|
||||
float NdotL = saturate(dot(surface.clearCoat.normal, dirToLight));
|
||||
float HdotL = saturate(dot(halfVector, dirToLight));
|
||||
|
||||
// HdotV = HdotL due to the definition of half vector
|
||||
float3 clearCoatF = FresnelSchlick(HdotL, 0.04) * surface.clearCoat.factor;
|
||||
float clearCoatRoughness = max(surface.clearCoat.roughness * surface.clearCoat.roughness, 0.0005f);
|
||||
float3 clearCoatSpecular = ClearCoatGGX(NdotH, HdotL, NdotL, surface.clearCoat.normal, clearCoatRoughness, clearCoatF );
|
||||
|
||||
specular = specular * (1.0 - clearCoatF) * (1.0 - clearCoatF) + clearCoatSpecular;
|
||||
}
|
||||
|
||||
specular *= lightIntensity;
|
||||
|
||||
return specular;
|
||||
}
|
||||
|
||||
|
||||
// Then include everything else
|
||||
#include <Atom/Features/PBR/Lights/Lights.azsli>
|
||||
#include <Atom/Features/PBR/Lights/Ibl.azsli>
|
||||
|
||||
|
||||
struct PbrLightingOutput
|
||||
{
|
||||
float4 m_diffuseColor;
|
||||
float4 m_specularColor;
|
||||
float4 m_albedo;
|
||||
float4 m_specularF0;
|
||||
float4 m_normal;
|
||||
float3 m_scatterDistance;
|
||||
};
|
||||
|
||||
|
||||
PbrLightingOutput GetPbrLightingOutput(Surface surface, LightingData lightingData)
|
||||
{
|
||||
PbrLightingOutput lightingOutput;
|
||||
|
||||
lightingOutput.m_diffuseColor = float4(lightingData.diffuseLighting, 1.0f);
|
||||
lightingOutput.m_specularColor = float4(lightingData.specularLighting, 1.0f);
|
||||
|
||||
// albedo, specularF0, roughness, and normals for later passes (specular IBL, Diffuse GI, SSR, AO, etc)
|
||||
lightingOutput.m_specularF0 = float4(surface.specularF0, surface.roughnessLinear);
|
||||
lightingOutput.m_albedo.rgb = surface.albedo * lightingData.diffuseResponse * lightingData.diffuseAmbientOcclusion;
|
||||
lightingOutput.m_albedo.a = lightingData.specularOcclusion;
|
||||
lightingOutput.m_normal.rgb = EncodeNormalSignedOctahedron(surface.normal);
|
||||
lightingOutput.m_normal.a = o_specularF0_enableMultiScatterCompensation ? 1.0f : 0.0f;
|
||||
|
||||
return lightingOutput;
|
||||
}
|
||||
@ -1,205 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Atom/Features/PBR/LightingOptions.azsli>
|
||||
|
||||
#include <viewsrg.srgi>
|
||||
#include <scenesrg.srgi>
|
||||
|
||||
#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
|
||||
|
||||
#include <Atom/RPI/Math.azsli>
|
||||
#include <Atom/RPI/TangentSpace.azsli>
|
||||
|
||||
#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
|
||||
#include <Atom/Features/PBR/ForwardPassSrg.azsli>
|
||||
|
||||
#include <Atom/Features/PBR/Lighting/StandardLighting.azsli>
|
||||
#include <Atom/Features/PBR/Decals.azsli>
|
||||
|
||||
// VSInput, VSOutput, ObjectSrg must be defined before including this file.
|
||||
|
||||
// DEPRECATED: Please use the VertexHelper(...) function in VertexHelper.azsli instead.
|
||||
//! @param skipShadowCoords can be useful for example when PixelDepthOffset is enable, because the pixel shader will have to run before the final world position is known
|
||||
void PbrVsHelper(in VSInput IN, inout VSOutput OUT, float3 worldPosition, bool skipShadowCoords = false)
|
||||
{
|
||||
OUT.m_worldPosition = worldPosition;
|
||||
OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(OUT.m_worldPosition, 1.0));
|
||||
|
||||
float4x4 objectToWorld = ObjectSrg::GetWorldMatrix();
|
||||
float3x3 objectToWorldIT = ObjectSrg::GetWorldMatrixInverseTranspose();
|
||||
|
||||
ConstructTBN(IN.m_normal, IN.m_tangent, IN.m_bitangent, objectToWorld, objectToWorldIT, OUT.m_normal, OUT.m_tangent, OUT.m_bitangent);
|
||||
|
||||
// directional light shadow
|
||||
const uint shadowIndex = ViewSrg::m_shadowIndexDirectionalLight;
|
||||
if (o_enableShadows && !skipShadowCoords && shadowIndex < SceneSrg::m_directionalLightCount)
|
||||
{
|
||||
DirectionalLightShadow::GetShadowCoords(
|
||||
shadowIndex,
|
||||
worldPosition,
|
||||
OUT.m_shadowCoords);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// DEPRECATED: Please use the functions in StandardLighting.azsli instead.
|
||||
// For an example on how to use those functions, see StandardPBR_forwardPass.azsl
|
||||
PbrLightingOutput PbrLighting( VSOutput IN,
|
||||
float3 baseColor,
|
||||
float metallic,
|
||||
float roughness,
|
||||
float specularF0Factor,
|
||||
float3 normal,
|
||||
float3 vtxTangent,
|
||||
float3 vtxBitangent,
|
||||
float2 anisotropy, // angle and factor
|
||||
float3 emissive,
|
||||
float diffuseAmbientOcclusion,
|
||||
float specularOcclusion,
|
||||
float4 transmissionTintThickness,
|
||||
float4 transmissionParams,
|
||||
float clearCoatFactor,
|
||||
float clearCoatRoughness,
|
||||
float3 clearCoatNormal,
|
||||
float alpha,
|
||||
OpacityMode opacityMode)
|
||||
{
|
||||
float3 worldPosition = IN.m_worldPosition;
|
||||
float4 position = IN.m_position;
|
||||
float3 shadowCoords[ViewSrg::MaxCascadeCount] = IN.m_shadowCoords;
|
||||
|
||||
// ______________________________________________________________________________________________
|
||||
// Surface
|
||||
|
||||
Surface surface;
|
||||
|
||||
surface.position = worldPosition;
|
||||
surface.normal = normal;
|
||||
surface.roughnessLinear = roughness;
|
||||
surface.transmission.tint = transmissionTintThickness.rgb;
|
||||
surface.transmission.thickness = transmissionTintThickness.w;
|
||||
surface.transmission.transmissionParams = transmissionParams;
|
||||
surface.clearCoat.factor = clearCoatFactor;
|
||||
surface.clearCoat.roughness = clearCoatRoughness;
|
||||
surface.clearCoat.normal = clearCoatNormal;
|
||||
|
||||
surface.CalculateRoughnessA();
|
||||
surface.SetAlbedoAndSpecularF0(baseColor, specularF0Factor, metallic);
|
||||
surface.anisotropy.Init(normal, vtxTangent, vtxBitangent, anisotropy.x, anisotropy.y, surface.roughnessA);
|
||||
|
||||
// ______________________________________________________________________________________________
|
||||
// LightingData
|
||||
|
||||
LightingData lightingData;
|
||||
|
||||
// Light iterator
|
||||
lightingData.tileIterator.Init(position, PassSrg::m_lightListRemapped, PassSrg::m_tileLightData);
|
||||
lightingData.Init(surface.position, surface.normal, surface.roughnessLinear);
|
||||
|
||||
lightingData.emissiveLighting = emissive;
|
||||
lightingData.diffuseAmbientOcclusion = diffuseAmbientOcclusion;
|
||||
lightingData.specularOcclusion = specularOcclusion;
|
||||
|
||||
// Directional light shadow coordinates
|
||||
lightingData.shadowCoords = shadowCoords;
|
||||
|
||||
// manipulate base layer f0 if clear coat is enabled
|
||||
if(o_clearCoat_feature_enabled)
|
||||
{
|
||||
// modify base layer's normal incidence reflectance
|
||||
// for the derivation of the following equation please refer to:
|
||||
// https://google.github.io/filament/Filament.md.html#materialsystem/clearcoatmodel/baselayermodification
|
||||
float3 f0 = (1.0 - 5.0 * sqrt(surface.specularF0)) / (5.0 - sqrt(surface.specularF0));
|
||||
surface.specularF0 = lerp(surface.specularF0, f0 * f0, clearCoatFactor);
|
||||
}
|
||||
|
||||
// Diffuse and Specular response (used in IBL calculations)
|
||||
lightingData.specularResponse = FresnelSchlickWithRoughness(lightingData.NdotV, surface.specularF0, surface.roughnessLinear);
|
||||
lightingData.diffuseResponse = 1.0 - lightingData.specularResponse;
|
||||
|
||||
if(o_clearCoat_feature_enabled)
|
||||
{
|
||||
// Clear coat layer has fixed IOR = 1.5 and transparent => F0 = (1.5 - 1)^2 / (1.5 + 1)^2 = 0.04
|
||||
lightingData.diffuseResponse *= 1.0 - (FresnelSchlickWithRoughness(lightingData.NdotV, float3(0.04, 0.04, 0.04), surface.clearCoat.roughness) * surface.clearCoat.factor);
|
||||
}
|
||||
|
||||
// Multiscatter compensation factor
|
||||
lightingData.CalculateMultiscatterCompensation(surface.specularF0, o_specularF0_enableMultiScatterCompensation);
|
||||
|
||||
// ______________________________________________________________________________________________
|
||||
// Lighting
|
||||
|
||||
// Apply Decals
|
||||
ApplyDecals(lightingData.tileIterator, surface);
|
||||
|
||||
// Apply Direct Lighting
|
||||
ApplyDirectLighting(surface, lightingData);
|
||||
|
||||
// Apply Image Based Lighting (IBL)
|
||||
ApplyIBL(surface, lightingData);
|
||||
|
||||
// Finalize Lighting
|
||||
lightingData.FinalizeLighting(surface.transmission.tint);
|
||||
|
||||
if (o_opacity_mode == OpacityMode::Blended || o_opacity_mode == OpacityMode::TintedTransparent)
|
||||
{
|
||||
alpha = FresnelSchlickWithRoughness(lightingData.NdotV, alpha, surface.roughnessLinear).x; // Increase opacity at grazing angles.
|
||||
}
|
||||
|
||||
PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha);
|
||||
|
||||
return lightingOutput;
|
||||
}
|
||||
|
||||
//! Populates a PbrLightingOutput struct with values that can be used to render a simple debug color in the PBR pipeline.
|
||||
//! Note that this will not give you a the exact color screen pixels since it is used in the PBR pipeline, it may
|
||||
//! still have lighting or other affects applied on top of it. But this is still a convenient way to quickly get some
|
||||
//! colors on screen.
|
||||
//! @param IN the pixel shader input structure
|
||||
//! @param debugColor the color to be drawn
|
||||
//! @param normalWS world space normal vector
|
||||
//! @return a PbrLightingOutput as returned by the main PbrLighting() function
|
||||
|
||||
PbrLightingOutput MakeDebugOutput(VSOutput IN, float3 debugColor, float3 normalWS)
|
||||
{
|
||||
// We happen to set this up initially using baseColor, but we could consider adding an option to use
|
||||
// emissive instead to avoid depending on scene lighting.
|
||||
const float3 baseColor = debugColor;
|
||||
const float metallic = 0;
|
||||
const float roughness = 1;
|
||||
const float specularF0Factor = 0.5;
|
||||
const float3 normal = normalWS;
|
||||
const float3 emissive = {0,0,0};
|
||||
const float occlusion = 1;
|
||||
const float clearCoatFactor = 0.0f;
|
||||
const float clearCoatRoughness = 0.0f;
|
||||
const float3 clearCoatNormal = {0,0,0};
|
||||
const float4 transmissionTintThickness = {0,0,0,0};
|
||||
const float4 transmissionParams = {0,0,0,0};
|
||||
const float2 anisotropy = 0.0; // Does not affect calculations unless 'o_enableAnisotropy' is enabled
|
||||
const float alpha = 1.0;
|
||||
|
||||
PbrLightingOutput lightingOutput = PbrLighting(IN, baseColor, metallic, roughness, specularF0Factor,
|
||||
normal, IN.m_tangent, IN.m_bitangent, anisotropy,
|
||||
emissive, occlusion, occlusion, transmissionTintThickness, transmissionParams, clearCoatFactor, clearCoatRoughness, clearCoatNormal, alpha, OpacityMode::Opaque);
|
||||
|
||||
return lightingOutput;
|
||||
}
|
||||
|
||||
//! Same as above, using the vertex normal
|
||||
PbrLightingOutput MakeDebugOutput(VSOutput IN, float3 debugColor)
|
||||
{
|
||||
return MakeDebugOutput(IN, debugColor, normalize(IN.m_normal));
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// //! The surface struct should contain all the info for a pixel that can be
|
||||
// //! passed onto the rendering logic for shading.
|
||||
// //! Note that metallic workflow can be supported by first converting to these physical properties first.
|
||||
// struct Surface
|
||||
// {
|
||||
// float3 position;
|
||||
// float3 normal;
|
||||
// float3 tangentAniso; //! surface space tangent for anisotropic use
|
||||
// float3 bitangentAniso; //! surface space bitangent for anisotropic use
|
||||
// float2 anisotropyFactors; //! anisotory factors along the tangent and the bitangent directions
|
||||
// float3 albedo;
|
||||
// float3 specularF0; //!< actual fresnel f0 spectral value of the surface (as opposed to a "factor")
|
||||
// float3 multiScatterCompensation; //!< the constant scaling term to approximate multiscattering contribution in specular BRDF
|
||||
// float roughnessLinear; //!< perceptually linear roughness value authored by artists. Must be remapped to roughnessA before use
|
||||
// float roughnessA; //!< actual roughness value ( a.k.a. "alpha roughness") to be used in microfacet calculations
|
||||
// float thickness; //!< pre baked local thickness, used for transmission
|
||||
// float4 transmissionParams; //!< parameters: thick mode->(attenuation coefficient, power, distortion, scale), thin mode: (float3 scatter distance, scale)
|
||||
// float clearCoatFactor; //!< clear coat strength factor
|
||||
// float clearCoatRoughness; //!< clear coat linear roughness (not base layer one)
|
||||
// float3 clearCoatNormal; //!< normal used for top layer clear coat
|
||||
// };
|
||||
//
|
||||
// //! Calculate and fill the data required for fast directional anisotropty surface response.
|
||||
// //! Assumption: the normal and roughnessA surface properties were filled and are valid
|
||||
// //! Notice that since the newly created surface tangent and bitangent will be rotated
|
||||
// //! according to the anisotropy direction and should not be used for other purposes uness
|
||||
// //! rotated back.
|
||||
// void CalculateSurfaceDirectionalAnisotropicData(
|
||||
// inout Surface surface, float2 anisotropyAngleAndFactor,
|
||||
// float3 vtxTangent, float3 vtxBitangent )
|
||||
// {
|
||||
// const float anisotropyAngle = anisotropyAngleAndFactor.x;
|
||||
// const float anisotropyFactor = anisotropyAngleAndFactor.y;
|
||||
//
|
||||
// surface.anisotropyFactors = max( 0.01,
|
||||
// float2( surface.roughnessA * (1.0 + anisotropyFactor),
|
||||
// surface.roughnessA * (1.0 - anisotropyFactor) )
|
||||
// );
|
||||
//
|
||||
// if (anisotropyAngle > 0.01)
|
||||
// {
|
||||
// // Base rotation according to anisotropic main direction
|
||||
// float aniSin, aniCos;
|
||||
// sincos(anisotropyAngle, aniSin, aniCos);
|
||||
//
|
||||
// // Rotate the vertex tangent to get new aligned to surface normal tangent
|
||||
// vtxTangent = aniCos * vtxTangent - aniSin * vtxBitangent;
|
||||
// }
|
||||
//
|
||||
// // Now create the new surface base according to the surface normal
|
||||
// // If rotation was required it was already applied to the tangent, hence to the bitangent
|
||||
// surface.bitangentAniso = normalize(cross(surface.normal, vtxTangent));
|
||||
// surface.tangentAniso = cross(surface.bitangentAniso, surface.normal);
|
||||
// }
|
||||
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Atom/Features/PBR/Surfaces/AnisotropicSurfaceData.azsli>
|
||||
#include <Atom/Features/PBR/Surfaces/BasePbrSurfaceData.azsli>
|
||||
#include <Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli>
|
||||
#include <Atom/Features/PBR/Surfaces/TransmissionSurfaceData.azsli>
|
||||
|
||||
class Surface
|
||||
{
|
||||
AnisotropicSurfaceData anisotropy;
|
||||
ClearCoatSurfaceData clearCoat;
|
||||
TransmissionSurfaceData transmission;
|
||||
|
||||
// ------- BasePbrSurfaceData -------
|
||||
|
||||
float3 position; //!< Position in world-space
|
||||
float3 normal; //!< Normal in world-space
|
||||
float3 albedo; //!< Albedo color of the non-metallic material, will be multiplied against the diffuse lighting value
|
||||
float3 specularF0; //!< Fresnel f0 spectral value of the surface
|
||||
float roughnessLinear; //!< Perceptually linear roughness value authored by artists. Must be remapped to roughnessA before use
|
||||
float roughnessA; //!< Actual roughness value ( a.k.a. "alpha roughness") to be used in microfacet calculations
|
||||
float roughnessA2; //!< Alpha roughness ^ 2 (i.e. roughnessA * roughnessA), used in GGX, cached here for perfromance
|
||||
|
||||
//! Applies specular anti-aliasing to roughnessA2
|
||||
void ApplySpecularAA();
|
||||
|
||||
//! Calculates roughnessA and roughnessA2 after roughness has been set
|
||||
void CalculateRoughnessA();
|
||||
|
||||
//! Sets albedo and specularF0 using metallic workflow
|
||||
void SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor, float metallic);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Specular Anti-Aliasing technique from this paper:
|
||||
// http://www.jp.square-enix.com/tech/library/pdf/ImprovedGeometricSpecularAA.pdf
|
||||
void Surface::ApplySpecularAA()
|
||||
{
|
||||
// Constants for formula below
|
||||
const float screenVariance = 0.25f;
|
||||
const float varianceThresh = 0.18f;
|
||||
|
||||
// Specular Anti-Aliasing
|
||||
float3 dndu = ddx_fine( normal );
|
||||
float3 dndv = ddy_fine( normal );
|
||||
float variance = screenVariance * (dot( dndu , dndu ) + dot( dndv , dndv ));
|
||||
float kernelRoughnessA2 = min(2.0 * variance , varianceThresh );
|
||||
float filteredRoughnessA2 = saturate ( roughnessA2 + kernelRoughnessA2 );
|
||||
roughnessA2 = filteredRoughnessA2;
|
||||
}
|
||||
|
||||
void Surface::CalculateRoughnessA()
|
||||
{
|
||||
// The roughness value in microfacet calculations (called "alpha" in the literature) does not give perceptually
|
||||
// linear results. Disney found that squaring the roughness value before using it in microfacet equations causes
|
||||
// the user-provided roughness parameter to be more perceptually linear. We keep both values available as some
|
||||
// equations need roughnessLinear (i.e. IBL sampling) while others need roughnessA (i.e. GGX equations).
|
||||
// See Burley's Disney PBR: https://pdfs.semanticscholar.org/eeee/3b125c09044d3e2f58ed0e4b1b66a677886d.pdf
|
||||
|
||||
roughnessA = max(roughnessLinear * roughnessLinear, MinRoughnessA);
|
||||
|
||||
roughnessA2 = roughnessA * roughnessA;
|
||||
if(o_applySpecularAA)
|
||||
{
|
||||
ApplySpecularAA();
|
||||
}
|
||||
}
|
||||
|
||||
void Surface::SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor, float metallic)
|
||||
{
|
||||
float3 dielectricSpecularF0 = MaxDielectricSpecularF0 * specularF0Factor;
|
||||
|
||||
// Compute albedo and specularF0 based on metalness
|
||||
albedo = lerp(baseColor, float3(0.0f, 0.0f, 0.0f), metallic);
|
||||
specularF0 = lerp(dielectricSpecularF0, baseColor, metallic);
|
||||
}
|
||||
|
||||
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Atom/Features/PBR/Surfaces/AnisotropicSurfaceData.azsli>
|
||||
#include <Atom/Features/PBR/Surfaces/BasePbrSurfaceData.azsli>
|
||||
#include <Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli>
|
||||
#include <Atom/Features/PBR/Surfaces/TransmissionSurfaceData.azsli>
|
||||
|
||||
class Surface
|
||||
{
|
||||
ClearCoatSurfaceData clearCoat;
|
||||
TransmissionSurfaceData transmission;
|
||||
|
||||
// ------- BasePbrSurfaceData -------
|
||||
|
||||
float3 position; //!< Position in world-space
|
||||
float3 normal; //!< Normal in world-space
|
||||
float3 albedo; //!< Albedo color of the non-metallic material, will be multiplied against the diffuse lighting value
|
||||
float3 specularF0; //!< Fresnel f0 spectral value of the surface
|
||||
float roughnessLinear; //!< Perceptually linear roughness value authored by artists. Must be remapped to roughnessA before use
|
||||
float roughnessA; //!< Actual roughness value ( a.k.a. "alpha roughness") to be used in microfacet calculations
|
||||
float roughnessA2; //!< Alpha roughness ^ 2 (i.e. roughnessA * roughnessA), used in GGX, cached here for perfromance
|
||||
|
||||
//! Applies specular anti-aliasing to roughnessA2
|
||||
void ApplySpecularAA();
|
||||
|
||||
//! Calculates roughnessA and roughnessA2 after roughness has been set
|
||||
void CalculateRoughnessA();
|
||||
|
||||
//! Sets albedo and specularF0 using metallic workflow
|
||||
void SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Specular Anti-Aliasing technique from this paper:
|
||||
// http://www.jp.square-enix.com/tech/library/pdf/ImprovedGeometricSpecularAA.pdf
|
||||
void Surface::ApplySpecularAA()
|
||||
{
|
||||
// Constants for formula below
|
||||
const float screenVariance = 0.25f;
|
||||
const float varianceThresh = 0.18f;
|
||||
|
||||
// Specular Anti-Aliasing
|
||||
float3 dndu = ddx_fine( normal );
|
||||
float3 dndv = ddy_fine( normal );
|
||||
float variance = screenVariance * (dot( dndu , dndu ) + dot( dndv , dndv ));
|
||||
float kernelRoughnessA2 = min(2.0 * variance , varianceThresh );
|
||||
float filteredRoughnessA2 = saturate ( roughnessA2 + kernelRoughnessA2 );
|
||||
roughnessA2 = filteredRoughnessA2;
|
||||
}
|
||||
|
||||
void Surface::CalculateRoughnessA()
|
||||
{
|
||||
// The roughness value in microfacet calculations (called "alpha" in the literature) does not give perceptually
|
||||
// linear results. Disney found that squaring the roughness value before using it in microfacet equations causes
|
||||
// the user-provided roughness parameter to be more perceptually linear. We keep both values available as some
|
||||
// equations need roughnessLinear (i.e. IBL sampling) while others need roughnessA (i.e. GGX equations).
|
||||
// See Burley's Disney PBR: https://pdfs.semanticscholar.org/eeee/3b125c09044d3e2f58ed0e4b1b66a677886d.pdf
|
||||
|
||||
roughnessA = max(roughnessLinear * roughnessLinear, MinRoughnessA);
|
||||
|
||||
roughnessA2 = roughnessA * roughnessA;
|
||||
if(o_applySpecularAA)
|
||||
{
|
||||
ApplySpecularAA();
|
||||
}
|
||||
}
|
||||
|
||||
void Surface::SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor)
|
||||
{
|
||||
albedo = baseColor;
|
||||
specularF0 = MaxDielectricSpecularF0 * specularF0Factor;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue