From aa06908024a3b35a0d59c968dda41ffd43f058f8 Mon Sep 17 00:00:00 2001 From: antonmic Date: Sat, 17 Apr 2021 09:52:04 -0700 Subject: [PATCH 01/33] Updated EnhancedPBR and touched up some includes --- .../Materials/Types/EnhancedPBR_Common.azsli | 1 + .../Types/EnhancedPBR_DepthPass_WithPS.azsl | 1 - .../Types/EnhancedPBR_ForwardPass.azsl | 151 ++++++++++++++---- .../Types/EnhancedPBR_Shadowmap_WithPS.azsl | 1 - .../Common/Assets/Materials/Types/Skin.azsl | 1 + .../StandardMultilayerPBR_ForwardPass.azsl | 20 ++- .../Materials/Types/StandardPBR_Common.azsli | 1 + .../Types/StandardPBR_DepthPass_WithPS.azsl | 1 - .../Types/StandardPBR_ForwardPass.azsl | 30 +++- .../Types/StandardPBR_Shadowmap_WithPS.azsl | 1 - .../Atom/Features/PBR/BackLighting.azsli | 18 ++- .../ShaderLib/Atom/Features/PBR/Decals.azsli | 40 ++--- .../PBR/Lighting/EnhancedLighting.azsli | 119 ++++++++++++++ .../Features/PBR/Lighting/SkinLighting.azsli | 119 ++++++++++++++ .../PBR/Lighting/StandardLighting.azsli | 68 +++++++- .../Atom/Features/PBR/LightingModel.azsli | 24 --- .../PBR/Lights/LightTypesCommon.azsli | 62 ------- .../Atom/Features/PBR/Microfacet/Brdf.azsli | 4 - .../ShaderLib/Atom/Features/PBR/Surface.azsli | 68 -------- .../PBR/Surfaces/BasePbrSurfaceData.azsli | 3 + .../PBR/Surfaces/EnhancedSurface.azsli | 91 +++++++++++ .../Features/PBR/Surfaces/SkinSurface.azsli | 91 +++++++++++ .../Atom/Features/Vertex/VertexHelper.azsli | 7 +- 23 files changed, 687 insertions(+), 235 deletions(-) create mode 100644 Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli create mode 100644 Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli delete mode 100644 Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surface.azsli create mode 100644 Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli create mode 100644 Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Common.azsli b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Common.azsli index fd6961c50d..f9bfb75fea 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Common.azsli +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Common.azsli @@ -13,6 +13,7 @@ #pragma once #include +#include #include #include "MaterialInputs/BaseColorInput.azsli" diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl index 81601860ed..28968b5941 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_DepthPass_WithPS.azsl @@ -10,7 +10,6 @@ * */ -#include #include #include "./EnhancedPBR_Common.azsli" #include diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl index a9d6f243c1..d0d060a4be 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl @@ -10,11 +10,25 @@ * */ -#include #include "EnhancedPBR_Common.azsli" + +// SRGs #include +#include + +// Pass Output #include + +// Utility #include +#include + +// Custom Surface & Lighting +#include + +// Decals +#include + // ---------- Material Parameters ---------- @@ -39,6 +53,8 @@ COMMON_OPTIONS_DETAIL_MAPS() #include "MaterialInputs/TransmissionInput.azsli" +// ---------- Vertex Shader ---------- + struct VSInput { // Base fields (required by the template azsli file)... @@ -67,8 +83,6 @@ struct VSOutput float2 m_detailUv[UvSetCount] : UV3; }; -#include -#include #include VSOutput EnhancedPbr_ForwardPassVS(VSInput IN) @@ -94,6 +108,9 @@ VSOutput EnhancedPbr_ForwardPassVS(VSInput IN) return OUT; } + +// ---------- Pixel Shader ---------- + PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float depth) { // ------- Tangents & Bitangets ------- @@ -144,6 +161,9 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float } } + Surface surface; + surface.position = IN.m_worldPosition; + // ------- Alpha & Clip ------- float2 baseColorUv = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; @@ -172,7 +192,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float float3x3 uvMatrix = MaterialSrg::m_normalMapUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); // By design, only UV0 is allowed to apply transforms. float detailLayerNormalFactor = MaterialSrg::m_detail_normal_factor * detailLayerBlendFactor; - float3 normal = GetDetailedNormalInputWS( + surface.normal = GetDetailedNormalInputWS( isFrontFace, IN.m_normal, tangents[MaterialSrg::m_normalMapUvIndex], bitangents[MaterialSrg::m_normalMapUvIndex], MaterialSrg::m_normalMap, MaterialSrg::m_sampler, normalUv, MaterialSrg::m_normalFactor, MaterialSrg::m_flipNormalX, MaterialSrg::m_flipNormalY, uvMatrix, o_normal_useTexture, tangents[MaterialSrg::m_detail_allMapsUvIndex], bitangents[MaterialSrg::m_detail_allMapsUvIndex], MaterialSrg::m_detail_normal_texture, MaterialSrg::m_sampler, detailUv, detailLayerNormalFactor, MaterialSrg::m_detail_normal_flipX, MaterialSrg::m_detail_normal_flipY, MaterialSrg::m_detailUvMatrix, o_detail_normal_useTexture); @@ -196,26 +216,20 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float metallic = GetMetallicInput(MaterialSrg::m_metallicMap, MaterialSrg::m_sampler, metallicUv, MaterialSrg::m_metallicFactor, o_metallic_useTexture); } - // ------- Roughness ------- - - float2 roughnessUv = IN.m_uv[MaterialSrg::m_roughnessMapUvIndex]; - float roughness = GetRoughnessInput(MaterialSrg::m_roughnessMap, MaterialSrg::m_sampler, roughnessUv, MaterialSrg::m_roughnessFactor, - MaterialSrg::m_roughnessLowerBound, MaterialSrg::m_roughnessUpperBound, o_roughness_useTexture); - // ------- Specular ------- float2 specularUv = IN.m_uv[MaterialSrg::m_specularF0MapUvIndex]; - float specularF0Factor = GetSpecularInput(MaterialSrg::m_specularF0Map, MaterialSrg::m_sampler, specularUv, MaterialSrg::m_specularF0Factor, o_specularF0_useTexture); + float specularF0 = GetSpecularInput(MaterialSrg::m_specularF0Map, MaterialSrg::m_sampler, specularUv, MaterialSrg::m_specularF0Factor, o_specularF0_useTexture); - // ------- Emissive ------- + surface.SetAlbedoAndSpecularF0(baseColor, specularF0, metallic); - float2 emissiveUv = IN.m_uv[MaterialSrg::m_emissiveMapUvIndex]; - float3 emissive = GetEmissiveInput(MaterialSrg::m_emissiveMap, MaterialSrg::m_sampler, emissiveUv, MaterialSrg::m_emissiveIntensity, MaterialSrg::m_emissiveColor.rgb, o_emissiveEnabled, o_emissive_useTexture); + // ------- Roughness ------- - // ------- Occlusion ------- + float2 roughnessUv = IN.m_uv[MaterialSrg::m_roughnessMapUvIndex]; + surface.roughnessLinear = GetRoughnessInput(MaterialSrg::m_roughnessMap, MaterialSrg::m_sampler, roughnessUv, MaterialSrg::m_roughnessFactor, + MaterialSrg::m_roughnessLowerBound, MaterialSrg::m_roughnessUpperBound, o_roughness_useTexture); - float2 occlusionUv = IN.m_uv[MaterialSrg::m_ambientOcclusionMapUvIndex]; - float occlusion = GetOcclusionInput(MaterialSrg::m_ambientOcclusionMap, MaterialSrg::m_sampler, occlusionUv, MaterialSrg::m_ambientOcclusionFactor, o_ambientOcclusion_useTexture); + surface.CalculateRoughnessA(); // ------- Subsurface ------- @@ -226,33 +240,100 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float float2 transmissionUv = IN.m_uv[MaterialSrg::m_transmissionThicknessMapUvIndex]; float4 transmissionTintThickness = GeTransmissionInput(MaterialSrg::m_transmissionThicknessMap, MaterialSrg::m_sampler, transmissionUv, MaterialSrg::m_transmissionTintThickness); + surface.transmission.tint = transmissionTintThickness.rgb; + surface.transmission.thickness = transmissionTintThickness.w; + surface.transmission.transmissionParams = MaterialSrg::m_transmissionParams; + + // ------- Anisotropy ------- + + if (o_enableAnisotropy) + { + // Convert the angle from [0..1] = [0 .. 180 degrees] to radians [0 .. PI] + const float anisotropyAngle = MaterialSrg::m_anisotropicAngle * PI; + const float anisotropyFactor = MaterialSrg::m_anisotropicFactor; + surface.anisotropy.Init(surface.normal, tangents[0], bitangents[0], anisotropyAngle, anisotropyFactor, surface.roughnessA); + } + + // ------- Lighting Data ------- + + LightingData lightingData; + + // Light iterator + lightingData.tileIterator.Init(IN.m_position, PassSrg::m_lightListRemapped, PassSrg::m_tileLightData); + lightingData.Init(surface.position, surface.normal, surface.roughnessLinear); + + // Directional light shadow coordinates + lightingData.shadowCoords = IN.m_shadowCoords; + + + // ------- Emissive ------- + + float2 emissiveUv = IN.m_uv[MaterialSrg::m_emissiveMapUvIndex]; + lightingData.emissiveLighting = GetEmissiveInput(MaterialSrg::m_emissiveMap, MaterialSrg::m_sampler, emissiveUv, MaterialSrg::m_emissiveIntensity, MaterialSrg::m_emissiveColor.rgb, o_emissiveEnabled, o_emissive_useTexture); + + // ------- Occlusion ------- + + float2 occlusionUv = IN.m_uv[MaterialSrg::m_ambientOcclusionMapUvIndex]; + lightingData.occlusion = GetOcclusionInput(MaterialSrg::m_ambientOcclusionMap, MaterialSrg::m_sampler, occlusionUv, MaterialSrg::m_ambientOcclusionFactor, o_ambientOcclusion_useTexture); // ------- Clearcoat ------- - float clearCoatFactor = 0.0; - float clearCoatRoughness = 0.0; - float3 clearCoatNormal = float3(0.0, 0.0, 0.0); - // TODO: Clean up the double uses of these clear coat flags - if(o_clearCoat_enabled && o_clearCoat_feature_enabled) + // [GFX TODO][ATOM-14603]: Clean up the double uses of these clear coat flags + if(o_clearCoat_feature_enabled) + { + if(o_clearCoat_enabled) + { + float3x3 uvMatrix = MaterialSrg::m_clearCoatNormalMapUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); + GetClearCoatInputs(MaterialSrg::m_clearCoatInfluenceMap, IN.m_uv[MaterialSrg::m_clearCoatInfluenceMapUvIndex], MaterialSrg::m_clearCoatFactor, o_clearCoat_factor_useTexture, + MaterialSrg::m_clearCoatRoughnessMap, IN.m_uv[MaterialSrg::m_clearCoatRoughnessMapUvIndex], MaterialSrg::m_clearCoatRoughness, o_clearCoat_roughness_useTexture, + MaterialSrg::m_clearCoatNormalMap, IN.m_uv[MaterialSrg::m_clearCoatNormalMapUvIndex], IN.m_normal, o_clearCoat_normal_useTexture, MaterialSrg::m_clearCoatNormalStrength, + uvMatrix, tangents[MaterialSrg::m_clearCoatNormalMapUvIndex], bitangents[MaterialSrg::m_clearCoatNormalMapUvIndex], + MaterialSrg::m_sampler, isFrontFace, + surface.clearCoat.factor, surface.clearCoat.roughness, surface.clearCoat.normal); + } + + // manipulate base layer f0 if clear coat is 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, surface.clearCoat.factor); + } + + // 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) { - float3x3 uvMatrix = MaterialSrg::m_clearCoatNormalMapUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); - GetClearCoatInputs(MaterialSrg::m_clearCoatInfluenceMap, IN.m_uv[MaterialSrg::m_clearCoatInfluenceMapUvIndex], MaterialSrg::m_clearCoatFactor, o_clearCoat_factor_useTexture, - MaterialSrg::m_clearCoatRoughnessMap, IN.m_uv[MaterialSrg::m_clearCoatRoughnessMapUvIndex], MaterialSrg::m_clearCoatRoughness, o_clearCoat_roughness_useTexture, - MaterialSrg::m_clearCoatNormalMap, IN.m_uv[MaterialSrg::m_clearCoatNormalMapUvIndex], IN.m_normal, o_clearCoat_normal_useTexture, MaterialSrg::m_clearCoatNormalStrength, - uvMatrix, tangents[MaterialSrg::m_clearCoatNormalMapUvIndex], bitangents[MaterialSrg::m_clearCoatNormalMapUvIndex], - MaterialSrg::m_sampler, isFrontFace, - clearCoatFactor, clearCoatRoughness, clearCoatNormal); + // 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 ------- + + lightingData.CalculateMultiscatterCompensation(surface.specularF0, o_specularF0_enableMultiScatterCompensation); + // ------- Lighting Calculation ------- - // Convert the angle from [0..1] = [0 .. 180 degrees] to radians [0 .. PI] - const float2 anisotropy = float2(MaterialSrg::m_anisotropicAngle * PI, MaterialSrg::m_anisotropicFactor); + // 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 = PbrLighting(IN, - baseColor, metallic, roughness, specularF0Factor, - normal, IN.m_tangent, IN.m_bitangent, anisotropy, - emissive, occlusion, transmissionTintThickness, MaterialSrg::m_transmissionParams, clearCoatFactor, clearCoatRoughness, clearCoatNormal, alpha, o_opacity_mode); + PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha); // ------- Opacity ------- diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Shadowmap_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Shadowmap_WithPS.azsl index e051a238bd..8a848f0bcc 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Shadowmap_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_Shadowmap_WithPS.azsl @@ -11,7 +11,6 @@ */ #include -#include #include "EnhancedPBR_Common.azsli" #include #include diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl index dc79a94007..bd0bdcd081 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl @@ -13,6 +13,7 @@ #include #include "Skin_Common.azsli" #include +#include #include #include diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl index 9e5c29ba34..30e7df8646 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl @@ -10,10 +10,23 @@ * */ +// SRGs #include #include +#include + +// Pass Output #include + +// Utility #include +#include + +// Custom Surface & Lighting +#include + +// Decals +#include // ---------- Material Parameters ---------- @@ -47,6 +60,9 @@ DEFINE_LAYER_OPTIONS(o_layer3_) #include "MaterialInputs/TransmissionInput.azsli" #include "StandardMultilayerPBR_Common.azsli" + +// ---------- Vertex Shader ---------- + struct VSInput { // Base fields (required by the template azsli file)... @@ -83,7 +99,6 @@ struct VSOutput float3 m_blendMask : UV7; }; -#include #include #include @@ -115,6 +130,9 @@ VSOutput ForwardPassVS(VSInput IN) return OUT; } + +// ---------- Pixel Shader ---------- + PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float depth) { depth = IN.m_position.z; diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Common.azsli b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Common.azsli index 70137a88c1..1a7e039da3 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Common.azsli +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Common.azsli @@ -13,6 +13,7 @@ #pragma once #include +#include #include #include "MaterialInputs/BaseColorInput.azsli" diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_DepthPass_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_DepthPass_WithPS.azsl index 2e64f5102a..4d4f7b195a 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_DepthPass_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_DepthPass_WithPS.azsl @@ -10,7 +10,6 @@ * */ -#include #include #include "./StandardPBR_Common.azsli" #include diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl index 999db3c5da..e4ec2c0f4e 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl @@ -10,11 +10,25 @@ * */ -#include #include "StandardPBR_Common.azsli" + +// SRGs #include +#include + +// Pass Output #include + +// Utility #include +#include + +// Custom Surface & Lighting +#include + +// Decals +#include + // ---------- Material Parameters ---------- @@ -38,6 +52,8 @@ COMMON_OPTIONS_PARALLAX() #include "MaterialInputs/TransmissionInput.azsli" +// ---------- Vertex Shader ---------- + struct VSInput { // Base fields (required by the template azsli file)... @@ -66,8 +82,6 @@ struct VSOutput float2 m_uv[UvSetCount] : UV1; }; -#include -#include #include VSOutput StandardPbr_ForwardPassVS(VSInput IN) @@ -85,6 +99,9 @@ VSOutput StandardPbr_ForwardPassVS(VSInput IN) return OUT; } + +// ---------- Pixel Shader ---------- + PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float depth) { // ------- Tangents & Bitangets ------- @@ -112,7 +129,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float { float3x3 uvMatrix = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); float3x3 uvMatrixInverse = MaterialSrg::m_parallaxUvIndex == 0 ? MaterialSrg::m_uvMatrixInverse : CreateIdentity3x3(); - GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, + GetParallaxInput(IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex], MaterialSrg::m_depthFactor, ObjectSrg::GetWorldMatrix(), uvMatrix, uvMatrixInverse, IN.m_uv[MaterialSrg::m_parallaxUvIndex], IN.m_worldPosition, depth); @@ -130,7 +147,6 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float Surface surface; surface.position = IN.m_worldPosition.xyz; - // ------- Alpha & Clip ------- float2 baseColorUv = IN.m_uv[MaterialSrg::m_baseColorMapUvIndex]; @@ -250,9 +266,9 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float 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); + // ------- Multiscatter ------- + lightingData.CalculateMultiscatterCompensation(surface.specularF0, o_specularF0_enableMultiScatterCompensation); // ------- Lighting Calculation ------- diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Shadowmap_WithPS.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Shadowmap_WithPS.azsl index 520c4cc580..b506e0451b 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Shadowmap_WithPS.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_Shadowmap_WithPS.azsl @@ -11,7 +11,6 @@ */ #include -#include #include "StandardPBR_Common.azsli" #include #include diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/BackLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/BackLighting.azsli index 2df17a41a9..62f77dd701 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/BackLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/BackLighting.azsli @@ -1,7 +1,23 @@ +/* +* 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 +// ------------------------------------------------------------------------------ +// NOTE: The following must be included or defined before including this file: +// - Surface - LightingData +// --------------------------------------------------------------------------------- + #include -#include // Analytical integation (approximation) of diffusion profile over radius, could be replaced by other pre integrated kernels // such as sum of Gaussian diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Decals.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Decals.azsli index b452f08c22..d2eb978eb6 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Decals.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Decals.azsli @@ -12,23 +12,27 @@ #pragma once +// ------------------------------------------------------------------------------ +// NOTE: The following must be included or defined before including this file: +// - Surface +// --------------------------------------------------------------------------------- + #include #include #include -#include void ApplyDecal(uint currDecalIndex, inout Surface surface); void ApplyDecals(inout LightCullingTileIterator tileIterator, inout Surface surface) { tileIterator.LoadAdvance(); - - while( !tileIterator.IsDone() ) - { - uint currDecalIndex = tileIterator.GetValue(); + + while( !tileIterator.IsDone() ) + { + uint currDecalIndex = tileIterator.GetValue(); tileIterator.LoadAdvance(); - ApplyDecal(currDecalIndex, surface); + ApplyDecal(currDecalIndex, surface); } } @@ -44,13 +48,13 @@ float GetDecalAttenuation(float3 surfNormal, float3 decalUp, float decalAngleAtt void ApplyDecal(uint currDecalIndex, inout Surface surface) { - ViewSrg::Decal decal = ViewSrg::m_decals[currDecalIndex]; + ViewSrg::Decal decal = ViewSrg::m_decals[currDecalIndex]; float3x3 decalRot = MatrixFromQuaternion(decal.m_quaternion); - float3 localPos = surface.position - decal.m_position; + float3 localPos = surface.position - decal.m_position; localPos = mul(localPos, decalRot); - + float3 decalUVW = localPos * rcp(decal.m_halfSize); if(decalUVW.x >= -1.0f && decalUVW.x <= 1.0f && decalUVW.y >= -1.0f && decalUVW.y <= 1.0f && @@ -70,25 +74,23 @@ void ApplyDecal(uint currDecalIndex, inout Surface surface) switch(textureArrayIndex) { case 0: - baseMap = ViewSrg::m_decalTextureArray0.Sample(PassSrg::LinearSampler, decalUV); + baseMap = ViewSrg::m_decalTextureArray0.Sample(PassSrg::LinearSampler, decalUV); break; case 1: - baseMap = ViewSrg::m_decalTextureArray1.Sample(PassSrg::LinearSampler, decalUV); + baseMap = ViewSrg::m_decalTextureArray1.Sample(PassSrg::LinearSampler, decalUV); break; case 2: - baseMap = ViewSrg::m_decalTextureArray2.Sample(PassSrg::LinearSampler, decalUV); + baseMap = ViewSrg::m_decalTextureArray2.Sample(PassSrg::LinearSampler, decalUV); break; case 3: - baseMap = ViewSrg::m_decalTextureArray3.Sample(PassSrg::LinearSampler, decalUV); + baseMap = ViewSrg::m_decalTextureArray3.Sample(PassSrg::LinearSampler, decalUV); break; case 4: - baseMap = ViewSrg::m_decalTextureArray4.Sample(PassSrg::LinearSampler, decalUV); + baseMap = ViewSrg::m_decalTextureArray4.Sample(PassSrg::LinearSampler, decalUV); break; } - float opacity = baseMap.a * decal.m_opacity * GetDecalAttenuation(surface.normal, decalRot[2], decal.m_angleAttenuation); - surface.albedo = lerp(surface.albedo, baseMap.rgb, opacity); - } + float opacity = baseMap.a * decal.m_opacity * GetDecalAttenuation(surface.normal, decalRot[2], decal.m_angleAttenuation); + surface.albedo = lerp(surface.albedo, baseMap.rgb, opacity); + } } - - diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli new file mode 100644 index 0000000000..8de8e0c33f --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli @@ -0,0 +1,119 @@ +/* +* 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 + +// Then include custom surface and lighting data types +#include +#include + +#include +#include + +// 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 +#include + + +struct PbrLightingOutput +{ + float4 m_diffuseColor; + float4 m_specularColor; + float4 m_albedo; + float4 m_specularF0; + float4 m_normal; + float4 m_clearCoatNormal; + 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; + lightingOutput.m_albedo.a = lightingData.occlusion; + lightingOutput.m_normal.rgb = EncodeNormalSignedOctahedron(surface.normal); + lightingOutput.m_normal.a = o_specularF0_enableMultiScatterCompensation ? 1.0f : 0.0f; + + // layout: (packedNormal.x, packedNormal.y, strength factor, clear coat roughness (not base material's roughness)) + lightingOutput.m_clearCoatNormal = float4(EncodeNormalSphereMap(surface.clearCoat.normal), o_clearCoat_feature_enabled ? surface.clearCoat.factor : 0.0, surface.clearCoat.roughness); + + return lightingOutput; +} diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli new file mode 100644 index 0000000000..8de8e0c33f --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli @@ -0,0 +1,119 @@ +/* +* 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 + +// Then include custom surface and lighting data types +#include +#include + +#include +#include + +// 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 +#include + + +struct PbrLightingOutput +{ + float4 m_diffuseColor; + float4 m_specularColor; + float4 m_albedo; + float4 m_specularF0; + float4 m_normal; + float4 m_clearCoatNormal; + 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; + lightingOutput.m_albedo.a = lightingData.occlusion; + lightingOutput.m_normal.rgb = EncodeNormalSignedOctahedron(surface.normal); + lightingOutput.m_normal.a = o_specularF0_enableMultiScatterCompensation ? 1.0f : 0.0f; + + // layout: (packedNormal.x, packedNormal.y, strength factor, clear coat roughness (not base material's roughness)) + lightingOutput.m_clearCoatNormal = float4(EncodeNormalSphereMap(surface.clearCoat.normal), o_clearCoat_feature_enabled ? surface.clearCoat.factor : 0.0, surface.clearCoat.roughness); + + return lightingOutput; +} diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli index 31fbbd2138..8de8e0c33f 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli @@ -19,6 +19,68 @@ #include #include +#include +#include + +// 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 #include @@ -55,9 +117,3 @@ PbrLightingOutput GetPbrLightingOutput(Surface surface, LightingData lightingDat return lightingOutput; } - - - - - - diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli index 581ca2f172..64f85b43f0 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli @@ -28,30 +28,6 @@ #include #include -// 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. diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/LightTypesCommon.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/LightTypesCommon.azsli index a668691b75..ac28000148 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/LightTypesCommon.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lights/LightTypesCommon.azsli @@ -16,71 +16,9 @@ #include #include -#include -#include -#include option bool o_area_light_validation = false; -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) - { - //AnisotropicGGX( float3 dirToCamera, float3 dirToLight, float3 normal, float3 tangent, float3 bitangent, float2 anisotropyFactors, - // float3 specularF0, float NdotV, float multiScatterCompensation ) - - 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; -} //! Adjust the intensity of specular light based on the radius of the light source and roughness of the surface to approximate energy conservation. float GetIntensityAdjustedByRadiusAndRoughness(float roughnessA, float radius, float distance2) diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Microfacet/Brdf.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Microfacet/Brdf.azsli index fa60e9485d..0f6c16f619 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Microfacet/Brdf.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Microfacet/Brdf.azsli @@ -18,7 +18,6 @@ * rather than transmit. **/ -#include #include #include "Ggx.azsli" #include "Fresnel.azsli" @@ -81,9 +80,6 @@ float3 DiffuseTitanfall(float roughnessA, float3 albedo, float3 normal, float3 d } - - - // ------- Specular Lighting ------- //! Computes specular response from surfaces with microgeometry. The common form for microfacet diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surface.azsli deleted file mode 100644 index 104eaf140e..0000000000 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surface.azsli +++ /dev/null @@ -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); -// } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/BasePbrSurfaceData.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/BasePbrSurfaceData.azsli index da4c44e1d8..d17f89707d 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/BasePbrSurfaceData.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/BasePbrSurfaceData.azsli @@ -63,6 +63,9 @@ void BasePbrSurfaceData::ApplySpecularAA() float kernelRoughnessA2 = min(2.0 * variance , varianceThresh ); float filteredRoughnessA2 = saturate ( roughnessA2 + kernelRoughnessA2 ); roughnessA2 = filteredRoughnessA2; + + roughnessA = sqrt(roughnessA2); + roughnessLinear = sqrt(roughnessA); } void BasePbrSurfaceData::CalculateRoughnessA() diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli new file mode 100644 index 0000000000..9d4163c474 --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli @@ -0,0 +1,91 @@ +/* +* 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 +#include +#include +#include + +class Surface //: BasePbrSurfaceData +{ + //BasePbrSurfaceData pbr; + 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 inSpecularF0, 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 inSpecularF0, float metallic) +{ + float3 dielectricSpecularF0 = MaxDielectricSpecularF0 * inSpecularF0; + + // Compute albedo and specularF0 based on metalness + albedo = lerp(baseColor, float3(0.0f, 0.0f, 0.0f), metallic); + specularF0 = lerp(dielectricSpecularF0, baseColor, metallic); +} + diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli new file mode 100644 index 0000000000..9d4163c474 --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli @@ -0,0 +1,91 @@ +/* +* 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 +#include +#include +#include + +class Surface //: BasePbrSurfaceData +{ + //BasePbrSurfaceData pbr; + 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 inSpecularF0, 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 inSpecularF0, float metallic) +{ + float3 dielectricSpecularF0 = MaxDielectricSpecularF0 * inSpecularF0; + + // Compute albedo and specularF0 based on metalness + albedo = lerp(baseColor, float3(0.0f, 0.0f, 0.0f), metallic); + specularF0 = lerp(dielectricSpecularF0, baseColor, metallic); +} + diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Vertex/VertexHelper.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Vertex/VertexHelper.azsli index 24cca8dc87..eaac9d82df 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Vertex/VertexHelper.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/Vertex/VertexHelper.azsli @@ -13,7 +13,9 @@ #pragma once // ------------------------------------------------------------------------------ -// NOTE: VSInput, VSOutput, ObjectSrg must be defined before including this file. +// NOTE: The following must be included or defined before including this file: +// - VSInput - ObjectSrg +// - VSOutput - PassSrg // --------------------------------------------------------------------------------- // Options @@ -23,8 +25,6 @@ #include #include #include -#include -#include // Math #include @@ -33,7 +33,6 @@ // Shadow Coords #include - //! @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 VertexHelper(in VSInput IN, inout VSOutput OUT, float3 worldPosition, bool skipShadowCoords = false) { From d0760009b04395aba3771650bd18f636c4dcd23b Mon Sep 17 00:00:00 2001 From: antonmic Date: Sat, 17 Apr 2021 10:28:27 -0700 Subject: [PATCH 02/33] Updated MultilayerPBR --- .../StandardMultilayerPBR_ForwardPass.azsl | 136 +++++++++++++----- .../PBR/Lighting/StandardLighting.azsli | 13 ++ .../Atom/Features/PBR/LightingModel.azsli | 40 ------ 3 files changed, 115 insertions(+), 74 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl index 30e7df8646..638a0a882e 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl @@ -99,7 +99,6 @@ struct VSOutput float3 m_blendMask : UV7; }; -#include #include VSOutput ForwardPassVS(VSInput IN) @@ -162,14 +161,14 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float if(o_debugDrawMode == DebugDrawMode::BlendMaskValues) { float3 blendMaskValues = GetBlendMaskValues(IN.m_uv[MaterialSrg::m_blendMaskUvIndex], IN.m_blendMask); - return MakeDebugOutput(IN, blendMaskValues); + return DebugOutput(blendMaskValues); } if(o_debugDrawMode == DebugDrawMode::DepthMaps) { GetDepth_Setup(IN.m_blendMask); float depth = GetDepth(IN.m_uv[MaterialSrg::m_parallaxUvIndex], float2(0,0), float2(0,0)); - return MakeDebugOutput(IN, float3(depth,depth,depth)); + return DebugOutput(float3(depth,depth,depth)); } // ------- Parallax ------- @@ -197,6 +196,9 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float } } + Surface surface; + surface.position = IN.m_worldPosition; + // ------- Setup the per-layer UV transforms ------- float2 uvLayer1[UvSetCount]; @@ -240,7 +242,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float float3 normalTS = ReorientTangentSpaceNormal(layer1_normalTS, layer2_normalTS); normalTS = ReorientTangentSpaceNormal(normalTS, layer3_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. - float3 normalWS = normalize(TangentSpaceToWorld(normalTS, IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex])); + surface.normal = normalize(TangentSpaceToWorld(normalTS, IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex])); // ------- Base Color ------- @@ -262,52 +264,78 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float float layer3_metallic = GetMetallicInput(MaterialSrg::m_layer3_m_metallicMap, MaterialSrg::m_sampler, uvLayer3[MaterialSrg::m_layer3_m_metallicMapUvIndex], MaterialSrg::m_layer3_m_metallicFactor, o_layer3_o_metallic_useTexture); metallic = BlendLayers(layer1_metallic, layer2_metallic, layer3_metallic, blendMaskValues); } + + // ------- Specular ------- + + float layer1_specularF0Factor = GetSpecularInput(MaterialSrg::m_layer1_m_specularF0Map, MaterialSrg::m_sampler, uvLayer1[MaterialSrg::m_layer1_m_specularF0MapUvIndex], MaterialSrg::m_layer1_m_specularF0Factor, o_layer1_o_specularF0_useTexture); + float layer2_specularF0Factor = GetSpecularInput(MaterialSrg::m_layer2_m_specularF0Map, MaterialSrg::m_sampler, uvLayer2[MaterialSrg::m_layer2_m_specularF0MapUvIndex], MaterialSrg::m_layer2_m_specularF0Factor, o_layer2_o_specularF0_useTexture); + float layer3_specularF0Factor = GetSpecularInput(MaterialSrg::m_layer3_m_specularF0Map, MaterialSrg::m_sampler, uvLayer3[MaterialSrg::m_layer3_m_specularF0MapUvIndex], MaterialSrg::m_layer3_m_specularF0Factor, o_layer3_o_specularF0_useTexture); + float specularF0 = BlendLayers(layer1_specularF0Factor, layer2_specularF0Factor, layer3_specularF0Factor, blendMaskValues); + + surface.SetAlbedoAndSpecularF0(baseColor, specularF0, metallic); // ------- Roughness ------- float layer1_roughness = GetRoughnessInput(MaterialSrg::m_layer1_m_roughnessMap, MaterialSrg::m_sampler, uvLayer1[MaterialSrg::m_layer1_m_roughnessMapUvIndex], MaterialSrg::m_layer1_m_roughnessFactor, MaterialSrg::m_layer1_m_roughnessLowerBound, MaterialSrg::m_layer1_m_roughnessUpperBound, o_layer1_o_roughness_useTexture); float layer2_roughness = GetRoughnessInput(MaterialSrg::m_layer2_m_roughnessMap, MaterialSrg::m_sampler, uvLayer2[MaterialSrg::m_layer2_m_roughnessMapUvIndex], MaterialSrg::m_layer2_m_roughnessFactor, MaterialSrg::m_layer2_m_roughnessLowerBound, MaterialSrg::m_layer2_m_roughnessUpperBound, o_layer2_o_roughness_useTexture); float layer3_roughness = GetRoughnessInput(MaterialSrg::m_layer3_m_roughnessMap, MaterialSrg::m_sampler, uvLayer3[MaterialSrg::m_layer3_m_roughnessMapUvIndex], MaterialSrg::m_layer3_m_roughnessFactor, MaterialSrg::m_layer3_m_roughnessLowerBound, MaterialSrg::m_layer3_m_roughnessUpperBound, o_layer3_o_roughness_useTexture); - float roughness = BlendLayers(layer1_roughness, layer2_roughness, layer3_roughness, blendMaskValues); + surface.roughnessLinear = BlendLayers(layer1_roughness, layer2_roughness, layer3_roughness, blendMaskValues); - // ------- Specular ------- + surface.CalculateRoughnessA(); - float layer1_specularF0Factor = GetSpecularInput(MaterialSrg::m_layer1_m_specularF0Map, MaterialSrg::m_sampler, uvLayer1[MaterialSrg::m_layer1_m_specularF0MapUvIndex], MaterialSrg::m_layer1_m_specularF0Factor, o_layer1_o_specularF0_useTexture); - float layer2_specularF0Factor = GetSpecularInput(MaterialSrg::m_layer2_m_specularF0Map, MaterialSrg::m_sampler, uvLayer2[MaterialSrg::m_layer2_m_specularF0MapUvIndex], MaterialSrg::m_layer2_m_specularF0Factor, o_layer2_o_specularF0_useTexture); - float layer3_specularF0Factor = GetSpecularInput(MaterialSrg::m_layer3_m_specularF0Map, MaterialSrg::m_sampler, uvLayer3[MaterialSrg::m_layer3_m_specularF0MapUvIndex], MaterialSrg::m_layer3_m_specularF0Factor, o_layer3_o_specularF0_useTexture); - float specularF0Factor = BlendLayers(layer1_specularF0Factor, layer2_specularF0Factor, layer3_specularF0Factor, blendMaskValues); + // ------- Subsurface ------- + + float2 subsurfaceUv = IN.m_uv[MaterialSrg::m_subsurfaceScatteringInfluenceMapUvIndex]; + float surfaceScatteringFactor = GetSubsurfaceInput(MaterialSrg::m_subsurfaceScatteringInfluenceMap, MaterialSrg::m_sampler, subsurfaceUv, MaterialSrg::m_subsurfaceScatteringFactor); + + // ------- Transmission ------- + + float2 transmissionUv = IN.m_uv[MaterialSrg::m_transmissionThicknessMapUvIndex]; + float4 transmissionTintThickness = GeTransmissionInput(MaterialSrg::m_transmissionThicknessMap, MaterialSrg::m_sampler, transmissionUv, MaterialSrg::m_transmissionTintThickness); + surface.transmission.tint = transmissionTintThickness.rgb; + 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; + + // Light iterator + lightingData.tileIterator.Init(IN.m_position, PassSrg::m_lightListRemapped, PassSrg::m_tileLightData); + lightingData.Init(surface.position, surface.normal, surface.roughnessLinear); + + // Directional light shadow coordinates + lightingData.shadowCoords = IN.m_shadowCoords; // ------- Emissive ------- float3 layer1_emissive = GetEmissiveInput(MaterialSrg::m_layer1_m_emissiveMap, MaterialSrg::m_sampler, uvLayer1[MaterialSrg::m_layer1_m_emissiveMapUvIndex], MaterialSrg::m_layer1_m_emissiveIntensity, MaterialSrg::m_layer1_m_emissiveColor.rgb, o_layer1_o_emissiveEnabled, o_layer1_o_emissive_useTexture); float3 layer2_emissive = GetEmissiveInput(MaterialSrg::m_layer2_m_emissiveMap, MaterialSrg::m_sampler, uvLayer2[MaterialSrg::m_layer2_m_emissiveMapUvIndex], MaterialSrg::m_layer2_m_emissiveIntensity, MaterialSrg::m_layer2_m_emissiveColor.rgb, o_layer2_o_emissiveEnabled, o_layer2_o_emissive_useTexture); float3 layer3_emissive = GetEmissiveInput(MaterialSrg::m_layer3_m_emissiveMap, MaterialSrg::m_sampler, uvLayer3[MaterialSrg::m_layer3_m_emissiveMapUvIndex], MaterialSrg::m_layer3_m_emissiveIntensity, MaterialSrg::m_layer3_m_emissiveColor.rgb, o_layer3_o_emissiveEnabled, o_layer3_o_emissive_useTexture); - float3 emissive = BlendLayers(layer1_emissive, layer2_emissive, layer3_emissive, blendMaskValues); + lightingData.emissiveLighting = BlendLayers(layer1_emissive, layer2_emissive, layer3_emissive, blendMaskValues); // ------- Occlusion ------- float layer1_occlusion = GetOcclusionInput(MaterialSrg::m_layer1_m_ambientOcclusionMap, MaterialSrg::m_sampler, uvLayer1[MaterialSrg::m_layer1_m_ambientOcclusionMapUvIndex], MaterialSrg::m_layer1_m_ambientOcclusionFactor, o_layer1_o_ambientOcclusion_useTexture); float layer2_occlusion = GetOcclusionInput(MaterialSrg::m_layer2_m_ambientOcclusionMap, MaterialSrg::m_sampler, uvLayer2[MaterialSrg::m_layer2_m_ambientOcclusionMapUvIndex], MaterialSrg::m_layer2_m_ambientOcclusionFactor, o_layer2_o_ambientOcclusion_useTexture); float layer3_occlusion = GetOcclusionInput(MaterialSrg::m_layer3_m_ambientOcclusionMap, MaterialSrg::m_sampler, uvLayer3[MaterialSrg::m_layer3_m_ambientOcclusionMapUvIndex], MaterialSrg::m_layer3_m_ambientOcclusionFactor, o_layer3_o_ambientOcclusion_useTexture); - float occlusion = BlendLayers(layer1_occlusion, layer2_occlusion, layer3_occlusion, blendMaskValues); - - // ------- Subsurface ------- - - float2 subsurfaceUv = IN.m_uv[MaterialSrg::m_subsurfaceScatteringInfluenceMapUvIndex]; - float surfaceScatteringFactor = GetSubsurfaceInput(MaterialSrg::m_subsurfaceScatteringInfluenceMap, MaterialSrg::m_sampler, subsurfaceUv, MaterialSrg::m_subsurfaceScatteringFactor); - - // ------- Transmission ------- - - float2 transmissionUv = IN.m_uv[MaterialSrg::m_transmissionThicknessMapUvIndex]; - float4 transmissionTintThickness = GeTransmissionInput(MaterialSrg::m_transmissionThicknessMap, MaterialSrg::m_sampler, transmissionUv, MaterialSrg::m_transmissionTintThickness); + lightingData.occlusion = BlendLayers(layer1_occlusion, layer2_occlusion, layer3_occlusion, blendMaskValues); // ------- Clearcoat ------- - float clearCoatFactor = 0.0f; - float clearCoatRoughness = 0.0f; - float3 clearCoatNormal = float3(0.0, 0.0, 0.0); if(o_clearCoat_feature_enabled) { + // --- Layer 1 --- + float layer1_clearCoatFactor = 0.0f; float layer1_clearCoatRoughness = 0.0f; float3 layer1_clearCoatNormal = float3(0.0, 0.0, 0.0); @@ -323,6 +351,8 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float layer1_clearCoatFactor, layer1_clearCoatRoughness, layer1_clearCoatNormal); } + // --- Layer 2 --- + float layer2_clearCoatFactor = 0.0f; float layer2_clearCoatRoughness = 0.0f; float3 layer2_clearCoatNormal = float3(0.0, 0.0, 0.0); @@ -338,6 +368,8 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float layer2_clearCoatFactor, layer2_clearCoatRoughness, layer2_clearCoatNormal); } + // --- Layer 3 --- + float layer3_clearCoatFactor = 0.0f; float layer3_clearCoatRoughness = 0.0f; float3 layer3_clearCoatNormal = float3(0.0, 0.0, 0.0); @@ -353,22 +385,58 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float layer3_clearCoatFactor, layer3_clearCoatRoughness, layer3_clearCoatNormal); } - clearCoatFactor = BlendLayers(layer1_clearCoatFactor, layer2_clearCoatFactor, layer3_clearCoatFactor, blendMaskValues); - clearCoatRoughness = BlendLayers(layer1_clearCoatRoughness, layer2_clearCoatRoughness, layer3_clearCoatRoughness, blendMaskValues); + // --- Blend Layers --- + + surface.clearCoat.factor = BlendLayers(layer1_clearCoatFactor, layer2_clearCoatFactor, layer3_clearCoatFactor, blendMaskValues); + surface.clearCoat.roughness = BlendLayers(layer1_clearCoatRoughness, layer2_clearCoatRoughness, layer3_clearCoatRoughness, blendMaskValues); // [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. - clearCoatNormal = BlendLayers(layer1_clearCoatNormal, layer2_clearCoatNormal, layer3_clearCoatNormal, blendMaskValues); - clearCoatNormal = normalize(clearCoatNormal); + surface.clearCoat.normal = BlendLayers(layer1_clearCoatNormal, layer2_clearCoatNormal, layer3_clearCoatNormal, blendMaskValues); + surface.clearCoat.normal = normalize(surface.clearCoat.normal); + + // manipulate base layer f0 if clear coat is 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, surface.clearCoat.factor); } + // 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 ------- + + lightingData.CalculateMultiscatterCompensation(surface.specularF0, o_specularF0_enableMultiScatterCompensation); + // ------- Lighting Calculation ------- - const float2 anisotropy = 0.0; // Does not affect calculations unless 'o_enableAnisotropy' is enabled + // 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 = PbrLighting(IN, - baseColor, metallic, roughness, specularF0Factor, - normalWS, tangents[0], bitangents[0], anisotropy, - emissive, occlusion, transmissionTintThickness, MaterialSrg::m_transmissionParams, clearCoatFactor, clearCoatRoughness, clearCoatNormal, alpha, o_opacity_mode); + PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha); // ------- Opacity ------- diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli index 8de8e0c33f..e9ea1325fd 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli @@ -117,3 +117,16 @@ PbrLightingOutput GetPbrLightingOutput(Surface surface, LightingData lightingDat return lightingOutput; } + +PbrLightingOutput DebugOutput(float3 color) +{ + PbrLightingOutput output = (PbrLightingOutput)0; + + float defaultNormal = float3(0.0f, 0.0f, 1.0f); + + output.m_diffuseColor = float4(color.rgb, 1.0f); + output.m_normal.rgb = EncodeNormalSignedOctahedron(defaultNormal); + output.m_clearCoatNormal = float4(EncodeNormalSphereMap(defaultNormal), 0.0f, 1.0f); + + return output; +} diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli index 64f85b43f0..5d25fa18fa 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli @@ -137,43 +137,3 @@ PbrLightingOutput PbrLighting( VSOutput IN, 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, 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)); -} From 0d412abe52703359cad2220a108379feea1df282 Mon Sep 17 00:00:00 2001 From: antonmic Date: Sat, 17 Apr 2021 12:37:25 -0700 Subject: [PATCH 03/33] Updated Skin shader --- .../Common/Assets/Materials/Types/Skin.azsl | 113 +++++++++++++----- .../Assets/Materials/Types/Skin_Common.azsli | 1 + .../PBR/Lighting/EnhancedLighting.azsli | 2 +- .../Features/PBR/Lighting/SkinLighting.azsli | 8 +- .../Features/PBR/Surfaces/SkinSurface.azsli | 11 +- 5 files changed, 93 insertions(+), 42 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl index bd0bdcd081..d189900627 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl @@ -10,12 +10,24 @@ * */ -#include #include "Skin_Common.azsli" + +// SRGs #include #include + +// Pass Output #include + +// Utility #include +#include // TODO: Remove this after OpacityMode is removed from LightingModel + +// Custom Surface & Lighting +#include + +// Decals +#include // ---------- Material Parameters ---------- @@ -54,6 +66,8 @@ option bool o_blendMask_isBound; #include "MaterialInputs/TransmissionInput.azsli" +// ---------- Vertex Shader ---------- + struct VSInput { // Base fields (required by the template azsli file)... @@ -90,8 +104,6 @@ struct VSOutput float4 m_blendMask : UV8; }; -#include // TODO: Remove this after OpacityMode is removed from LightingModel -#include #include VSOutput SkinVS(VSInput IN) @@ -132,6 +144,9 @@ VSOutput SkinVS(VSInput IN) return OUT; } + +// ---------- Pixel Shader ---------- + float3 ApplyBaseColorWrinkleMap(bool shouldApply, float3 baseColor, Texture2D map, sampler mapSampler, float2 uv, float factor) { if (shouldApply) @@ -178,6 +193,9 @@ PbrLightingOutput SkinPS_Common(VSOutput IN) PrepareGeneratedTangent(IN.m_normal, IN.m_worldPosition, isFrontFace, IN.m_uv, UvSetCount, tangents, bitangents, startIndex); } + Surface surface; + surface.position = IN.m_worldPosition; + // ------- Detail Layer Setup ------- // When the detail maps and the detail blend mask are on the same UV, they both use the transformed detail UVs because they are 'attached' to each other @@ -213,19 +231,18 @@ PbrLightingOutput SkinPS_Common(VSOutput IN) normalMapSample = ApplyNormalWrinkleMap(o_wrinkleLayers_normal_useTexture4, normalMapSample, MaterialSrg::m_wrinkle_normal_texture4, MaterialSrg::m_sampler, normalUv, MaterialSrg::m_flipNormalX, MaterialSrg::m_flipNormalY, IN.m_blendMask.a); } - float3 normalWS; if(o_detail_normal_useTexture) { float3 normalTS = GetTangentSpaceNormal(normalMapSample, uvMatrix, MaterialSrg::m_normalFactor); bool applyOverlay = true; - normalWS = ApplyNormalMapOverlayWS(applyOverlay, IN.m_normal, normalTS, tangents[MaterialSrg::m_normalMapUvIndex], bitangents[MaterialSrg::m_normalMapUvIndex], + surface.normal = ApplyNormalMapOverlayWS(applyOverlay, IN.m_normal, normalTS, tangents[MaterialSrg::m_normalMapUvIndex], bitangents[MaterialSrg::m_normalMapUvIndex], MaterialSrg::m_detail_normal_texture, MaterialSrg::m_sampler, IN.m_detailUv, MaterialSrg::m_detail_normal_flipX, MaterialSrg::m_detail_normal_flipY, detailLayerNormalFactor, tangents[MaterialSrg::m_detail_allMapsUvIndex], bitangents[MaterialSrg::m_detail_allMapsUvIndex], MaterialSrg::m_detailUvMatrix); } else { - normalWS = GetWorldSpaceNormal(normalMapSample, IN.m_normal, tangents[MaterialSrg::m_normalMapUvIndex], bitangents[MaterialSrg::m_normalMapUvIndex], + surface.normal = GetWorldSpaceNormal(normalMapSample, IN.m_normal, tangents[MaterialSrg::m_normalMapUvIndex], bitangents[MaterialSrg::m_normalMapUvIndex], uvMatrix, MaterialSrg::m_normalFactor); } @@ -266,17 +283,29 @@ PbrLightingOutput SkinPS_Common(VSOutput IN) baseColor = ApplyTextureOverlay(o_detail_baseColor_useTexture, baseColor, MaterialSrg::m_detail_baseColor_texture, MaterialSrg::m_sampler, IN.m_detailUv, detailLayerBaseColorFactor); + if(o_wrinkleLayers_enabled && o_wrinkleLayers_showBlendMaskValues && o_blendMask_isBound) + { + // Overlay debug colors to highlight the different blend weights coming from the vertex color stream. + if(o_wrinkleLayers_count > 0) { baseColor = lerp(baseColor, float3(1,0,0), IN.m_blendMask.r); } + if(o_wrinkleLayers_count > 1) { baseColor = lerp(baseColor, float3(0,1,0), IN.m_blendMask.g); } + if(o_wrinkleLayers_count > 2) { baseColor = lerp(baseColor, float3(0,0,1), IN.m_blendMask.b); } + if(o_wrinkleLayers_count > 3) { baseColor = lerp(baseColor, float3(1,1,1), IN.m_blendMask.a); } + } + + // ------- Specular ------- + + float2 specularUv = IN.m_uv[MaterialSrg::m_specularF0MapUvIndex]; + float specularF0 = GetSpecularInput(MaterialSrg::m_specularF0Map, MaterialSrg::m_sampler, specularUv, MaterialSrg::m_specularF0Factor, o_specularF0_useTexture); + + surface.SetAlbedoAndSpecularF0(baseColor, specularF0); // ------- Roughness ------- float2 roughnessUv = IN.m_uv[MaterialSrg::m_roughnessMapUvIndex]; - float roughness = GetRoughnessInput(MaterialSrg::m_roughnessMap, MaterialSrg::m_sampler, roughnessUv, MaterialSrg::m_roughnessFactor, + surface.roughnessLinear = GetRoughnessInput(MaterialSrg::m_roughnessMap, MaterialSrg::m_sampler, roughnessUv, MaterialSrg::m_roughnessFactor, MaterialSrg::m_roughnessLowerBound, MaterialSrg::m_roughnessUpperBound, o_roughness_useTexture); - // ------- Specular ------- - - float2 specularUv = IN.m_uv[MaterialSrg::m_specularF0MapUvIndex]; - float specularF0Factor = GetSpecularInput(MaterialSrg::m_specularF0Map, MaterialSrg::m_sampler, specularUv, MaterialSrg::m_specularF0Factor, o_specularF0_useTexture); + surface.CalculateRoughnessA(); // ------- Subsurface ------- @@ -287,30 +316,54 @@ PbrLightingOutput SkinPS_Common(VSOutput IN) float2 transmissionUv = IN.m_uv[MaterialSrg::m_transmissionThicknessMapUvIndex]; float4 transmissionTintThickness = GeTransmissionInput(MaterialSrg::m_transmissionThicknessMap, MaterialSrg::m_sampler, transmissionUv, MaterialSrg::m_transmissionTintThickness); + surface.transmission.tint = transmissionTintThickness.rgb; + surface.transmission.thickness = transmissionTintThickness.w; + surface.transmission.transmissionParams = MaterialSrg::m_transmissionParams; - // ------- Lighting Calculation ------- + // ------- Anisotropy ------- - if(o_wrinkleLayers_enabled && o_wrinkleLayers_showBlendMaskValues && o_blendMask_isBound) + if (o_enableAnisotropy) { - // Overlay debug colors to highlight the different blend weights coming from the vertex color stream. - if(o_wrinkleLayers_count > 0) { baseColor = lerp(baseColor, float3(1,0,0), IN.m_blendMask.r); } - if(o_wrinkleLayers_count > 1) { baseColor = lerp(baseColor, float3(0,1,0), IN.m_blendMask.g); } - if(o_wrinkleLayers_count > 2) { baseColor = lerp(baseColor, float3(0,0,1), IN.m_blendMask.b); } - if(o_wrinkleLayers_count > 3) { baseColor = lerp(baseColor, float3(1,1,1), IN.m_blendMask.a); } + const float anisotropyAngle = 0.0f; + const float anisotropyFactor = 0.0f; + surface.anisotropy.Init(surface.normal, tangents[0], bitangents[0], anisotropyAngle, anisotropyFactor, surface.roughnessA); } - float metallic = 0; - float3 emissive = float3(0,0,0); - float occlusion = 1; - float2 anisotropy = float2(0,0); - float clearCoatFactor = 0.0; - float clearCoatRoughness = 0.0; - float3 clearCoatNormal = float3(0.0, 0.0, 0.0); - float alpha = 1; - - PbrLightingOutput lightingOutput = PbrLighting(IN, baseColor, metallic, roughness, specularF0Factor, - normalWS, tangents[0], bitangents[0], anisotropy, - emissive, occlusion, transmissionTintThickness, MaterialSrg::m_transmissionParams, clearCoatFactor, clearCoatRoughness, clearCoatNormal, alpha, o_opacity_mode); + // ------- Lighting Data ------- + + LightingData lightingData; + + // Light iterator + lightingData.tileIterator.Init(IN.m_position, PassSrg::m_lightListRemapped, PassSrg::m_tileLightData); + lightingData.Init(surface.position, surface.normal, surface.roughnessLinear); + + // Directional light shadow coordinates + lightingData.shadowCoords = IN.m_shadowCoords; + + // Diffuse and Specular response (used in IBL calculations) + lightingData.specularResponse = FresnelSchlickWithRoughness(lightingData.NdotV, surface.specularF0, surface.roughnessLinear); + lightingData.diffuseResponse = 1.0 - lightingData.specularResponse; + + + // ------- Lighting Calculation ------- + + surface.clearCoat.factor = 0.0; + surface.clearCoat.roughness = 0.0; + surface.clearCoat.normal = float3(0.0, 0.0, 0.0); + + // 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); + + PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData); // ------- Preparing output ------- diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin_Common.azsli b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin_Common.azsli index 9754698101..20bf7c1f2a 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin_Common.azsli +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin_Common.azsli @@ -13,6 +13,7 @@ #pragma once #include +#include #include #include "MaterialInputs/BaseColorInput.azsli" diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli index 8de8e0c33f..47d75a1a9a 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli @@ -17,7 +17,7 @@ // Then include custom surface and lighting data types #include -#include +#include #include #include diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli index 8de8e0c33f..dcc0e21a07 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli @@ -17,7 +17,7 @@ // Then include custom surface and lighting data types #include -#include +#include #include #include @@ -98,12 +98,12 @@ struct PbrLightingOutput }; -PbrLightingOutput GetPbrLightingOutput(Surface surface, LightingData lightingData, float alpha) +PbrLightingOutput GetPbrLightingOutput(Surface surface, LightingData lightingData) { PbrLightingOutput lightingOutput; - lightingOutput.m_diffuseColor = float4(lightingData.diffuseLighting, alpha); - lightingOutput.m_specularColor = float4(lightingData.specularLighting, 1.0); + 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); diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli index 9d4163c474..228ea4bb52 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli @@ -41,7 +41,7 @@ class Surface //: BasePbrSurfaceData void CalculateRoughnessA(); //! Sets albedo and specularF0 using metallic workflow - void SetAlbedoAndSpecularF0(float3 baseColor, float inSpecularF0, float metallic); + void SetAlbedoAndSpecularF0(float3 baseColor, float inSpecularF0); }; @@ -80,12 +80,9 @@ void Surface::CalculateRoughnessA() } } -void Surface::SetAlbedoAndSpecularF0(float3 baseColor, float inSpecularF0, float metallic) +void Surface::SetAlbedoAndSpecularF0(float3 baseColor, float inSpecularF0) { - float3 dielectricSpecularF0 = MaxDielectricSpecularF0 * inSpecularF0; - - // Compute albedo and specularF0 based on metalness - albedo = lerp(baseColor, float3(0.0f, 0.0f, 0.0f), metallic); - specularF0 = lerp(dielectricSpecularF0, baseColor, metallic); + albedo = baseColor; + specularF0 = MaxDielectricSpecularF0 * inSpecularF0; } From b6c4c07fc5d35c8863e19110d8cfbb6777e9377b Mon Sep 17 00:00:00 2001 From: antonmic Date: Sun, 18 Apr 2021 03:09:20 -0700 Subject: [PATCH 04/33] New forward subsurface pass --- .../Types/EnhancedPBR_ForwardPass.azsl | 2 +- .../Types/EnhancedPBR_ForwardPass.shader | 2 +- .../Common/Assets/Materials/Types/Skin.azsl | 11 +- .../Common/Assets/Materials/Types/Skin.shader | 2 +- .../StandardMultilayerPBR_ForwardPass.azsl | 12 -- .../Types/StandardPBR_ForwardPass.azsl | 11 -- .../Common/Assets/Passes/ForwardMSAA.pass | 40 ----- .../Assets/Passes/ForwardSubsurfaceMSAA.pass | 163 ++++++++++++++++++ .../Common/Assets/Passes/OpaqueParent.pass | 109 +++++++++++- .../Assets/Passes/PassTemplates.azasset | 4 + .../Atom/Features/PBR/ForwardPassOutput.azsli | 2 - .../PBR/ForwardSubsurfacePassOutput.azsli | 36 ++++ .../Features/PBR/Lighting/SkinLighting.azsli | 11 +- .../PBR/Lighting/StandardLighting.azsli | 22 +-- .../Features/PBR/Surfaces/SkinSurface.azsli | 1 - .../PBR/Surfaces/StandardSurface.azsli | 1 - 16 files changed, 318 insertions(+), 111 deletions(-) create mode 100644 Gems/Atom/Feature/Common/Assets/Passes/ForwardSubsurfaceMSAA.pass create mode 100644 Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/ForwardSubsurfacePassOutput.azsli diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl index d0d060a4be..6f0d9ecd0e 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl @@ -17,7 +17,7 @@ #include // Pass Output -#include +#include // Utility #include diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.shader b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.shader index 49725bedc9..8cf1c92dc7 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.shader +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.shader @@ -50,5 +50,5 @@ ] }, - "DrawList" : "forward" + "DrawList" : "forwardWithSubsurfaceOutput" } \ No newline at end of file diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl index d189900627..12a543e136 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl @@ -17,7 +17,7 @@ #include // Pass Output -#include +#include // Utility #include @@ -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; diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.shader b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.shader index 763f3a23a1..8651d6f688 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.shader +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.shader @@ -42,5 +42,5 @@ ] }, - "DrawList" : "forward" + "DrawList" : "forwardWithSubsurfaceOutput" } \ No newline at end of file diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl index 638a0a882e..02e6d40209 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl @@ -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; } diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl index e4ec2c0f4e..96b6d2c736 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl @@ -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; } diff --git a/Gems/Atom/Feature/Common/Assets/Passes/ForwardMSAA.pass b/Gems/Atom/Feature/Common/Assets/Passes/ForwardMSAA.pass index b5d5f9f92c..d33691cfd7 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/ForwardMSAA.pass +++ b/Gems/Atom/Feature/Common/Assets/Passes/ForwardMSAA.pass @@ -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" - } } ] } diff --git a/Gems/Atom/Feature/Common/Assets/Passes/ForwardSubsurfaceMSAA.pass b/Gems/Atom/Feature/Common/Assets/Passes/ForwardSubsurfaceMSAA.pass new file mode 100644 index 0000000000..ba09ff7a72 --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/Passes/ForwardSubsurfaceMSAA.pass @@ -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" + } + } + ] + } + } +} \ No newline at end of file diff --git a/Gems/Atom/Feature/Common/Assets/Passes/OpaqueParent.pass b/Gems/Atom/Feature/Common/Assets/Passes/OpaqueParent.pass index 8131bbdf5d..867b4c0970 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/OpaqueParent.pass +++ b/Gems/Atom/Feature/Common/Assets/Passes/OpaqueParent.pass @@ -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" } } diff --git a/Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset b/Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset index 3cedd78210..96075c1bbb 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset +++ b/Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset @@ -48,6 +48,10 @@ "Name": "ForwardMSAAPassTemplate", "Path": "Passes/ForwardMSAA.pass" }, + { + "Name": "ForwardSubsurfaceMSAAPassTemplate", + "Path": "Passes/ForwardSubsurfaceMSAA.pass" + }, { "Name": "MainPipeline", "Path": "Passes/MainPipeline.pass" diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/ForwardPassOutput.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/ForwardPassOutput.azsli index 4185b08571..c2a68d29d0 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/ForwardPassOutput.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/ForwardPassOutput.azsli @@ -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; }; diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/ForwardSubsurfacePassOutput.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/ForwardSubsurfacePassOutput.azsli new file mode 100644 index 0000000000..4185b08571 --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/ForwardSubsurfacePassOutput.azsli @@ -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; +}; diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli index dcc0e21a07..cd04e85516 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli @@ -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) { diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli index e9ea1325fd..cadd02a703 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli @@ -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) { diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli index 228ea4bb52..5092414a11 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli @@ -20,7 +20,6 @@ class Surface //: BasePbrSurfaceData { //BasePbrSurfaceData pbr; - AnisotropicSurfaceData anisotropy; ClearCoatSurfaceData clearCoat; TransmissionSurfaceData transmission; diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli index 9d4163c474..e6ca84c19e 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli @@ -20,7 +20,6 @@ class Surface //: BasePbrSurfaceData { //BasePbrSurfaceData pbr; - AnisotropicSurfaceData anisotropy; ClearCoatSurfaceData clearCoat; TransmissionSurfaceData transmission; From b9c618329a50b91ca1ccd9067a679de1388f53dd Mon Sep 17 00:00:00 2001 From: Walters Date: Mon, 19 Apr 2021 17:08:15 -0700 Subject: [PATCH 05/33] Customer PR. Released unused raw asset data in EmotionFX asset to reclaim memory after asset initialization --- .../EMotionFX/Code/Source/Integration/Assets/ActorAsset.cpp | 3 ++- .../Code/Source/Integration/Assets/AnimGraphAsset.cpp | 1 + Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h | 6 ++++++ .../Code/Source/Integration/Assets/MotionAsset.cpp | 1 + .../Code/Source/Integration/Assets/MotionSetAsset.cpp | 1 + 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Gems/EMotionFX/Code/Source/Integration/Assets/ActorAsset.cpp b/Gems/EMotionFX/Code/Source/Integration/Assets/ActorAsset.cpp index d0b24cb203..4a20190630 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Assets/ActorAsset.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Assets/ActorAsset.cpp @@ -68,6 +68,8 @@ namespace EMotionFX &actorSettings, ""); + assetData->ReleaseEmotionFXData(); + if (!assetData->m_emfxActor) { AZ_Error("EMotionFX", false, "Failed to initialize actor asset %s", asset.ToString().c_str()); @@ -77,7 +79,6 @@ namespace EMotionFX assetData->m_emfxActor->SetIsOwnedByRuntime(true); // Note: Render actor depends on the mesh asset, so we need to manually create it after mesh asset has been loaded. - return static_cast(assetData->m_emfxActor); } diff --git a/Gems/EMotionFX/Code/Source/Integration/Assets/AnimGraphAsset.cpp b/Gems/EMotionFX/Code/Source/Integration/Assets/AnimGraphAsset.cpp index 82bb487d2e..3dd9621420 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Assets/AnimGraphAsset.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Assets/AnimGraphAsset.cpp @@ -90,6 +90,7 @@ namespace EMotionFX } } + assetData->ReleaseEmotionFXData(); AZ_Error("EMotionFX", assetData->m_emfxAnimGraph, "Failed to initialize anim graph asset %s", asset.GetHint().c_str()); return static_cast(assetData->m_emfxAnimGraph); } diff --git a/Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h b/Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h index 2936076258..4e7f1c984f 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h +++ b/Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h @@ -36,6 +36,12 @@ namespace EMotionFX : AZ::Data::AssetData(id) {} + void ReleaseEmotionFXData() + { + m_emfxNativeData.clear(); + m_emfxNativeData.shrink_to_fit(); + } + AZStd::vector m_emfxNativeData; }; diff --git a/Gems/EMotionFX/Code/Source/Integration/Assets/MotionAsset.cpp b/Gems/EMotionFX/Code/Source/Integration/Assets/MotionAsset.cpp index 6bcc572ec6..5acbf5b4f7 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Assets/MotionAsset.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Assets/MotionAsset.cpp @@ -47,6 +47,7 @@ namespace EMotionFX assetData->m_emfxMotion->SetIsOwnedByRuntime(true); } + assetData->ReleaseEmotionFXData(); AZ_Error("EMotionFX", assetData->m_emfxMotion, "Failed to initialize motion asset %s", asset.GetHint().c_str()); return (assetData->m_emfxMotion); } diff --git a/Gems/EMotionFX/Code/Source/Integration/Assets/MotionSetAsset.cpp b/Gems/EMotionFX/Code/Source/Integration/Assets/MotionSetAsset.cpp index f437cea256..3fe6e0c395 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Assets/MotionSetAsset.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Assets/MotionSetAsset.cpp @@ -232,6 +232,7 @@ namespace EMotionFX // Set motion set's motion load callback, so if EMotion FX queries back for a motion, // we can pull the one managed through an AZ::Asset. assetData->m_emfxMotionSet->SetCallback(aznew CustomMotionSetCallback(asset)); + assetData->ReleaseEmotionFXData(); return true; } From 7c099ed11cfa636d033df8cd461f6ad0eda31cb5 Mon Sep 17 00:00:00 2001 From: antonmic Date: Mon, 19 Apr 2021 21:00:13 -0700 Subject: [PATCH 06/33] Updated AutoBrick and MinimalPBR --- .../Atom/Features/PBR/LightingModel.azsli | 208 +++++++++--------- .../PBR/Surfaces/ClearCoatSurfaceData.azsli | 9 + .../Surfaces/TransmissionSurfaceData.azsli | 9 + .../atom_feature_common_asset_files.cmake | 16 +- .../Types/AutoBrick_ForwardPass.azsl | 79 +++++-- .../Types/MinimalPBR_ForwardPass.azsl | 77 +++++-- 6 files changed, 250 insertions(+), 148 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli index 5d25fa18fa..4f2b02ac3d 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli @@ -32,108 +32,108 @@ // 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 occlusion, - 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.occlusion = occlusion; - - // 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; -} +// 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 occlusion, +// 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.occlusion = occlusion; +// +// // 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; +// } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli index c0fc626075..71f0d8a0e8 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli @@ -17,4 +17,13 @@ class ClearCoatSurfaceData float factor; //!< clear coat strength factor float roughness; //!< clear coat linear roughness (not base layer one) float3 normal; //!< normal used for top layer clear coat + + void InitializeToZero(); }; + +void ClearCoatSurfaceData::InitializeToZero() +{ + factor = 0.0f; + roughness = 0.0f; + normal = float3(0.0f, 0.0f, 0.0f); +} diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/TransmissionSurfaceData.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/TransmissionSurfaceData.azsli index 987e4ea575..cff91d5180 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/TransmissionSurfaceData.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/TransmissionSurfaceData.azsli @@ -17,4 +17,13 @@ class TransmissionSurfaceData float3 tint; 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) + + void InitializeToZero(); }; + +void TransmissionSurfaceData::InitializeToZero() +{ + tint = float3(0.0f, 0.0f, 0.0f); + thickness = 0.0f; + transmissionParams = float4(0.0f, 0.0f, 0.0f, 0.0f); +} diff --git a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake index 1b8c0e0987..58d56af614 100644 --- a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake +++ b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake @@ -141,6 +141,7 @@ set(FILES Passes/Forward.pass Passes/ForwardCheckerboard.pass Passes/ForwardMSAA.pass + Passes/ForwardSubsurfaceMSAA.pass Passes/FullscreenCopy.pass Passes/FullscreenOutputOnly.pass Passes/ImGui.pass @@ -165,6 +166,7 @@ set(FILES Passes/MSAAResolveDepth.pass Passes/OpaqueParent.pass Passes/PostProcessParent.pass + Passes/ProjectedShadowmaps.pass Passes/RayTracingAccelerationStructure.pass Passes/ReflectionComposite.pass Passes/ReflectionCopyFrameBuffer.pass @@ -191,7 +193,6 @@ set(FILES Passes/SMAAConvertToPerceptualColor.pass Passes/SMAAEdgeDetection.pass Passes/SMAANeighborhoodBlending.pass - Passes/ProjectedShadowmaps.pass Passes/SsaoCompute.pass Passes/SsaoHalfRes.pass Passes/SsaoParent.pass @@ -230,14 +231,16 @@ set(FILES ShaderLib/Atom/Features/PBR/DefaultObjectSrg.azsli ShaderLib/Atom/Features/PBR/ForwardPassOutput.azsli ShaderLib/Atom/Features/PBR/ForwardPassSrg.azsli + ShaderLib/Atom/Features/PBR/ForwardSubsurfacePassOutput.azsli ShaderLib/Atom/Features/PBR/Hammersley.azsli ShaderLib/Atom/Features/PBR/LightingModel.azsli ShaderLib/Atom/Features/PBR/LightingOptions.azsli ShaderLib/Atom/Features/PBR/LightingUtils.azsli - ShaderLib/Atom/Features/PBR/Surface.azsli ShaderLib/Atom/Features/PBR/TransparentPassSrg.azsli ShaderLib/Atom/Features/PBR/Lighting/DualSpecularLighting.azsli + ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli ShaderLib/Atom/Features/PBR/Lighting/LightingData.azsli + ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli ShaderLib/Atom/Features/PBR/Lights/CapsuleLight.azsli ShaderLib/Atom/Features/PBR/Lights/DirectionalLight.azsli @@ -249,6 +252,8 @@ set(FILES ShaderLib/Atom/Features/PBR/Lights/PointLight.azsli ShaderLib/Atom/Features/PBR/Lights/PolygonLight.azsli ShaderLib/Atom/Features/PBR/Lights/QuadLight.azsli + ShaderLib/Atom/Features/PBR/Lights/SimplePointLight.azsli + ShaderLib/Atom/Features/PBR/Lights/SimpleSpotLight.azsli ShaderLib/Atom/Features/PBR/Microfacet/Brdf.azsli ShaderLib/Atom/Features/PBR/Microfacet/Fresnel.azsli ShaderLib/Atom/Features/PBR/Microfacet/Ggx.azsli @@ -256,6 +261,8 @@ set(FILES ShaderLib/Atom/Features/PBR/Surfaces/BasePbrSurfaceData.azsli ShaderLib/Atom/Features/PBR/Surfaces/ClearCoatSurfaceData.azsli ShaderLib/Atom/Features/PBR/Surfaces/DualSpecularSurface.azsli + ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli + ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli ShaderLib/Atom/Features/PBR/Surfaces/TransmissionSurfaceData.azsli ShaderLib/Atom/Features/PostProcessing/Aces.azsli @@ -271,9 +278,12 @@ set(FILES ShaderLib/Atom/Features/Shadow/BicubicPcfFilters.azsli ShaderLib/Atom/Features/Shadow/DirectionalLightShadow.azsli ShaderLib/Atom/Features/Shadow/JitterTablePcf.azsli + ShaderLib/Atom/Features/Shadow/ProjectedShadow.azsli ShaderLib/Atom/Features/Shadow/Shadow.azsli ShaderLib/Atom/Features/Shadow/ShadowmapAtlasLib.azsli - ShaderLib/Atom/Features/Shadow/ProjectedShadow.azsli + ShaderLib/Atom/Features/Vertex/VertexHelper.azsli + ShaderResourceGroups/RayTracingSceneSrg.azsli + ShaderResourceGroups/RayTracingSceneSrgAll.azsli ShaderResourceGroups/SceneSrg.azsli ShaderResourceGroups/SceneSrgAll.azsli ShaderResourceGroups/SceneTimeSrg.azsli diff --git a/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl b/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl index f484006fe1..5895a00e88 100644 --- a/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl +++ b/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl @@ -14,9 +14,12 @@ #include "AutoBrick_Common.azsli" #include #include +#include #include #include #include +#include +#include struct VSInput { @@ -38,7 +41,6 @@ struct VSOutput float2 m_uv : UV1; }; -#include #include VSOutput AutoBrick_ForwardPassVS(VSInput IN) @@ -129,8 +131,6 @@ float GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy) ForwardPassOutput AutoBrick_ForwardPassPS(VSOutput IN) { - ForwardPassOutput OUT; - float3x3 identityUvMatrix = { 1,0,0, 0,1,0, @@ -164,22 +164,62 @@ ForwardPassOutput AutoBrick_ForwardPassPS(VSOutput IN) GetSurfaceShape(IN.m_uv, surfaceDepth, surfaceNormal); const float3 normal = TangentSpaceToWorld(surfaceNormal, normalize(IN.m_normal), normalize(IN.m_tangent), normalize(IN.m_bitangent)); - const float occlusion = 1.0f - surfaceDepth * AutoBrickSrg::m_aoFactor; - const float metallic = 0; - const float roughness = 1; - const float specularF0Factor = 0.5; - const float3 emissive = {0,0,0}; - const float clearCoatFactor = 0.0; - const float clearCoatRoughness = 0.0; - 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; - const float alpha = 1.0; - - PbrLightingOutput lightingOutput = PbrLighting(IN, baseColor, metallic, roughness, specularF0Factor, - normal, IN.m_tangent, IN.m_bitangent, anisotropy, - emissive, occlusion, transmissionTintThickness, transmissionParams, clearCoatFactor, clearCoatRoughness, clearCoatNormal, alpha, OpacityMode::Opaque); + // ------- Surface ------- + + Surface surface; + + // Position, Normal, Roughness + surface.position = IN.m_worldPosition.xyz; + surface.normal = normalize(normal); + surface.roughnessLinear = 1.0f; + surface.CalculateRoughnessA(); + + // Albedo, SpecularF0 + const float metallic = 0.0f; + const float specularF0 = 0.5f; + surface.SetAlbedoAndSpecularF0(baseColor, specularF0, metallic); + + // Clear Coat, Transmission + surface.clearCoat.InitializeToZero(); + surface.transmission.InitializeToZero(); + + // ------- LightingData ------- + + LightingData lightingData; + + // Light iterator + lightingData.tileIterator.Init(IN.m_position, PassSrg::m_lightListRemapped, PassSrg::m_tileLightData); + lightingData.Init(surface.position, surface.normal, surface.roughnessLinear); + + // Shadow + lightingData.shadowCoords = IN.m_shadowCoords; + lightingData.occlusion = 1.0f - surfaceDepth * AutoBrickSrg::m_aoFactor; + + // Diffuse and Specular response + lightingData.specularResponse = FresnelSchlickWithRoughness(lightingData.NdotV, surface.specularF0, surface.roughnessLinear); + lightingData.diffuseResponse = 1.0f - lightingData.specularResponse; + + const float alpha = 1.0f; + + // ------- Lighting Calculation ------- + + // 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); + + PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha); + + // ------- Output ------- + + ForwardPassOutput OUT; OUT.m_diffuseColor = lightingOutput.m_diffuseColor; OUT.m_diffuseColor.w = -1; // Subsurface scattering is disabled @@ -188,7 +228,6 @@ ForwardPassOutput AutoBrick_ForwardPassPS(VSOutput IN) OUT.m_albedo = lightingOutput.m_albedo; OUT.m_normal = lightingOutput.m_normal; OUT.m_clearCoatNormal = lightingOutput.m_clearCoatNormal; - OUT.m_scatterDistance = float3(0,0,0); return OUT; } diff --git a/Gems/Atom/TestData/TestData/Materials/Types/MinimalPBR_ForwardPass.azsl b/Gems/Atom/TestData/TestData/Materials/Types/MinimalPBR_ForwardPass.azsl index 64903eb1db..e3bd81c504 100644 --- a/Gems/Atom/TestData/TestData/Materials/Types/MinimalPBR_ForwardPass.azsl +++ b/Gems/Atom/TestData/TestData/Materials/Types/MinimalPBR_ForwardPass.azsl @@ -12,10 +12,13 @@ #include #include +#include #include #include #include #include +#include +#include ShaderResourceGroup MinimalPBRSrg : SRG_PerMaterial { @@ -42,7 +45,6 @@ struct VSOutput float3 m_shadowCoords[ViewSrg::MaxCascadeCount] : UV3; }; -#include #include VSOutput MinimalPBR_MainPassVS(VSInput IN) @@ -58,26 +60,60 @@ VSOutput MinimalPBR_MainPassVS(VSInput IN) ForwardPassOutput MinimalPBR_MainPassPS(VSOutput IN) { - ForwardPassOutput OUT; + // ------- Surface ------- + + Surface surface; - const float3 baseColor = MinimalPBRSrg::m_baseColor; - const float metallic = MinimalPBRSrg::m_metallic; - const float roughness = MinimalPBRSrg::m_roughness; - const float specularF0Factor = 0.5; - const float3 normal = normalize(IN.m_normal); - const float3 emissive = {0,0,0}; - const float occlusion = 1; - const float clearCoatFactor = 0.0; - const float clearCoatRoughness = 0.0; - 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, transmissionTintThickness, transmissionParams, clearCoatFactor, clearCoatRoughness, clearCoatNormal, alpha, OpacityMode::Opaque); + // Position, Normal, Roughness + surface.position = IN.m_worldPosition.xyz; + surface.normal = normalize(IN.m_normal); + surface.roughnessLinear = MinimalPBRSrg::m_roughness; + surface.CalculateRoughnessA(); + + // Albedo, SpecularF0 + const float specularF0 = 0.5f; + surface.SetAlbedoAndSpecularF0(MinimalPBRSrg::m_baseColor, specularF0, MinimalPBRSrg::m_metallic); + + // Clear Coat, Transmission + surface.clearCoat.InitializeToZero(); + surface.transmission.InitializeToZero(); + + // ------- LightingData ------- + + LightingData lightingData; + + // Light iterator + lightingData.tileIterator.Init(IN.m_position, PassSrg::m_lightListRemapped, PassSrg::m_tileLightData); + lightingData.Init(surface.position, surface.normal, surface.roughnessLinear); + + // Shadow, Occlusion + lightingData.shadowCoords = IN.m_shadowCoords; + + // Diffuse and Specular response + lightingData.specularResponse = FresnelSchlickWithRoughness(lightingData.NdotV, surface.specularF0, surface.roughnessLinear); + lightingData.diffuseResponse = 1.0f - lightingData.specularResponse; + + const float alpha = 1.0f; + + // ------- Lighting Calculation ------- + + // 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); + + PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha); + + // ------- Output ------- + + ForwardPassOutput OUT; OUT.m_diffuseColor = lightingOutput.m_diffuseColor; OUT.m_diffuseColor.w = -1; // Subsurface scattering is disabled @@ -86,7 +122,6 @@ ForwardPassOutput MinimalPBR_MainPassPS(VSOutput IN) OUT.m_albedo = lightingOutput.m_albedo; OUT.m_normal = lightingOutput.m_normal; OUT.m_clearCoatNormal = lightingOutput.m_clearCoatNormal; - OUT.m_scatterDistance = float3(0,0,0); return OUT; } From 89edc04129216d1d9b5597526460257ac308dba6 Mon Sep 17 00:00:00 2001 From: antonmic Date: Mon, 19 Apr 2021 22:07:27 -0700 Subject: [PATCH 07/33] Fixed subsurface scattering, which now is executes in separate FowardWithSubsurfaceOutput pass --- .../Types/EnhancedPBR_ForwardPass_EDS.shader | 2 +- .../015_SubsurfaceScattering.material | 21 +++++++++++++++---- ...SubsurfaceScattering_Transmission.material | 3 ++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass_EDS.shader b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass_EDS.shader index 6adbba952d..359c9d7003 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass_EDS.shader +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass_EDS.shader @@ -49,5 +49,5 @@ ] }, - "DrawList" : "forward" + "DrawList" : "forwardWithSubsurfaceOutput" } \ No newline at end of file diff --git a/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/015_SubsurfaceScattering.material b/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/015_SubsurfaceScattering.material index 4be87e1a25..4650425e5a 100644 --- a/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/015_SubsurfaceScattering.material +++ b/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/015_SubsurfaceScattering.material @@ -1,20 +1,33 @@ { "description": "", - "materialType": "Materials/Types/StandardPBR.materialtype", + "materialType": "Materials/Types/EnhancedPBR.materialtype", "parentMaterial": "", "propertyLayoutVersion": 3, "properties": { + "emissive": { + "color": [ + 1.0, + 0.0, + 0.0, + 1.0 + ], + "intensity": 4.119999885559082 + }, "subsurfaceScattering": { "enableSubsurfaceScattering": true, "influenceMap": "TestData/Textures/checker8x8_512.png", "scatterColor": [ 1.0, - 0.19937437772750855, - 0.07179369777441025, + 0.20000000298023225, + 0.07058823853731156, 1.0 ], "scatterDistance": 40.0, - "subsurfaceScatterFactor": 1.0 + "subsurfaceScatterFactor": 1.0, + "thickness": 0.41999998688697817, + "transmissionMode": "ThinObject", + "transmissionScale": 6.599999904632568, + "useThicknessMap": false } } } \ No newline at end of file diff --git a/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/015_SubsurfaceScattering_Transmission.material b/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/015_SubsurfaceScattering_Transmission.material index 843df87038..997aa33467 100644 --- a/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/015_SubsurfaceScattering_Transmission.material +++ b/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/015_SubsurfaceScattering_Transmission.material @@ -1,11 +1,12 @@ { "description": "", - "materialType": "Materials/Types/StandardPBR.materialtype", + "materialType": "Materials/Types/EnhancedPBR.materialtype", "parentMaterial": "", "propertyLayoutVersion": 3, "properties": { "subsurfaceScattering": { "enableSubsurfaceScattering": true, + "enableTransmission": true, "scatterDistance": 64.6464614868164, "subsurfaceScatterFactor": 1.0, "thicknessMap": "TestData/Textures/checker8x8_512.png", From 57b68302aef8a3b4032dbf09f41640b771d11928 Mon Sep 17 00:00:00 2001 From: antonmic Date: Mon, 19 Apr 2021 22:48:34 -0700 Subject: [PATCH 08/33] Deleting obsolete LightingModel.azsli --- .../Atom/Features/PBR/AlphaUtils.azsli | 1 - .../Atom/Features/PBR/LightingModel.azsli | 139 ------------------ .../atom_feature_common_asset_files.cmake | 1 - 3 files changed, 141 deletions(-) delete mode 100644 Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/AlphaUtils.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/AlphaUtils.azsli index 99f56f1fd3..09d8332ee8 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/AlphaUtils.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/AlphaUtils.azsli @@ -12,7 +12,6 @@ #pragma once -// TODO: Move this to LightingModel.azsli option enum class OpacityMode {Opaque, Cutout, Blended, TintedTransparent} o_opacity_mode; void CheckClipping(float alpha, float opacityFactor) diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli deleted file mode 100644 index 4f2b02ac3d..0000000000 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/LightingModel.azsli +++ /dev/null @@ -1,139 +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 - -#include -#include - -#include - -#include -#include - -#include -#include - -#include -#include - - - -// 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 occlusion, -// 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.occlusion = occlusion; -// -// // 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; -// } - diff --git a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake index 58d56af614..ad2567dcc9 100644 --- a/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake +++ b/Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake @@ -233,7 +233,6 @@ set(FILES ShaderLib/Atom/Features/PBR/ForwardPassSrg.azsli ShaderLib/Atom/Features/PBR/ForwardSubsurfacePassOutput.azsli ShaderLib/Atom/Features/PBR/Hammersley.azsli - ShaderLib/Atom/Features/PBR/LightingModel.azsli ShaderLib/Atom/Features/PBR/LightingOptions.azsli ShaderLib/Atom/Features/PBR/LightingUtils.azsli ShaderLib/Atom/Features/PBR/TransparentPassSrg.azsli From 1ef7d5c14b66b3a1865cd0aaef941b2b81db45a4 Mon Sep 17 00:00:00 2001 From: Gene Walters Date: Wed, 21 Apr 2021 09:46:06 -0700 Subject: [PATCH 09/33] updating based on feedback --- Gems/EMotionFX/Code/Source/Integration/Assets/ActorAsset.cpp | 2 +- .../Code/Source/Integration/Assets/AnimGraphAsset.cpp | 2 +- Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h | 5 ++--- .../EMotionFX/Code/Source/Integration/Assets/MotionAsset.cpp | 2 +- .../Code/Source/Integration/Assets/MotionSetAsset.cpp | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Gems/EMotionFX/Code/Source/Integration/Assets/ActorAsset.cpp b/Gems/EMotionFX/Code/Source/Integration/Assets/ActorAsset.cpp index 4a20190630..518db289e2 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Assets/ActorAsset.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Assets/ActorAsset.cpp @@ -68,7 +68,7 @@ namespace EMotionFX &actorSettings, ""); - assetData->ReleaseEmotionFXData(); + assetData->ReleaseEMotionFXData(); if (!assetData->m_emfxActor) { diff --git a/Gems/EMotionFX/Code/Source/Integration/Assets/AnimGraphAsset.cpp b/Gems/EMotionFX/Code/Source/Integration/Assets/AnimGraphAsset.cpp index 3dd9621420..a8b9746789 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Assets/AnimGraphAsset.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Assets/AnimGraphAsset.cpp @@ -90,7 +90,7 @@ namespace EMotionFX } } - assetData->ReleaseEmotionFXData(); + assetData->ReleaseEMotionFXData(); AZ_Error("EMotionFX", assetData->m_emfxAnimGraph, "Failed to initialize anim graph asset %s", asset.GetHint().c_str()); return static_cast(assetData->m_emfxAnimGraph); } diff --git a/Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h b/Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h index 4e7f1c984f..9b174c0620 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h +++ b/Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h @@ -36,10 +36,9 @@ namespace EMotionFX : AZ::Data::AssetData(id) {} - void ReleaseEmotionFXData() + void ReleaseEMotionFXData() { - m_emfxNativeData.clear(); - m_emfxNativeData.shrink_to_fit(); + m_emfxNativeData = {}; } AZStd::vector m_emfxNativeData; diff --git a/Gems/EMotionFX/Code/Source/Integration/Assets/MotionAsset.cpp b/Gems/EMotionFX/Code/Source/Integration/Assets/MotionAsset.cpp index 5acbf5b4f7..2d95066b13 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Assets/MotionAsset.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Assets/MotionAsset.cpp @@ -47,7 +47,7 @@ namespace EMotionFX assetData->m_emfxMotion->SetIsOwnedByRuntime(true); } - assetData->ReleaseEmotionFXData(); + assetData->ReleaseEMotionFXData(); AZ_Error("EMotionFX", assetData->m_emfxMotion, "Failed to initialize motion asset %s", asset.GetHint().c_str()); return (assetData->m_emfxMotion); } diff --git a/Gems/EMotionFX/Code/Source/Integration/Assets/MotionSetAsset.cpp b/Gems/EMotionFX/Code/Source/Integration/Assets/MotionSetAsset.cpp index 3fe6e0c395..a49dd95986 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Assets/MotionSetAsset.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Assets/MotionSetAsset.cpp @@ -232,7 +232,7 @@ namespace EMotionFX // Set motion set's motion load callback, so if EMotion FX queries back for a motion, // we can pull the one managed through an AZ::Asset. assetData->m_emfxMotionSet->SetCallback(aznew CustomMotionSetCallback(asset)); - assetData->ReleaseEmotionFXData(); + assetData->ReleaseEMotionFXData(); return true; } From bfc4a3bb2179e6490006f6946e3a52b31a0fc341 Mon Sep 17 00:00:00 2001 From: hultonha Date: Thu, 22 Apr 2021 13:57:03 +0100 Subject: [PATCH 10/33] fix bug for setting SimpleMotion asset --- .../PropertyMotionCtrl.cpp | 201 ++++-------------- .../PropertyMotionCtrl.h | 119 ++++------- 2 files changed, 86 insertions(+), 234 deletions(-) diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMotionCtrl.cpp b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMotionCtrl.cpp index 69f5d9801a..1df31a2c1d 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMotionCtrl.cpp +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMotionCtrl.cpp @@ -1,187 +1,64 @@ /* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates, or -* a third party where indicated. -* -* 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. -* -*/ + * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates, or + * a third party where indicated. + * + * 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. + * + */ #include "EditorDefs.h" #include "PropertyMotionCtrl.h" -// Qt -#include -#include -#include - // AzToolsFramework -#include #include +#include - -MotionPropertyCtrl::MotionPropertyCtrl(QWidget *pParent) - : QWidget(pParent) -{ - m_motionLabel = new QLabel; - - m_pBrowseButton = new QToolButton; - m_pBrowseButton->setIcon(QIcon(":/reflectedPropertyCtrl/img/file_browse.png")); - m_pApplyButton = new QToolButton; - m_pApplyButton->setIcon(QIcon(":/reflectedPropertyCtrl/img/apply.png")); - - m_pApplyButton->setFocusPolicy(Qt::StrongFocus); - m_pBrowseButton->setFocusPolicy(Qt::StrongFocus); - - QHBoxLayout *pLayout = new QHBoxLayout(this); - pLayout->setContentsMargins(0, 0, 0, 0); - pLayout->addWidget(m_motionLabel, 1); - pLayout->addWidget(m_pBrowseButton); - pLayout->addWidget(m_pApplyButton); - - connect(m_pBrowseButton, &QAbstractButton::clicked, this, &MotionPropertyCtrl::OnBrowseClicked); - connect(m_pApplyButton, &QAbstractButton::clicked, this, &MotionPropertyCtrl::OnApplyClicked); -}; - -MotionPropertyCtrl::~MotionPropertyCtrl() -{ -} - - -void MotionPropertyCtrl::SetValue(const CReflectedVarMotion &motion) -{ - m_motion = motion; - SetLabelText(motion.m_motion); -} - -CReflectedVarMotion MotionPropertyCtrl::value() const -{ - return m_motion; -} - -void MotionPropertyCtrl::OnBrowseClicked() -{ - - static AZ::Data::AssetType emotionFXMotionAssetType("{00494B8E-7578-4BA2-8B28-272E90680787}"); // from MotionAsset.h in EMotionFX Gem - - // Request the AssetBrowser Dialog and set a type filter - AssetSelectionModel selection = AssetSelectionModel::AssetTypeSelection(emotionFXMotionAssetType); - selection.SetSelectedAssetId(m_motion.m_assetId); - AzToolsFramework::EditorRequests::Bus::Broadcast(&AzToolsFramework::EditorRequests::BrowseForAssets, selection); - if (selection.IsValid()) - { - auto product = azrtti_cast(selection.GetResult()); - if (product != nullptr) - { - m_motion.m_motion = product->GetRelativePath(); - m_motion.m_assetId = product->GetAssetId(); - SetLabelText(m_motion.m_motion); - emit ValueChanged(m_motion); - } - } -} - -// TODO: Might be able to delete this function -void MotionPropertyCtrl::OnApplyClicked() -{ -#if 0 - CUIEnumerations &roGeneralProxy = CUIEnumerations::GetUIEnumerationsInstance(); - QStringList cSelectedMotions; - size_t nTotalMotions(0); - size_t nCurrentMotion(0); - - QString combinedString = GetIEditor()->GetResourceSelectorHost()->GetGlobalSelection("motion"); - SplitString(combinedString, cSelectedMotions, ','); - - nTotalMotions = cSelectedMotions.size(); - for (nCurrentMotion = 0; nCurrentMotion < nTotalMotions; ++nCurrentMotion) - { - QString& rstrCurrentAnimAction = cSelectedMotions[nCurrentMotion]; - if (!rstrCurrentAnimAction.isEmpty()) - { - m_motion.m_motion = rstrCurrentAnimAction.toLatin1().data(); - SetLabelText(m_motion.m_motion); - emit ValueChanged(m_motion); - } - } -#endif -} - -QWidget* MotionPropertyCtrl::GetFirstInTabOrder() -{ - return m_pBrowseButton; -} -QWidget* MotionPropertyCtrl::GetLastInTabOrder() -{ - return m_pApplyButton; -} - -void MotionPropertyCtrl::UpdateTabOrder() -{ - setTabOrder(m_pBrowseButton, m_pApplyButton); -} - -void MotionPropertyCtrl::SetLabelText(const AZStd::string& motion) -{ - if (!motion.empty()) - { - AZStd::string filename; - if (AzFramework::StringFunc::Path::GetFileName(motion.c_str(), filename)) - { - m_motionLabel->setText(filename.c_str()); - } - else - { - m_motionLabel->setText(motion.c_str()); - } - } - else - { - m_motionLabel->setText(""); - } -} - - -QWidget* MotionPropertyWidgetHandler::CreateGUI(QWidget *pParent) +QWidget* MotionPropertyWidgetHandler::CreateGUI(QWidget* pParent) { - MotionPropertyCtrl* newCtrl = aznew MotionPropertyCtrl(pParent); - connect(newCtrl, &MotionPropertyCtrl::ValueChanged, newCtrl, [newCtrl]() - { - EBUS_EVENT(AzToolsFramework::PropertyEditorGUIMessages::Bus, RequestWrite, newCtrl); - }); + AzToolsFramework::PropertyAssetCtrl* newCtrl = aznew AzToolsFramework::PropertyAssetCtrl(pParent); + connect( + newCtrl, &AzToolsFramework::PropertyAssetCtrl::OnAssetIDChanged, this, [newCtrl]([[maybe_unused]] AZ::Data::AssetId newAssetId) { + EBUS_EVENT(AzToolsFramework::PropertyEditorGUIMessages::Bus, RequestWrite, newCtrl); + AzToolsFramework::PropertyEditorGUIMessages::Bus::Broadcast( + &AzToolsFramework::PropertyEditorGUIMessages::Bus::Handler::OnEditingFinished, newCtrl); + }); return newCtrl; } - -void MotionPropertyWidgetHandler::ConsumeAttribute(MotionPropertyCtrl* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) +void MotionPropertyWidgetHandler::ConsumeAttribute( + [[maybe_unused]] AzToolsFramework::PropertyAssetCtrl* GUI, [[maybe_unused]] AZ::u32 attrib, + [[maybe_unused]] AzToolsFramework::PropertyAttributeReader* attrValue, [[maybe_unused]] const char* debugName) { - Q_UNUSED(GUI); - Q_UNUSED(attrib); - Q_UNUSED(attrValue); - Q_UNUSED(debugName); } -void MotionPropertyWidgetHandler::WriteGUIValuesIntoProperty(size_t index, MotionPropertyCtrl* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) +void MotionPropertyWidgetHandler::WriteGUIValuesIntoProperty( + [[maybe_unused]] size_t index, [[maybe_unused]] AzToolsFramework::PropertyAssetCtrl* GUI, property_t& instance, + [[maybe_unused]] AzToolsFramework::InstanceDataNode* node) { - Q_UNUSED(index); - Q_UNUSED(node); - CReflectedVarMotion val = GUI->value(); + CReflectedVarMotion val; + val.m_motion = GUI->GetCurrentAssetHint(); + val.m_assetId = GUI->GetSelectedAssetID(); instance = static_cast(val); } -bool MotionPropertyWidgetHandler::ReadValuesIntoGUI(size_t index, MotionPropertyCtrl* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) +bool MotionPropertyWidgetHandler::ReadValuesIntoGUI( + [[maybe_unused]] size_t index, [[maybe_unused]] AzToolsFramework::PropertyAssetCtrl* GUI, const property_t& instance, + [[maybe_unused]] AzToolsFramework::InstanceDataNode* node) { - Q_UNUSED(index); - Q_UNUSED(node); - CReflectedVarMotion val = instance; - GUI->SetValue(val); + static const AZ::Data::AssetType emotionFXMotionAssetType( + "{00494B8E-7578-4BA2-8B28-272E90680787}"); // from MotionAsset.h in EMotionFX Gem + + GUI->blockSignals(true); + GUI->SetSelectedAssetID(instance.m_assetId); + GUI->SetCurrentAssetType(emotionFXMotionAssetType); + GUI->blockSignals(false); + return false; } - #include - diff --git a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMotionCtrl.h b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMotionCtrl.h index 568111b521..d04f1b3353 100644 --- a/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMotionCtrl.h +++ b/Code/Sandbox/Editor/Controls/ReflectedPropertyControl/PropertyMotionCtrl.h @@ -1,92 +1,67 @@ /* -* 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. -* -*/ + * 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. + * + */ -#ifndef CRYINCLUDE_EDITOR_UTILS_PROPERTYMOTIONCTRL_H -#define CRYINCLUDE_EDITOR_UTILS_PROPERTYMOTIONCTRL_H #pragma once #if !defined(Q_MOC_RUN) -#include -#include #include "ReflectedVar.h" -#include -#include +#include +#include +#include #include - +#include +#include #endif -class QToolButton; -class QLabel; -class QHBoxLayout; - -namespace AzToolsFramework -{ - class PropertyAssetCtrl; -} - -class MotionPropertyCtrl - : public QWidget +class MotionPropertyWidgetHandler : QObject, + public AzToolsFramework::PropertyHandler { Q_OBJECT -public: - AZ_CLASS_ALLOCATOR(MotionPropertyCtrl, AZ::SystemAllocator, 0); - MotionPropertyCtrl(QWidget* pParent = nullptr); - virtual ~MotionPropertyCtrl(); - - CReflectedVarMotion value() const; - - QWidget* GetFirstInTabOrder(); - QWidget* GetLastInTabOrder(); - void UpdateTabOrder(); - -signals: - void ValueChanged(CReflectedVarMotion value); +public: + AZ_CLASS_ALLOCATOR(MotionPropertyWidgetHandler, AZ::SystemAllocator, 0); -public slots: - void SetValue(const CReflectedVarMotion& motion); + virtual AZ::u32 GetHandlerName(void) const override + { + return AZ_CRC("Motion", 0xf5fea1e8); + } -protected slots: - void OnBrowseClicked(); - void OnApplyClicked(); + virtual bool IsDefaultHandler() const override + { + return true; + } -private: - void SetLabelText(const AZStd::string& motion); + virtual QWidget* GetFirstInTabOrder(AzToolsFramework::PropertyAssetCtrl* widget) override + { + return widget->GetFirstInTabOrder(); + } - QToolButton* m_pBrowseButton; - QToolButton* m_pApplyButton; - QLabel* m_motionLabel; + virtual QWidget* GetLastInTabOrder(AzToolsFramework::PropertyAssetCtrl* widget) override + { + return widget->GetLastInTabOrder(); + } - CReflectedVarMotion m_motion; -}; - -class MotionPropertyWidgetHandler - : QObject - , public AzToolsFramework::PropertyHandler < CReflectedVarMotion, MotionPropertyCtrl > -{ -public: - AZ_CLASS_ALLOCATOR(MotionPropertyWidgetHandler, AZ::SystemAllocator, 0); - - virtual AZ::u32 GetHandlerName(void) const override { return AZ_CRC("Motion", 0xf5fea1e8); } - virtual bool IsDefaultHandler() const override { return true; } - virtual QWidget* GetFirstInTabOrder(MotionPropertyCtrl* widget) override { return widget->GetFirstInTabOrder(); } - virtual QWidget* GetLastInTabOrder(MotionPropertyCtrl* widget) override { return widget->GetLastInTabOrder(); } - virtual void UpdateWidgetInternalTabbing(MotionPropertyCtrl* widget) override { widget->UpdateTabOrder(); } + virtual void UpdateWidgetInternalTabbing(AzToolsFramework::PropertyAssetCtrl* widget) override + { + widget->UpdateTabOrder(); + } virtual QWidget* CreateGUI(QWidget* pParent) override; - virtual void ConsumeAttribute(MotionPropertyCtrl* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, const char* debugName) override; - virtual void WriteGUIValuesIntoProperty(size_t index, MotionPropertyCtrl* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override; - virtual bool ReadValuesIntoGUI(size_t index, MotionPropertyCtrl* GUI, const property_t& instance, AzToolsFramework::InstanceDataNode* node) override; + virtual void ConsumeAttribute( + AzToolsFramework::PropertyAssetCtrl* GUI, AZ::u32 attrib, AzToolsFramework::PropertyAttributeReader* attrValue, + const char* debugName) override; + virtual void WriteGUIValuesIntoProperty( + size_t index, AzToolsFramework::PropertyAssetCtrl* GUI, property_t& instance, AzToolsFramework::InstanceDataNode* node) override; + virtual bool ReadValuesIntoGUI( + size_t index, AzToolsFramework::PropertyAssetCtrl* GUI, const property_t& instance, + AzToolsFramework::InstanceDataNode* node) override; }; - - -#endif // CRYINCLUDE_EDITOR_UTILS_PROPERTYMOTIONCTRL_H From 0e803713bf212b575eab8d422a5a28208f4c5b8a Mon Sep 17 00:00:00 2001 From: amzn-sean <75276488+amzn-sean@users.noreply.github.com> Date: Thu, 22 Apr 2021 12:58:43 +0100 Subject: [PATCH 11/33] Ragdoll now uses Add/Remove SimulatedBody Addressed Minor Character PR feedback --- .../AzFramework/Physics/Character.h | 2 +- .../Physics/Common/PhysicsSimulatedBody.h | 2 +- .../SimulatedBodyConfiguration.cpp | 1 + .../SimulatedBodyConfiguration.h | 1 + .../AzFramework/Physics/Ragdoll.cpp | 5 ++ .../AzFramework/AzFramework/Physics/Ragdoll.h | 8 ++- .../PhysXCharacters/API/CharacterUtils.cpp | 37 ++++++------ .../PhysXCharacters/API/CharacterUtils.h | 5 +- .../Source/PhysXCharacters/API/Ragdoll.cpp | 20 ++----- .../Code/Source/PhysXCharacters/API/Ragdoll.h | 8 +-- .../PhysXCharacters/API/RagdollNode.cpp | 58 ++++++++++++++++--- .../Source/PhysXCharacters/API/RagdollNode.h | 8 ++- .../CharacterControllerComponent.cpp | 3 +- .../Components/RagdollComponent.cpp | 40 +++++++++---- .../Components/RagdollComponent.h | 4 +- Gems/PhysX/Code/Source/Scene/PhysXScene.cpp | 36 ++++++++++-- .../PhysXCharactersRagdollBenchmarks.cpp | 19 +++--- Gems/PhysX/Code/Tests/RagdollTests.cpp | 17 ++++-- 18 files changed, 183 insertions(+), 91 deletions(-) diff --git a/Code/Framework/AzFramework/AzFramework/Physics/Character.h b/Code/Framework/AzFramework/AzFramework/Physics/Character.h index d6f67706f4..19a6cbfe03 100644 --- a/Code/Framework/AzFramework/AzFramework/Physics/Character.h +++ b/Code/Framework/AzFramework/AzFramework/Physics/Character.h @@ -78,7 +78,7 @@ namespace Physics float m_minimumMovementDistance = 0.001f; //!< To avoid jittering, the controller will not attempt to move distances below this. float m_maximumSpeed = 100.0f; //!< If the accumulated requested velocity for a tick exceeds this magnitude, it will be clamped. AZStd::string m_colliderTag; //!< Used to identify the collider associated with the character controller. - AZStd::shared_ptr m_shapeConfig = nullptr; //!< The shape to use when creating the character controller. + AZStd::shared_ptr m_shapeConfig; //!< The shape to use when creating the character controller. AZStd::vector> m_colliders; //!< The list of colliders to attach to the character controller. }; diff --git a/Code/Framework/AzFramework/AzFramework/Physics/Common/PhysicsSimulatedBody.h b/Code/Framework/AzFramework/AzFramework/Physics/Common/PhysicsSimulatedBody.h index d892e433bc..ed8a68dc24 100644 --- a/Code/Framework/AzFramework/AzFramework/Physics/Common/PhysicsSimulatedBody.h +++ b/Code/Framework/AzFramework/AzFramework/Physics/Common/PhysicsSimulatedBody.h @@ -55,7 +55,7 @@ namespace AzPhysics //! Flag to determine if the body is part of the simulation. //! When true the body will be affected by any forces, collisions, and found with scene queries. - bool m_simulating = true; + bool m_simulating = false; //! Helper functions for setting user data. //! @param userData Can be a pointer to any type as internally will be cast to a void*. Object lifetime not managed by the SimulatedBody. diff --git a/Code/Framework/AzFramework/AzFramework/Physics/Configuration/SimulatedBodyConfiguration.cpp b/Code/Framework/AzFramework/AzFramework/Physics/Configuration/SimulatedBodyConfiguration.cpp index 0e29263e30..01bff3ccbb 100644 --- a/Code/Framework/AzFramework/AzFramework/Physics/Configuration/SimulatedBodyConfiguration.cpp +++ b/Code/Framework/AzFramework/AzFramework/Physics/Configuration/SimulatedBodyConfiguration.cpp @@ -46,6 +46,7 @@ namespace AzPhysics ->Field("orientation", &SimulatedBodyConfiguration::m_orientation) ->Field("scale", &SimulatedBodyConfiguration::m_scale) ->Field("entityId", &SimulatedBodyConfiguration::m_entityId) + ->Field("startSimulationEnabled", &SimulatedBodyConfiguration::m_startSimulationEnabled) ; } } diff --git a/Code/Framework/AzFramework/AzFramework/Physics/Configuration/SimulatedBodyConfiguration.h b/Code/Framework/AzFramework/AzFramework/Physics/Configuration/SimulatedBodyConfiguration.h index 203590adbb..6862bfccb8 100644 --- a/Code/Framework/AzFramework/AzFramework/Physics/Configuration/SimulatedBodyConfiguration.h +++ b/Code/Framework/AzFramework/AzFramework/Physics/Configuration/SimulatedBodyConfiguration.h @@ -39,6 +39,7 @@ namespace AzPhysics AZ::Vector3 m_position = AZ::Vector3::CreateZero(); AZ::Quaternion m_orientation = AZ::Quaternion::CreateIdentity(); AZ::Vector3 m_scale = AZ::Vector3::CreateOne(); + bool m_startSimulationEnabled = true; // Entity/object association. AZ::EntityId m_entityId = AZ::EntityId(AZ::EntityId::InvalidEntityId); diff --git a/Code/Framework/AzFramework/AzFramework/Physics/Ragdoll.cpp b/Code/Framework/AzFramework/AzFramework/Physics/Ragdoll.cpp index 02cd96ac00..f634360445 100644 --- a/Code/Framework/AzFramework/AzFramework/Physics/Ragdoll.cpp +++ b/Code/Framework/AzFramework/AzFramework/Physics/Ragdoll.cpp @@ -52,6 +52,11 @@ namespace Physics } } + RagdollConfiguration::RagdollConfiguration() + { + m_startSimulationEnabled = false; //ragdolls do not start enabled. + } + void RagdollConfiguration::Reflect(AZ::ReflectContext* context) { AZ::SerializeContext* serializeContext = azrtti_cast(context); diff --git a/Code/Framework/AzFramework/AzFramework/Physics/Ragdoll.h b/Code/Framework/AzFramework/AzFramework/Physics/Ragdoll.h index 3f98ca9303..239d93cf32 100644 --- a/Code/Framework/AzFramework/AzFramework/Physics/Ragdoll.h +++ b/Code/Framework/AzFramework/AzFramework/Physics/Ragdoll.h @@ -24,6 +24,8 @@ namespace Physics { + using ParentIndices = AZStd::vector; + class RagdollNodeConfiguration : public AzPhysics::RigidBodyConfiguration { @@ -46,7 +48,7 @@ namespace Physics AZ_RTTI(RagdollConfiguration, "{7C96D332-61D8-4C58-A2BF-707716D38D14}", AzPhysics::SimulatedBodyConfiguration); static void Reflect(AZ::ReflectContext* context); - RagdollConfiguration() = default; + RagdollConfiguration(); explicit RagdollConfiguration(const RagdollConfiguration& settings) = default; RagdollNodeConfiguration* FindNodeConfigByName(const AZStd::string& nodeName) const; @@ -56,6 +58,8 @@ namespace Physics AZStd::vector m_nodes; CharacterColliderConfiguration m_colliders; + RagdollState m_initialState; + ParentIndices m_parentIndices; }; /// Represents a single rigid part of a ragdoll. @@ -79,7 +83,7 @@ namespace Physics { public: AZ_CLASS_ALLOCATOR(Ragdoll, AZ::SystemAllocator, 0); - AZ_RTTI(Ragdoll, "{01F09602-80EC-4693-A0E7-C2719239044B}", AzPhysics::SimulatedBody); + AZ_RTTI(Physics::Ragdoll, "{01F09602-80EC-4693-A0E7-C2719239044B}", AzPhysics::SimulatedBody); virtual ~Ragdoll() = default; /// Inserts the ragdoll into the physics simulation. diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp b/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp index 6523238430..1c91818eb5 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp +++ b/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp @@ -167,19 +167,18 @@ namespace PhysX return aznew CharacterController(pxController, AZStd::move(callbackManager), scene->GetSceneHandle()); } - AZStd::unique_ptr CreateRagdoll(Physics::RagdollConfiguration& configuration, - const Physics::RagdollState& initialState, const ParentIndices& parentIndices, AzPhysics::SceneHandle sceneHandle) + Ragdoll* CreateRagdoll(Physics::RagdollConfiguration& configuration, AzPhysics::SceneHandle sceneHandle) { const size_t numNodes = configuration.m_nodes.size(); - if (numNodes != initialState.size()) + if (numNodes != configuration.m_initialState.size()) { AZ_Error("PhysX Ragdoll", false, "Mismatch between number of nodes in ragdoll configuration (%i) " - "and number of nodes in the initial ragdoll state (%i)", numNodes, initialState.size()); + "and number of nodes in the initial ragdoll state (%i)", numNodes, configuration.m_initialState.size()); return nullptr; } - AZStd::unique_ptr ragdoll = AZStd::make_unique(sceneHandle); - ragdoll->SetParentIndices(parentIndices); + Ragdoll* ragdoll = aznew Ragdoll(sceneHandle); + ragdoll->SetParentIndices(configuration.m_parentIndices); auto* sceneInterface = AZ::Interface::Get(); if (sceneInterface == nullptr) @@ -192,7 +191,7 @@ namespace PhysX for (size_t nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) { Physics::RagdollNodeConfiguration& nodeConfig = configuration.m_nodes[nodeIndex]; - const Physics::RagdollNodeState& nodeState = initialState[nodeIndex]; + const Physics::RagdollNodeState& nodeState = configuration.m_initialState[nodeIndex]; Physics::CharacterColliderNodeConfiguration* colliderNodeConfig = configuration.m_colliders.FindNodeConfigByName(nodeConfig.m_debugName); if (colliderNodeConfig) @@ -212,22 +211,20 @@ namespace PhysX } nodeConfig.m_colliderAndShapeData = shapes; } + nodeConfig.m_startSimulationEnabled = false; + nodeConfig.m_position = nodeState.m_position; + nodeConfig.m_orientation = nodeState.m_orientation; - AzPhysics::SimulatedBodyHandle newBodyHandle = sceneInterface->AddSimulatedBody(sceneHandle, &nodeConfig); - if (newBodyHandle == AzPhysics::InvalidSimulatedBodyHandle) + AZStd::unique_ptr node = AZStd::make_unique(sceneHandle, nodeConfig); + if (node->GetRigidBodyHandle() != AzPhysics::InvalidSimulatedBodyHandle) + { + ragdoll->AddNode(AZStd::move(node)); + } + else { AZ_Error("PhysX Ragdoll", false, "Failed to create rigid body for ragdoll node %s", nodeConfig.m_debugName.c_str()); - return nullptr; + node.reset(); } - sceneInterface->DisableSimulationOfBody(sceneHandle, newBodyHandle); - auto* rigidBody = azdynamic_cast(sceneInterface->GetSimulatedBodyFromHandle(sceneHandle, newBodyHandle)); - - physx::PxRigidDynamic* pxRigidDynamic = static_cast(rigidBody->GetNativePointer()); - physx::PxTransform transform(PxMathConvert(nodeState.m_position), PxMathConvert(nodeState.m_orientation)); - pxRigidDynamic->setGlobalPose(transform); - - AZStd::unique_ptr node = AZStd::make_unique(rigidBody, newBodyHandle); - ragdoll->AddNode(AZStd::move(node)); } // Set up joints. Needs a second pass because child nodes in the ragdoll config aren't guaranteed to have @@ -235,7 +232,7 @@ namespace PhysX size_t rootIndex = SIZE_MAX; for (size_t nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) { - size_t parentIndex = parentIndices[nodeIndex]; + size_t parentIndex = configuration.m_parentIndices[nodeIndex]; if (parentIndex < numNodes) { physx::PxRigidDynamic* parentActor = ragdoll->GetPxRigidDynamic(parentIndex); diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.h b/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.h index 07aa4008d3..e919426457 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.h +++ b/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.h @@ -40,11 +40,8 @@ namespace PhysX //! Creates a ragdoll based on the specified setup and initial pose. //! @param configuration Information about collider geometry and joint setup required to initialize the ragdoll. - //! @param initialState Initial settings for the positions, orientations and velocities of the ragdoll nodes. - //! @param parentIndices Identifies the parent ragdoll node for each node in the ragdoll. //! @param sceneHandle A handle to the physics scene in which the ragdoll should be created. - AZStd::unique_ptr CreateRagdoll(Physics::RagdollConfiguration& configuration, - const Physics::RagdollState& initialState, const ParentIndices& parentIndices, AzPhysics::SceneHandle sceneHandle); + Ragdoll* CreateRagdoll(Physics::RagdollConfiguration& configuration, AzPhysics::SceneHandle sceneHandle); //! Creates a joint drive with properties based on the input values. //! The input values are validated and the damping ratio is used to calculate the damping value used internally. diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/API/Ragdoll.cpp b/Gems/PhysX/Code/Source/PhysXCharacters/API/Ragdoll.cpp index 72cb511e21..5249781e31 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/API/Ragdoll.cpp +++ b/Gems/PhysX/Code/Source/PhysXCharacters/API/Ragdoll.cpp @@ -45,7 +45,7 @@ namespace PhysX AZ::SerializeContext* serializeContext = azrtti_cast(context); if (serializeContext) { - serializeContext->Class() + serializeContext->Class() ->Version(1) ; } @@ -56,7 +56,7 @@ namespace PhysX m_nodes.push_back(AZStd::move(node)); } - void Ragdoll::SetParentIndices(const ParentIndices& parentIndices) + void Ragdoll::SetParentIndices(const Physics::ParentIndices& parentIndices) { m_parentIndices = parentIndices; } @@ -109,7 +109,6 @@ namespace PhysX this->ApplyQueuedDisableSimulation(); }) { - m_simulating = false; m_sceneOwner = sceneHandle; } @@ -117,14 +116,7 @@ namespace PhysX { m_sceneStartSimHandler.Disconnect(); - if (auto* sceneInterface = AZ::Interface::Get()) - { - const size_t numNodes = m_nodes.size(); - for (size_t nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) - { - sceneInterface->RemoveSimulatedBody(m_sceneOwner, m_nodes[nodeIndex]->GetRigidBodyHandle()); - } - } + m_nodes.clear(); //the nodes destructor will remove the simulated body from the scene. } void Ragdoll::ApplyQueuedEnableSimulation() @@ -204,7 +196,6 @@ namespace PhysX sceneInterface->EnableSimulationOfBody(m_sceneOwner, m_nodes[nodeIndex]->GetRigidBodyHandle()); } - else { AZ_Error("PhysX Ragdoll", false, "Invalid PhysX actor for node index %i", nodeIndex); @@ -222,8 +213,7 @@ namespace PhysX } sceneInterface->RegisterSceneSimulationStartHandler(m_sceneOwner, m_sceneStartSimHandler); - - m_simulating = true; + sceneInterface->EnableSimulationOfBody(m_sceneOwner, m_bodyHandle); } void Ragdoll::EnableSimulationQueued(const Physics::RagdollState& initialState) @@ -276,7 +266,7 @@ namespace PhysX } } - m_simulating = false; + sceneInterface->DisableSimulationOfBody(m_sceneOwner, m_bodyHandle); } void Ragdoll::DisableSimulationQueued() diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/API/Ragdoll.h b/Gems/PhysX/Code/Source/PhysXCharacters/API/Ragdoll.h index 46bae6648b..7bf807bcc5 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/API/Ragdoll.h +++ b/Gems/PhysX/Code/Source/PhysXCharacters/API/Ragdoll.h @@ -19,8 +19,6 @@ namespace PhysX { - using ParentIndices = AZStd::vector; - /// PhysX specific implementation of generic physics API Ragdoll class. class Ragdoll : public Physics::Ragdoll @@ -29,7 +27,7 @@ namespace PhysX friend class RagdollComponent; AZ_CLASS_ALLOCATOR(Ragdoll, AZ::SystemAllocator, 0); - AZ_TYPE_INFO_LEGACY(PhysX::Ragdoll, "{55D477B5-B922-4D3E-89FE-7FB7B9FDD635}", Physics::Ragdoll); + AZ_RTTI(PhysX::Ragdoll, "{55D477B5-B922-4D3E-89FE-7FB7B9FDD635}", Physics::Ragdoll); static void Reflect(AZ::ReflectContext* context); Ragdoll() = default; @@ -38,7 +36,7 @@ namespace PhysX ~Ragdoll(); void AddNode(AZStd::unique_ptr node); - void SetParentIndices(const ParentIndices& parentIndices); + void SetParentIndices(const Physics::ParentIndices& parentIndices); void SetRootIndex(size_t nodeIndex); physx::PxRigidDynamic* GetPxRigidDynamic(size_t nodeIndex) const; physx::PxTransform GetRootPxTransform() const; @@ -75,7 +73,7 @@ namespace PhysX void ApplyQueuedDisableSimulation(); AZStd::vector> m_nodes; - ParentIndices m_parentIndices; + Physics::ParentIndices m_parentIndices; AZ::Outcome m_rootIndex = AZ::Failure(); /// Queued initial state for the ragdoll, for EnableSimulationQueued, to be applied prior to the world update. diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/API/RagdollNode.cpp b/Gems/PhysX/Code/Source/PhysXCharacters/API/RagdollNode.cpp index 63d62144f8..6e3b97212b 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/API/RagdollNode.cpp +++ b/Gems/PhysX/Code/Source/PhysXCharacters/API/RagdollNode.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -30,14 +31,14 @@ namespace PhysX } } - RagdollNode::RagdollNode(AzPhysics::RigidBody* rigidBody, AzPhysics::SimulatedBodyHandle rigidBodyHandle) - : m_rigidBody(rigidBody) - , m_rigidBodyHandle(rigidBodyHandle) + RagdollNode::RagdollNode(AzPhysics::SceneHandle sceneHandle, Physics::RagdollNodeConfiguration& nodeConfig) { - physx::PxRigidDynamic* pxRigidDynamic = static_cast(m_rigidBody->GetNativePointer()); - m_actorUserData = PhysX::ActorData(pxRigidDynamic); - m_actorUserData.SetRagdollNode(this); - m_actorUserData.SetEntityId(m_rigidBody->GetEntityId()); + CreatePhysicsBody(sceneHandle, nodeConfig); + } + + RagdollNode::~RagdollNode() + { + DestroyPhysicsBody(); } void RagdollNode::SetJoint(const AZStd::shared_ptr& joint) @@ -124,4 +125,47 @@ namespace PhysX { return m_rigidBodyHandle; } + + void RagdollNode::CreatePhysicsBody(AzPhysics::SceneHandle sceneHandle, Physics::RagdollNodeConfiguration& nodeConfig) + { + if (auto* sceneInterface = AZ::Interface::Get()) + { + m_rigidBodyHandle = sceneInterface->AddSimulatedBody(sceneHandle, &nodeConfig); + if (m_rigidBodyHandle == AzPhysics::InvalidSimulatedBodyHandle) + { + AZ_Error("PhysX RagdollNode", false, "Failed to create rigid body for ragdoll node %s", nodeConfig.m_debugName.c_str()); + return; + } + m_rigidBody = azdynamic_cast(sceneInterface->GetSimulatedBodyFromHandle(sceneHandle, m_rigidBodyHandle)); + } + if (m_rigidBody == nullptr) + { + AZ_Error("PhysX RagdollNode", false, "Failed to create rigid body for ragdoll node %s", nodeConfig.m_debugName.c_str()); + return; + } + m_sceneOwner = sceneHandle; + + physx::PxRigidDynamic* pxRigidDynamic = static_cast(m_rigidBody->GetNativePointer()); + physx::PxTransform transform(PxMathConvert(nodeConfig.m_position), PxMathConvert(nodeConfig.m_orientation)); + pxRigidDynamic->setGlobalPose(transform); + + m_actorUserData = PhysX::ActorData(pxRigidDynamic); + m_actorUserData.SetRagdollNode(this); + m_actorUserData.SetEntityId(m_rigidBody->GetEntityId()); + } + + void RagdollNode::DestroyPhysicsBody() + { + if (m_rigidBody != nullptr) + { + if (auto* sceneInterface = AZ::Interface::Get()) + { + sceneInterface->RemoveSimulatedBody(m_sceneOwner, m_rigidBodyHandle); + } + m_rigidBody = nullptr; + m_rigidBodyHandle = AzPhysics::InvalidSimulatedBodyHandle; + m_sceneOwner = AzPhysics::InvalidSceneHandle; + } + } + } // namespace PhysX diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/API/RagdollNode.h b/Gems/PhysX/Code/Source/PhysXCharacters/API/RagdollNode.h index c23930e25e..0567723c01 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/API/RagdollNode.h +++ b/Gems/PhysX/Code/Source/PhysXCharacters/API/RagdollNode.h @@ -29,8 +29,8 @@ namespace PhysX static void Reflect(AZ::ReflectContext* context); RagdollNode() = default; - explicit RagdollNode(AzPhysics::RigidBody* rigidBody, AzPhysics::SimulatedBodyHandle rigidBodyHandle); - ~RagdollNode() = default; + explicit RagdollNode(AzPhysics::SceneHandle sceneHandle, Physics::RagdollNodeConfiguration& nodeConfig); + ~RagdollNode(); void SetJoint(const AZStd::shared_ptr& joint); @@ -58,9 +58,13 @@ namespace PhysX AzPhysics::SimulatedBodyHandle GetRigidBodyHandle() const; private: + void CreatePhysicsBody(AzPhysics::SceneHandle sceneHandle, Physics::RagdollNodeConfiguration& nodeConfig); + void DestroyPhysicsBody(); + AZStd::shared_ptr m_joint; AzPhysics::RigidBody* m_rigidBody; AzPhysics::SimulatedBodyHandle m_rigidBodyHandle = AzPhysics::InvalidSimulatedBodyHandle; + AzPhysics::SceneHandle m_sceneOwner = AzPhysics::InvalidSceneHandle; PhysX::ActorData m_actorUserData; }; } // namespace PhysX diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/Components/CharacterControllerComponent.cpp b/Gems/PhysX/Code/Source/PhysXCharacters/Components/CharacterControllerComponent.cpp index 26ef5f0032..ca02554036 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/Components/CharacterControllerComponent.cpp +++ b/Gems/PhysX/Code/Source/PhysXCharacters/Components/CharacterControllerComponent.cpp @@ -412,7 +412,6 @@ namespace PhysX AZ::TransformBus::EventResult(entityTranslation, GetEntityId(), &AZ::TransformBus::Events::GetWorldTranslation); m_characterConfig->m_position = entityTranslation; - AZ_Assert(m_controller == nullptr, "Calling create CharacterControllerComponent::CreateController() with an already created controller."); if (auto* sceneInterface = AZ::Interface::Get()) { AzPhysics::SimulatedBodyHandle bodyHandle = sceneInterface->AddSimulatedBody(defaultSceneHandle, m_characterConfig.get()); @@ -451,8 +450,8 @@ namespace PhysX if (auto* sceneInterface = AZ::Interface::Get()) { sceneInterface->RemoveSimulatedBody(m_controller->m_sceneOwner, m_controller->m_bodyHandle); - m_controller = nullptr; } + m_controller = nullptr; m_preSimulateHandler.Disconnect(); diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/Components/RagdollComponent.cpp b/Gems/PhysX/Code/Source/PhysXCharacters/Components/RagdollComponent.cpp index 56627ff7b9..d120e3d6b0 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/Components/RagdollComponent.cpp +++ b/Gems/PhysX/Code/Source/PhysXCharacters/Components/RagdollComponent.cpp @@ -55,6 +55,16 @@ namespace PhysX } } + if (classElement.GetVersion() < 3) + { + int ragdollElementIndex = classElement.FindElement(AZ_CRC_CE("PhysXRagdoll")); + + if (ragdollElementIndex >= 0) + { + classElement.RemoveElement(ragdollElementIndex); + } + } + return true; } @@ -66,8 +76,7 @@ namespace PhysX if (serializeContext) { serializeContext->Class() - ->Version(2, &VersionConverter) - ->Field("PhysXRagdoll", &RagdollComponent::m_ragdoll) + ->Version(3, &VersionConverter) ->Field("PositionIterations", &RagdollComponent::m_positionIterations) ->Field("VelocityIterations", &RagdollComponent::m_velocityIterations) ->Field("EnableJointProjection", &RagdollComponent::m_enableJointProjection) @@ -187,7 +196,7 @@ namespace PhysX Physics::Ragdoll* RagdollComponent::GetRagdoll() { - return m_ragdoll.get(); + return m_ragdoll; } void RagdollComponent::GetState(Physics::RagdollState& ragdollState) const @@ -250,7 +259,7 @@ namespace PhysX AzPhysics::SimulatedBody* RagdollComponent::GetWorldBody() { - return m_ragdoll.get(); + return GetRagdoll(); } AzPhysics::SceneQueryHit RagdollComponent::RayCast(const AzPhysics::RayCastRequest& request) @@ -283,8 +292,8 @@ namespace PhysX return; } - ParentIndices parentIndices; - parentIndices.resize(numNodes); + + ragdollConfiguration.m_parentIndices.resize(numNodes); for (size_t nodeIndex = 0; nodeIndex < numNodes; nodeIndex++) { AZStd::string parentName; @@ -292,7 +301,7 @@ namespace PhysX AzFramework::CharacterPhysicsDataRequestBus::EventResult(parentName, GetEntityId(), &AzFramework::CharacterPhysicsDataRequests::GetParentNodeName, nodeName); AZ::Outcome parentIndex = Utils::Characters::GetNodeIndex(ragdollConfiguration, parentName); - parentIndices[nodeIndex] = parentIndex ? parentIndex.GetValue() : SIZE_MAX; + ragdollConfiguration.m_parentIndices[nodeIndex] = parentIndex ? parentIndex.GetValue() : SIZE_MAX; ragdollConfiguration.m_nodes[nodeIndex].m_entityId = GetEntityId(); } @@ -303,12 +312,17 @@ namespace PhysX AZ::Transform entityTransform = AZ::Transform::CreateIdentity(); AZ::TransformBus::EventResult(entityTransform, GetEntityId(), &AZ::TransformBus::Events::GetWorldTM); - Physics::RagdollState bindPoseWorld = GetBindPoseWorld(bindPose, entityTransform); + ragdollConfiguration.m_initialState = GetBindPoseWorld(bindPose, entityTransform); AzPhysics::SceneHandle defaultSceneHandle = AzPhysics::InvalidSceneHandle; Physics::DefaultWorldBus::BroadcastResult(defaultSceneHandle, &Physics::DefaultWorldRequests::GetDefaultSceneHandle); - m_ragdoll = Utils::Characters::CreateRagdoll(ragdollConfiguration, bindPoseWorld, parentIndices, defaultSceneHandle); - if (!m_ragdoll) + + if (auto* sceneInterface = AZ::Interface::Get()) + { + AzPhysics::SimulatedBodyHandle bodyHandle = sceneInterface->AddSimulatedBody(defaultSceneHandle, &ragdollConfiguration); + m_ragdoll = azdynamic_cast(sceneInterface->GetSimulatedBodyFromHandle(defaultSceneHandle, bodyHandle)); + } + if (m_ragdoll == nullptr) { AZ_Error("PhysX Ragdoll Component", false, "Failed to create ragdoll."); return; @@ -358,7 +372,11 @@ namespace PhysX AzFramework::RagdollPhysicsNotificationBus::Event(GetEntityId(), &AzFramework::RagdollPhysicsNotifications::OnRagdollDeactivated); - m_ragdoll.reset(); + if (auto* sceneInterface = AZ::Interface::Get()) + { + sceneInterface->RemoveSimulatedBody(m_ragdoll->m_sceneOwner, m_ragdoll->m_bodyHandle); + } + m_ragdoll = nullptr; } } diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/Components/RagdollComponent.h b/Gems/PhysX/Code/Source/PhysXCharacters/Components/RagdollComponent.h index 77a4c992a3..1b616dda79 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/Components/RagdollComponent.h +++ b/Gems/PhysX/Code/Source/PhysXCharacters/Components/RagdollComponent.h @@ -32,7 +32,7 @@ namespace PhysX , public AzFramework::CharacterPhysicsDataNotificationBus::Handler { public: - AZ_COMPONENT(RagdollComponent, "{B89498F8-4718-42FE-A457-A377DD0D61A0}"); + AZ_COMPONENT(PhysX::RagdollComponent, "{B89498F8-4718-42FE-A457-A377DD0D61A0}"); static void Reflect(AZ::ReflectContext* context); @@ -105,7 +105,7 @@ namespace PhysX bool IsJointProjectionVisible(); - AZStd::unique_ptr m_ragdoll; + Ragdoll* m_ragdoll; /// Minimum number of position iterations to perform in the PhysX solver. /// Lower iteration counts are less expensive but may behave less realistically. AZ::u32 m_positionIterations = 16; diff --git a/Gems/PhysX/Code/Source/Scene/PhysXScene.cpp b/Gems/PhysX/Code/Source/Scene/PhysXScene.cpp index 1e6eee774e..03bbac9fd4 100644 --- a/Gems/PhysX/Code/Source/Scene/PhysXScene.cpp +++ b/Gems/PhysX/Code/Source/Scene/PhysXScene.cpp @@ -209,6 +209,13 @@ namespace PhysX return controller; } + AzPhysics::SimulatedBody* CreateRagdollBody(PhysXScene* scene, + const Physics::RagdollConfiguration* ragdollConfig) + { + return Utils::Characters::CreateRagdoll(const_cast(*ragdollConfig), + scene->GetSceneHandle()); + } + //helper to perform a ray cast AzPhysics::SceneQueryHits RayCast(const AzPhysics::RayCastRequest* raycastRequest, AZStd::vector& raycastBuffer, @@ -622,6 +629,15 @@ namespace PhysX { newBody = Internal::CreateCharacterBody(this, azdynamic_cast(simulatedBodyConfig)); } + else if (azrtti_istypeof(simulatedBodyConfig)) + { + newBody = Internal::CreateRagdollBody(this, azdynamic_cast(simulatedBodyConfig)); + } + else + { + AZ_Warning("PhysXScene", false, "Unknown SimulatedBodyConfiguration."); + return AzPhysics::InvalidSimulatedBodyHandle; + } if (newBody != nullptr) { @@ -648,8 +664,11 @@ namespace PhysX newBody->m_bodyHandle = newBodyHandle; m_simulatedBodyAddedEvent.Signal(m_sceneHandle, newBodyHandle); - // Enable simulation by default (not signaling OnSimulationBodySimulationEnabled event) - EnableSimulationOfBodyInternal(*newBody); + // Enable simulation by default (not signaling OnSimulationBodySimulationEnabled event) + if (simulatedBodyConfig->m_startSimulationEnabled) + { + EnableSimulationOfBodyInternal(*newBody); + } return newBodyHandle; } @@ -878,7 +897,8 @@ namespace PhysX void PhysXScene::EnableSimulationOfBodyInternal(AzPhysics::SimulatedBody& body) { //character controller is a special actor and only needs the m_simulating flag set, - if (!azrtti_istypeof(body)) + if (!azrtti_istypeof(body) && + !azrtti_istypeof(body)) { auto pxActor = static_cast(body.GetNativePointer()); AZ_Assert(pxActor, "Simulated Body doesn't have a valid physx actor"); @@ -904,7 +924,8 @@ namespace PhysX void PhysXScene::DisableSimulationOfBodyInternal(AzPhysics::SimulatedBody& body) { //character controller is a special actor and only needs the m_simulating flag set, - if (!azrtti_istypeof(body)) + if (!azrtti_istypeof(body) && + !azrtti_istypeof(body)) { auto pxActor = static_cast(body.GetNativePointer()); AZ_Assert(pxActor, "Simulated Body doesn't have a valid physx actor"); @@ -948,11 +969,14 @@ namespace PhysX void PhysXScene::ClearDeferedDeletions() { - for (auto& simulatedBody : m_deferredDeletions) + // swap the deletions in case the simulated body + // manages more bodies and removes them on destruction (ie. Ragdoll). + AZStd::vector deletions; + deletions.swap(m_deferredDeletions); + for (auto* simulatedBody : deletions) { delete simulatedBody; } - m_deferredDeletions.clear(); } void PhysXScene::ProcessTriggerEvents() diff --git a/Gems/PhysX/Code/Tests/Benchmarks/PhysXCharactersRagdollBenchmarks.cpp b/Gems/PhysX/Code/Tests/Benchmarks/PhysXCharactersRagdollBenchmarks.cpp index 149dfac30b..4f905342be 100644 --- a/Gems/PhysX/Code/Tests/Benchmarks/PhysXCharactersRagdollBenchmarks.cpp +++ b/Gems/PhysX/Code/Tests/Benchmarks/PhysXCharactersRagdollBenchmarks.cpp @@ -125,19 +125,24 @@ namespace PhysX::Benchmarks return GetTPose(AZ::Vector3::CreateZero(), simulationType); } - AZStd::unique_ptr CreateRagdoll(AzPhysics::SceneHandle sceneHandle) + PhysX::Ragdoll* CreateRagdoll(AzPhysics::SceneHandle sceneHandle) { Physics::RagdollConfiguration* configuration = AZ::Utils::LoadObjectFromFile(AZ::Test::GetEngineRootPath() + "/Gems/PhysX/Code/Tests/RagdollConfiguration.xml"); - Physics::RagdollState initialState = GetTPose(); - PhysX::ParentIndices parentIndices; + configuration->m_initialState = GetTPose(); + configuration->m_parentIndices.reserve(configuration->m_nodes.size()); for (int i = 0; i < configuration->m_nodes.size(); i++) { - parentIndices.push_back(RagdollTestData::ParentIndices[i]); + configuration->m_parentIndices.push_back(RagdollTestData::ParentIndices[i]); } - return PhysX::Utils::Characters::CreateRagdoll(*configuration, initialState, parentIndices, sceneHandle); + if (auto* sceneInterface = AZ::Interface::Get()) + { + AzPhysics::SimulatedBodyHandle bodyHandle = sceneInterface->AddSimulatedBody(sceneHandle, configuration); + return azdynamic_cast(sceneInterface->GetSimulatedBodyFromHandle(sceneHandle, bodyHandle)); + } + return nullptr; } //! BM_Ragdoll_AtRest - This test just spawns the requested number of ragdolls and places them near the terrain @@ -148,7 +153,7 @@ namespace PhysX::Benchmarks const int numRagdolls = static_cast(state.range(0)); //create ragdolls - AZStd::vector> ragdolls; + AZStd::vector ragdolls; ragdolls.reserve(numRagdolls); for (int i = 0; i < numRagdolls; i++) { @@ -218,7 +223,7 @@ namespace PhysX::Benchmarks washingMachineCentre, RagdollConstants::WashingMachine::BladeRPM); //create ragdolls - AZStd::vector> ragdolls; + AZStd::vector ragdolls; ragdolls.reserve(numRagdolls); for (int i = 0; i < numRagdolls; i++) { diff --git a/Gems/PhysX/Code/Tests/RagdollTests.cpp b/Gems/PhysX/Code/Tests/RagdollTests.cpp index 8e3bdc69c3..ec803c1707 100644 --- a/Gems/PhysX/Code/Tests/RagdollTests.cpp +++ b/Gems/PhysX/Code/Tests/RagdollTests.cpp @@ -37,7 +37,7 @@ namespace PhysX - + )DELIMITER"; @@ -63,19 +63,24 @@ namespace PhysX return ragdollState; } - AZStd::unique_ptr CreateRagdoll(AzPhysics::SceneHandle sceneHandle) + Ragdoll* CreateRagdoll(AzPhysics::SceneHandle sceneHandle) { Physics::RagdollConfiguration* configuration = AZ::Utils::LoadObjectFromFile(AZ::Test::GetCurrentExecutablePath() + "/Test.Assets/Gems/PhysX/Code/Tests/RagdollConfiguration.xml"); - Physics::RagdollState initialState = GetTPose(); - ParentIndices parentIndices; + configuration->m_initialState = GetTPose(); + configuration->m_parentIndices.reserve(configuration->m_nodes.size()); for (int i = 0; i < configuration->m_nodes.size(); i++) { - parentIndices.push_back(RagdollTestData::ParentIndices[i]); + configuration->m_parentIndices.push_back(RagdollTestData::ParentIndices[i]); } - return Utils::Characters::CreateRagdoll(*configuration, initialState, parentIndices, sceneHandle); + if (auto* sceneInterface = AZ::Interface::Get()) + { + AzPhysics::SimulatedBodyHandle bodyHandle = sceneInterface->AddSimulatedBody(sceneHandle, configuration); + return azdynamic_cast(sceneInterface->GetSimulatedBodyFromHandle(sceneHandle, bodyHandle)); + } + return nullptr; } #if AZ_TRAIT_DISABLE_FAILED_PHYSICS_TESTS From 8f265f2d3bbdd5ae3a7ffb7dfb473b2284a01798 Mon Sep 17 00:00:00 2001 From: amzn-sean <75276488+amzn-sean@users.noreply.github.com> Date: Thu, 22 Apr 2021 15:19:41 +0100 Subject: [PATCH 12/33] fixed failing tests --- .../collision_events_script.scriptcanvas | 3898 +++++++++-------- .../onpostphysicsupdate.scriptcanvas | 2257 +++++----- .../ontick.scriptcanvas | 1592 +++---- ...tCanvas_ShapeCastVerification.scriptcanvas | 1295 +++--- ..._ScriptCanvas_PostUpdateEvent.scriptcanvas | 890 ++-- ...7_ScriptCanvas_PreUpdateEvent.scriptcanvas | 1099 ++--- 6 files changed, 5667 insertions(+), 5364 deletions(-) diff --git a/AutomatedTesting/Levels/Physics/C12712452_ScriptCanvas_CollisionEvents/collision_events_script.scriptcanvas b/AutomatedTesting/Levels/Physics/C12712452_ScriptCanvas_CollisionEvents/collision_events_script.scriptcanvas index a422f072a5..34e80f3ccd 100644 --- a/AutomatedTesting/Levels/Physics/C12712452_ScriptCanvas_CollisionEvents/collision_events_script.scriptcanvas +++ b/AutomatedTesting/Levels/Physics/C12712452_ScriptCanvas_CollisionEvents/collision_events_script.scriptcanvas @@ -3,7 +3,7 @@ - + @@ -16,21 +16,21 @@ - + - + - + - + - + @@ -39,23 +39,9 @@ - - - - - - - - - - - - - - - - + + @@ -76,12 +62,13 @@ + - + @@ -91,8 +78,8 @@ - - + + @@ -101,7 +88,7 @@ - + @@ -113,12 +100,13 @@ + - + @@ -128,8 +116,8 @@ - - + + @@ -150,12 +138,13 @@ + - + @@ -164,9 +153,14 @@ + + + + + - - + + @@ -175,24 +169,59 @@ - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -201,9 +230,14 @@ + + + + + - - + + @@ -212,24 +246,25 @@ - - + + - + - + + - + @@ -239,34 +274,35 @@ - + - - + + - - + + - + + - + @@ -276,34 +312,35 @@ - + - - + + - + - + + - + @@ -312,37 +349,18 @@ - - - - - - - - - - - - - - - - - - - - + - - + + - + @@ -354,53 +372,37 @@ + - - + + - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - + + + + + + + + @@ -408,72 +410,127 @@ - + - + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -482,9 +539,14 @@ + + + + + - - + + @@ -494,23 +556,24 @@ - + - + + - + @@ -520,8 +583,8 @@ - - + + @@ -530,7 +593,7 @@ - + @@ -542,12 +605,13 @@ + - + @@ -557,8 +621,8 @@ - - + + @@ -579,12 +643,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -593,9 +704,14 @@ + + + + + - - + + @@ -604,24 +720,25 @@ - - + + - + - + + - + @@ -631,34 +748,35 @@ - + - - + + - - + + - + + - + @@ -668,34 +786,35 @@ - + - - + + - + - + + - + @@ -704,37 +823,18 @@ - - - - - - - - - - - - - - - - - - - - + - - + + - + @@ -746,53 +846,37 @@ + - - + + - - - - - - - + + - + - - - - - - - - - - - - - - - - - - - - + + + + + + + + @@ -800,21 +884,21 @@ - + - + - + - + - + @@ -824,13 +908,22 @@ - + + + + + + + + + + - - + + @@ -840,23 +933,24 @@ - + - + + - + @@ -866,8 +960,8 @@ - - + + @@ -888,12 +982,13 @@ + - + @@ -903,8 +998,8 @@ - - + + @@ -925,58 +1020,13 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -986,8 +1036,8 @@ - - + + @@ -996,7 +1046,7 @@ - + @@ -1008,12 +1058,13 @@ + - + @@ -1023,8 +1074,8 @@ - - + + @@ -1036,7 +1087,7 @@ - + @@ -1045,12 +1096,13 @@ + - + @@ -1060,34 +1112,73 @@ - - + + - - + + - + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1101,9 +1192,23 @@ + + + + + + + + + + + + + + - - + + @@ -1124,24 +1229,54 @@ + - - + + - + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + @@ -1149,21 +1284,21 @@ - + - + - + - + - + @@ -1172,12 +1307,26 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + @@ -1195,12 +1344,13 @@ + - + @@ -1210,8 +1360,8 @@ - - + + @@ -1220,7 +1370,7 @@ - + @@ -1232,12 +1382,13 @@ + - + @@ -1247,8 +1398,8 @@ - - + + @@ -1269,12 +1420,13 @@ + - + @@ -1283,14 +1435,9 @@ - - - - - - - + + @@ -1299,162 +1446,25 @@ - - + + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1463,14 +1473,9 @@ - - - - - - - + + @@ -1479,24 +1484,25 @@ - - + + - + - + + - + @@ -1506,34 +1512,35 @@ - + - - + + - - + + - + + - + @@ -1543,34 +1550,35 @@ - + - - + + - + - + + - + @@ -1579,18 +1587,37 @@ + + + + + + + + + + + + + + + + + + + - + - - - + + + - + @@ -1602,36 +1629,54 @@ + - - + + - - + + + + + + + - + - - - - - - - + + + + + + + + + + + + + + + + + + + + - @@ -1639,21 +1684,21 @@ - + - + - + - + - + @@ -1663,8 +1708,8 @@ - - + + @@ -1685,12 +1730,13 @@ + - + @@ -1700,8 +1746,8 @@ - - + + @@ -1710,7 +1756,7 @@ - + @@ -1722,12 +1768,13 @@ + - + @@ -1736,14 +1783,9 @@ - - - - - - - + + @@ -1752,24 +1794,25 @@ - - + + - + + - + @@ -1779,10 +1822,10 @@ - - + + - + @@ -1790,60 +1833,24 @@ - + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1853,8 +1860,8 @@ - - + + @@ -1863,7 +1870,7 @@ - + @@ -1875,12 +1882,13 @@ + - + @@ -1889,9 +1897,14 @@ + + + + + - - + + @@ -1900,24 +1913,25 @@ - - + + - + + - + @@ -1927,10 +1941,10 @@ - - + + - + @@ -1938,23 +1952,24 @@ - + - + + - + @@ -1963,14 +1978,9 @@ - - - - - - - + + @@ -1979,58 +1989,25 @@ - - + + - + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -2040,34 +2017,35 @@ - - + + - + - - + + - + + - + @@ -2077,8 +2055,8 @@ - - + + @@ -2090,7 +2068,7 @@ - + @@ -2099,12 +2077,104 @@ + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2114,143 +2184,165 @@ - - + + - + - - + + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + - + @@ -2259,7 +2351,7 @@ - + @@ -2310,6 +2402,7 @@ + @@ -2347,6 +2440,7 @@ + @@ -2384,6 +2478,7 @@ + @@ -2421,21 +2516,21 @@ - + - + - + - + - + @@ -2446,7 +2541,7 @@ - + @@ -2467,12 +2562,13 @@ + - + @@ -2483,7 +2579,7 @@ - + @@ -2504,12 +2600,13 @@ + - + @@ -2518,11 +2615,54 @@ + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2541,18 +2681,28 @@ + + + + + + + + + + + + + + + + + - - - - - - - - + @@ -2560,21 +2710,21 @@ - + - + - + - + @@ -2611,12 +2761,13 @@ + - + @@ -2648,12 +2799,13 @@ + - + @@ -2685,6 +2837,7 @@ + @@ -2706,7 +2859,7 @@ - + @@ -2722,21 +2875,21 @@ - + - + - + - + - + @@ -2746,22 +2899,13 @@ - - - - - - - + - - - - - + + @@ -2771,23 +2915,24 @@ - + - + + - + @@ -2797,8 +2942,8 @@ - - + + @@ -2819,12 +2964,13 @@ + - + @@ -2834,8 +2980,8 @@ - - + + @@ -2856,12 +3002,13 @@ + - + @@ -2871,71 +3018,81 @@ - - + + - - + + - + - + + - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -2945,34 +3102,35 @@ - - + + - - + + - - + + - + + - + @@ -2982,34 +3140,35 @@ - - + + - - + + - + - + + - + @@ -3018,37 +3177,18 @@ - - - - - - - - - - - - - - - - - - - - + - + - + @@ -3060,53 +3200,19 @@ + - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - + + + + + + @@ -3114,21 +3220,21 @@ - + - + - + - + - + @@ -3137,13 +3243,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -3153,24 +3292,25 @@ - - + + - + + - + @@ -3179,8 +3319,13 @@ + + + + + - + @@ -3191,23 +3336,24 @@ - + - + + - + @@ -3217,10 +3363,10 @@ - + - + @@ -3228,17 +3374,18 @@ - + - + + @@ -3254,21 +3401,118 @@ - + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -3276,21 +3520,21 @@ - + - + - + - + @@ -3327,12 +3571,13 @@ + - + @@ -3364,12 +3609,13 @@ + - + @@ -3401,43 +3647,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -3458,16 +3668,16 @@ - - - + + + - + @@ -3475,7 +3685,7 @@ - + @@ -3526,6 +3736,7 @@ + @@ -3563,6 +3774,7 @@ + @@ -3600,6 +3812,7 @@ + @@ -3637,58 +3850,21 @@ - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -3698,8 +3874,8 @@ - - + + @@ -3720,49 +3896,13 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -3772,8 +3912,8 @@ - - + + @@ -3794,12 +3934,13 @@ + - + @@ -3809,8 +3950,8 @@ - - + + @@ -3831,12 +3972,13 @@ + - + @@ -3851,8 +3993,8 @@ - - + + @@ -3873,49 +4015,47 @@ + - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -3924,9 +4064,23 @@ + + + + + + + + + + + + + + - - + + @@ -3935,10 +4089,10 @@ - + - + @@ -3947,12 +4101,13 @@ + - + @@ -3962,34 +4117,35 @@ - - + + - + - - + + - + + - + @@ -3999,8 +4155,8 @@ - - + + @@ -4012,7 +4168,7 @@ - + @@ -4021,103 +4177,13 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -4126,14 +4192,9 @@ - - - - - - - + + @@ -4142,24 +4203,25 @@ - - + + - + + - + @@ -4169,8 +4231,8 @@ - - + + @@ -4179,10 +4241,10 @@ - + - + @@ -4191,12 +4253,13 @@ + - + @@ -4206,34 +4269,35 @@ - + - - + + - + - + + - + @@ -4243,11 +4307,11 @@ - + - + @@ -4265,58 +4329,13 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -4325,8 +4344,27 @@ + + + + + + + + + + + + + + + + + + + - + @@ -4337,23 +4375,87 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -4362,8 +4464,13 @@ + + + + + - + @@ -4373,24 +4480,25 @@ - - + + - + + - + @@ -4399,13 +4507,8 @@ - - - - - - + @@ -4416,23 +4519,24 @@ - + - + + - + @@ -4442,10 +4546,10 @@ - + - + @@ -4453,17 +4557,18 @@ - + - + + @@ -4479,12 +4584,21 @@ - + - + + + + + + + + + + @@ -4492,21 +4606,21 @@ - + - + - + @@ -4538,12 +4652,13 @@ + - + @@ -4575,12 +4690,13 @@ + - + @@ -4612,16 +4728,17 @@ + - + - + @@ -4631,21 +4748,21 @@ - + - + - + - + - + @@ -4654,14 +4771,9 @@ - - - - - - - + + @@ -4671,23 +4783,24 @@ - + - + + - + @@ -4697,8 +4810,8 @@ - - + + @@ -4707,7 +4820,7 @@ - + @@ -4719,12 +4832,13 @@ + - + @@ -4734,10 +4848,10 @@ - + - + @@ -4745,47 +4859,30 @@ - + - + + - - - - - - - - - - - - - - - - + - - - - - - - - + + - + + + + @@ -4793,7 +4890,7 @@ - + @@ -4839,6 +4936,7 @@ + @@ -4876,6 +4974,7 @@ + @@ -4918,6 +5017,7 @@ + @@ -4955,6 +5055,7 @@ + @@ -4985,7 +5086,7 @@ - + @@ -4995,7 +5096,7 @@ - + @@ -5003,7 +5104,7 @@ - + @@ -5016,7 +5117,7 @@ - + @@ -5026,7 +5127,7 @@ - + @@ -5034,7 +5135,7 @@ - + @@ -5047,7 +5148,7 @@ - + @@ -5057,7 +5158,7 @@ - + @@ -5065,7 +5166,7 @@ - + @@ -5078,7 +5179,7 @@ - + @@ -5088,7 +5189,7 @@ - + @@ -5096,7 +5197,7 @@ - + @@ -5109,7 +5210,7 @@ - + @@ -5119,7 +5220,7 @@ - + @@ -5127,7 +5228,7 @@ - + @@ -5140,7 +5241,7 @@ - + @@ -5150,7 +5251,7 @@ - + @@ -5158,7 +5259,7 @@ - + @@ -5171,7 +5272,7 @@ - + @@ -5181,7 +5282,7 @@ - + @@ -5189,7 +5290,7 @@ - + @@ -5202,7 +5303,7 @@ - + @@ -5212,7 +5313,7 @@ - + @@ -5220,7 +5321,7 @@ - + @@ -5233,7 +5334,7 @@ - + @@ -5243,7 +5344,7 @@ - + @@ -5251,7 +5352,7 @@ - + @@ -5264,7 +5365,7 @@ - + @@ -5274,7 +5375,7 @@ - + @@ -5282,7 +5383,7 @@ - + @@ -5295,7 +5396,7 @@ - + @@ -5305,7 +5406,7 @@ - + @@ -5313,7 +5414,7 @@ - + @@ -5326,7 +5427,7 @@ - + @@ -5336,7 +5437,7 @@ - + @@ -5344,7 +5445,7 @@ - + @@ -5357,7 +5458,7 @@ - + @@ -5367,7 +5468,7 @@ - + @@ -5375,7 +5476,7 @@ - + @@ -5388,7 +5489,7 @@ - + @@ -5398,7 +5499,7 @@ - + @@ -5406,7 +5507,7 @@ - + @@ -5419,7 +5520,7 @@ - + @@ -5429,7 +5530,7 @@ - + @@ -5437,7 +5538,7 @@ - + @@ -5450,7 +5551,7 @@ - + @@ -5460,7 +5561,7 @@ - + @@ -5468,7 +5569,7 @@ - + @@ -5481,7 +5582,7 @@ - + @@ -5491,7 +5592,7 @@ - + @@ -5499,7 +5600,7 @@ - + @@ -5512,7 +5613,7 @@ - + @@ -5522,7 +5623,7 @@ - + @@ -5530,7 +5631,7 @@ - + @@ -5543,7 +5644,7 @@ - + @@ -5553,7 +5654,7 @@ - + @@ -5561,7 +5662,7 @@ - + @@ -5574,7 +5675,7 @@ - + @@ -5584,7 +5685,7 @@ - + @@ -5592,7 +5693,7 @@ - + @@ -5605,7 +5706,7 @@ - + @@ -5615,7 +5716,7 @@ - + @@ -5623,7 +5724,7 @@ - + @@ -5636,7 +5737,7 @@ - + @@ -5646,7 +5747,7 @@ - + @@ -5654,7 +5755,7 @@ - + @@ -5667,7 +5768,7 @@ - + @@ -5677,7 +5778,7 @@ - + @@ -5685,7 +5786,7 @@ - + @@ -5698,7 +5799,7 @@ - + @@ -5708,7 +5809,7 @@ - + @@ -5716,7 +5817,7 @@ - + @@ -5729,7 +5830,7 @@ - + @@ -5739,7 +5840,7 @@ - + @@ -5747,7 +5848,7 @@ - + @@ -5760,7 +5861,7 @@ - + @@ -5770,7 +5871,7 @@ - + @@ -5778,7 +5879,7 @@ - + @@ -5791,7 +5892,7 @@ - + @@ -5801,7 +5902,7 @@ - + @@ -5809,7 +5910,7 @@ - + @@ -5822,7 +5923,7 @@ - + @@ -5832,7 +5933,7 @@ - + @@ -5840,7 +5941,7 @@ - + @@ -5853,7 +5954,7 @@ - + @@ -5863,7 +5964,7 @@ - + @@ -5871,7 +5972,7 @@ - + @@ -5884,7 +5985,7 @@ - + @@ -5894,7 +5995,7 @@ - + @@ -5902,7 +6003,7 @@ - + @@ -5915,7 +6016,7 @@ - + @@ -5925,7 +6026,7 @@ - + @@ -5933,7 +6034,7 @@ - + @@ -5946,7 +6047,7 @@ - + @@ -5956,7 +6057,7 @@ - + @@ -5964,7 +6065,7 @@ - + @@ -5977,7 +6078,7 @@ - + @@ -5987,7 +6088,7 @@ - + @@ -5995,7 +6096,7 @@ - + @@ -6008,7 +6109,7 @@ - + @@ -6018,7 +6119,7 @@ - + @@ -6026,7 +6127,7 @@ - + @@ -6039,7 +6140,7 @@ - + @@ -6049,7 +6150,7 @@ - + @@ -6057,7 +6158,7 @@ - + @@ -6070,7 +6171,7 @@ - + @@ -6080,7 +6181,7 @@ - + @@ -6088,7 +6189,7 @@ - + @@ -6101,7 +6202,7 @@ - + @@ -6111,7 +6212,7 @@ - + @@ -6119,7 +6220,7 @@ - + @@ -6132,7 +6233,7 @@ - + @@ -6142,7 +6243,7 @@ - + @@ -6150,7 +6251,7 @@ - + @@ -6163,7 +6264,7 @@ - + @@ -6173,7 +6274,7 @@ - + @@ -6181,7 +6282,7 @@ - + @@ -6194,7 +6295,7 @@ - + @@ -6204,7 +6305,7 @@ - + @@ -6212,7 +6313,7 @@ - + @@ -6225,7 +6326,7 @@ - + @@ -6235,7 +6336,7 @@ - + @@ -6243,7 +6344,7 @@ - + @@ -6256,7 +6357,7 @@ - + @@ -6266,7 +6367,7 @@ - + @@ -6274,7 +6375,7 @@ - + @@ -6287,7 +6388,7 @@ - + @@ -6297,7 +6398,7 @@ - + @@ -6305,7 +6406,7 @@ - + @@ -6318,7 +6419,7 @@ - + @@ -6328,7 +6429,7 @@ - + @@ -6336,7 +6437,7 @@ - + @@ -6349,7 +6450,7 @@ - + @@ -6359,7 +6460,7 @@ - + @@ -6367,7 +6468,7 @@ - + @@ -6386,7 +6487,7 @@ - + @@ -6394,7 +6495,7 @@ - + @@ -6402,83 +6503,41 @@ - + - + - + - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -6486,27 +6545,27 @@ - + - + - + - + @@ -6520,7 +6579,7 @@ - + @@ -6533,28 +6592,28 @@ - + - + - + - + @@ -6562,62 +6621,41 @@ - + - - - + + + + - - - + + + + - - - - - - - - + - - - - + + + - - - - - - - - - - - - - - - - - - + + + @@ -6625,7 +6663,7 @@ - + @@ -6633,27 +6671,27 @@ - + - + - + - + @@ -6667,20 +6705,22 @@ - + - - - + + + + - - - + + + + @@ -6691,17 +6731,15 @@ - - - - + + + - - - - + + + @@ -6709,41 +6747,46 @@ - + - - - + + + + + + + + + - + - - + + - + - - + + - + - - - - + + + @@ -6751,46 +6794,41 @@ - + - - - - - - - - + + - + - - + + - + - - + + - - - - - - + - + + + + + + + @@ -6798,41 +6836,41 @@ - + - - - + + + + - - - + + + + - + - - - - + + + - - - - + + + @@ -6840,41 +6878,41 @@ - + - - - + + + + - - - + + + + - + - - - - + + + - - - - + + + @@ -6882,7 +6920,7 @@ - + @@ -6890,7 +6928,7 @@ - + @@ -6910,7 +6948,7 @@ - + @@ -6924,7 +6962,7 @@ - + @@ -6937,28 +6975,28 @@ - + - + - + - + @@ -6966,41 +7004,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -7008,7 +7046,7 @@ - + @@ -7021,28 +7059,28 @@ - + - + - + - + @@ -7050,41 +7088,41 @@ - + - - - + + + + - - - + + + + - + - - - - + + + - - - - + + + @@ -7092,20 +7130,22 @@ - + - - - + + + + - - - + + + + @@ -7116,17 +7156,15 @@ - - - - + + + - - - - + + + @@ -7134,41 +7172,41 @@ - + - - - + + + + - - - + + + + - + - - - - + + + - - - - + + + @@ -7176,41 +7214,41 @@ - + - - - + + + + - - - + + + + - + - - - - + + + - - - - + + + @@ -7218,7 +7256,7 @@ - + @@ -7231,7 +7269,7 @@ - + @@ -7252,7 +7290,7 @@ - + @@ -7260,41 +7298,41 @@ - + - - - + + + + - - - + + + + - + - - - - + + + - - - - + + + @@ -7302,7 +7340,7 @@ - + @@ -7310,27 +7348,27 @@ - + - + - + - + @@ -7344,7 +7382,7 @@ - + @@ -7357,28 +7395,28 @@ - + - + - + - + @@ -7386,27 +7424,78 @@ - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -7417,10 +7506,22 @@ - - + + - + + + + + + + + + + + + + @@ -7431,23 +7532,27 @@ - + - - + + - + - + + + + + - + @@ -7455,27 +7560,23 @@ - - - - - + - + - - + + - + - + @@ -7497,7 +7598,7 @@ - + @@ -7524,14 +7625,15 @@ - + + - + @@ -7558,14 +7660,15 @@ - + + - + @@ -7592,7 +7695,8 @@ - + + diff --git a/AutomatedTesting/Levels/Physics/C14902098_ScriptCanvas_PostPhysicsUpdate/onpostphysicsupdate.scriptcanvas b/AutomatedTesting/Levels/Physics/C14902098_ScriptCanvas_PostPhysicsUpdate/onpostphysicsupdate.scriptcanvas index 88e3333298..f4ca23b882 100644 --- a/AutomatedTesting/Levels/Physics/C14902098_ScriptCanvas_PostPhysicsUpdate/onpostphysicsupdate.scriptcanvas +++ b/AutomatedTesting/Levels/Physics/C14902098_ScriptCanvas_PostPhysicsUpdate/onpostphysicsupdate.scriptcanvas @@ -3,7 +3,7 @@ - + @@ -16,21 +16,21 @@ - + - + - + - + - + @@ -41,7 +41,7 @@ - + @@ -62,12 +62,13 @@ + - + @@ -77,8 +78,8 @@ - - + + @@ -99,12 +100,13 @@ + - + @@ -114,10 +116,10 @@ - - + + - + @@ -125,48 +127,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -178,46 +138,13 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -226,49 +153,36 @@ - - - - - - - - - - - - - - - - + + - + - - + + - + + - + @@ -278,34 +192,35 @@ - - + + - + - - + + - + + - + @@ -315,10 +230,10 @@ - - + + - + @@ -326,34 +241,205 @@ - + - + + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -362,24 +448,25 @@ - - + + - + + - + @@ -389,8 +476,8 @@ - - + + @@ -399,10 +486,10 @@ - + - + @@ -411,12 +498,13 @@ + - + @@ -425,27 +513,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + - - - - + @@ -455,73 +562,71 @@ - - + + - + + - - + + - - - - - - - + + - + - - - - - - + + + + + + + + - + - + - + - + - + - + @@ -553,12 +658,13 @@ + - + @@ -590,12 +696,13 @@ + - + @@ -604,23 +711,18 @@ - - - - - - + - - + + - + @@ -632,12 +734,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -646,13 +780,8 @@ - - - - - - + @@ -663,7 +792,131 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -674,6 +927,7 @@ + @@ -716,6 +970,7 @@ + @@ -753,6 +1008,7 @@ + @@ -803,21 +1059,21 @@ - + - + - + - + - + @@ -827,8 +1083,8 @@ - - + + @@ -849,12 +1105,13 @@ + - + @@ -864,8 +1121,8 @@ - - + + @@ -874,7 +1131,7 @@ - + @@ -886,12 +1143,13 @@ + - + @@ -901,65 +1159,35 @@ - - + + - - + + - + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -968,14 +1196,9 @@ - - - - - - - + + @@ -984,24 +1207,25 @@ - - + + - + + - + @@ -1011,8 +1235,8 @@ - - + + @@ -1021,7 +1245,7 @@ - + @@ -1033,12 +1257,13 @@ + - + @@ -1047,18 +1272,23 @@ + + + + + - - + + - + - + @@ -1070,12 +1300,13 @@ + - + @@ -1085,10 +1316,10 @@ - + - + @@ -1096,47 +1327,207 @@ - + - + + - - - - - - - - - - - - - + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + @@ -1144,21 +1535,21 @@ - + - + - + - + - + @@ -1169,7 +1560,7 @@ - + @@ -1190,12 +1581,13 @@ + - + @@ -1206,7 +1598,7 @@ - + @@ -1227,12 +1619,56 @@ + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1264,12 +1700,13 @@ + - + @@ -1301,12 +1738,13 @@ + - + @@ -1338,12 +1776,13 @@ + - + @@ -1375,21 +1814,38 @@ + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -1399,7 +1855,7 @@ - + @@ -1409,7 +1865,7 @@ - + @@ -1425,7 +1881,7 @@ - + @@ -1472,6 +1928,7 @@ + @@ -1509,6 +1966,7 @@ + @@ -1529,125 +1987,21 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + @@ -1656,9 +2010,23 @@ + + + + + + + + + + + + + + - + @@ -1679,12 +2047,13 @@ + - + @@ -1695,7 +2064,7 @@ - + @@ -1716,12 +2085,13 @@ + - + @@ -1731,7 +2101,7 @@ - + @@ -1753,12 +2123,13 @@ + - + @@ -1768,7 +2139,7 @@ - + @@ -1790,12 +2161,13 @@ + - + @@ -1805,8 +2177,8 @@ - - + + @@ -1818,7 +2190,7 @@ - + @@ -1827,12 +2199,13 @@ + - + @@ -1846,363 +2219,22 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + - + @@ -2224,12 +2256,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -2239,34 +2321,35 @@ - - + + - + - - + + - + + - + @@ -2276,10 +2359,10 @@ - - + + - + @@ -2287,23 +2370,24 @@ - + - + + - + @@ -2313,10 +2397,10 @@ - - + + - + @@ -2324,23 +2408,24 @@ - + - + + - + @@ -2349,18 +2434,23 @@ + + + + + - - + + - + - + @@ -2372,65 +2462,25 @@ + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2440,7 +2490,7 @@ - + @@ -2450,7 +2500,7 @@ - + @@ -2458,7 +2508,7 @@ - + @@ -2471,7 +2521,7 @@ - + @@ -2481,7 +2531,7 @@ - + @@ -2489,7 +2539,7 @@ - + @@ -2502,7 +2552,7 @@ - + @@ -2512,7 +2562,7 @@ - + @@ -2520,7 +2570,7 @@ - + @@ -2533,7 +2583,7 @@ - + @@ -2543,7 +2593,7 @@ - + @@ -2551,7 +2601,7 @@ - + @@ -2564,7 +2614,7 @@ - + @@ -2574,7 +2624,7 @@ - + @@ -2582,7 +2632,7 @@ - + @@ -2595,7 +2645,7 @@ - + @@ -2605,7 +2655,7 @@ - + @@ -2613,7 +2663,7 @@ - + @@ -2626,7 +2676,7 @@ - + @@ -2636,7 +2686,7 @@ - + @@ -2644,7 +2694,7 @@ - + @@ -2657,7 +2707,7 @@ - + @@ -2667,7 +2717,7 @@ - + @@ -2675,7 +2725,7 @@ - + @@ -2688,7 +2738,7 @@ - + @@ -2698,7 +2748,7 @@ - + @@ -2706,7 +2756,7 @@ - + @@ -2719,7 +2769,7 @@ - + @@ -2729,7 +2779,7 @@ - + @@ -2737,7 +2787,7 @@ - + @@ -2750,7 +2800,7 @@ - + @@ -2760,7 +2810,7 @@ - + @@ -2768,7 +2818,7 @@ - + @@ -2781,7 +2831,7 @@ - + @@ -2791,7 +2841,7 @@ - + @@ -2799,7 +2849,7 @@ - + @@ -2812,7 +2862,7 @@ - + @@ -2822,7 +2872,7 @@ - + @@ -2830,7 +2880,7 @@ - + @@ -2843,7 +2893,7 @@ - + @@ -2853,7 +2903,7 @@ - + @@ -2861,7 +2911,7 @@ - + @@ -2880,7 +2930,7 @@ - + @@ -2888,41 +2938,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -2930,62 +2980,46 @@ - + - - - - - - - - - - - + + + - + - - - + + + + - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + @@ -2993,41 +3027,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -3035,41 +3069,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -3077,41 +3111,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -3119,22 +3153,20 @@ - + - - - - + + + - - - - + + + @@ -3145,15 +3177,17 @@ - - - + + + + - - - + + + + @@ -3161,46 +3195,62 @@ - + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + - - + + - + - - + + - + - - - + + + + @@ -3208,41 +3258,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -3250,41 +3300,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -3292,41 +3342,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -3365,23 +3415,23 @@ - + - - + + - + - + - + @@ -3389,15 +3439,15 @@ - - + + - + - + @@ -3415,7 +3465,7 @@ - + @@ -3441,6 +3491,7 @@ + diff --git a/AutomatedTesting/Levels/Physics/C14902098_ScriptCanvas_PostPhysicsUpdate/ontick.scriptcanvas b/AutomatedTesting/Levels/Physics/C14902098_ScriptCanvas_PostPhysicsUpdate/ontick.scriptcanvas index f49edd0f46..65f10d4f81 100644 --- a/AutomatedTesting/Levels/Physics/C14902098_ScriptCanvas_PostPhysicsUpdate/ontick.scriptcanvas +++ b/AutomatedTesting/Levels/Physics/C14902098_ScriptCanvas_PostPhysicsUpdate/ontick.scriptcanvas @@ -3,7 +3,7 @@ - + @@ -16,21 +16,127 @@ - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -41,7 +147,7 @@ - + @@ -62,12 +168,13 @@ + - + @@ -78,7 +185,7 @@ - + @@ -99,12 +206,13 @@ + - + @@ -119,7 +227,7 @@ - + @@ -141,12 +249,13 @@ + - + @@ -155,23 +264,18 @@ - - - - - - + - + - + @@ -183,12 +287,13 @@ + - + @@ -197,23 +302,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + @@ -225,12 +363,13 @@ + - + @@ -240,10 +379,10 @@ - + - + @@ -262,6 +401,7 @@ + @@ -275,36 +415,52 @@ - + - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - @@ -312,21 +468,21 @@ - + - + - + - + - + @@ -337,7 +493,7 @@ - + @@ -358,12 +514,13 @@ + - + @@ -373,8 +530,8 @@ - - + + @@ -395,12 +552,13 @@ + - + @@ -410,10 +568,10 @@ - - + + - + @@ -421,23 +579,24 @@ - + - + + - + @@ -446,55 +605,23 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - + - + @@ -506,85 +633,130 @@ + - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - - - - - - - - - + + + + + + @@ -593,7 +765,7 @@ - + @@ -639,6 +811,7 @@ + @@ -676,6 +849,7 @@ + @@ -713,6 +887,7 @@ + @@ -750,6 +925,7 @@ + @@ -787,6 +963,7 @@ + @@ -824,6 +1001,7 @@ + @@ -861,6 +1039,7 @@ + @@ -898,6 +1077,7 @@ + @@ -940,6 +1120,7 @@ + @@ -977,6 +1158,7 @@ + @@ -1056,125 +1238,21 @@ - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + @@ -1183,14 +1261,9 @@ - - - - - - - + + @@ -1200,23 +1273,24 @@ - + - + + - + @@ -1226,8 +1300,8 @@ - - + + @@ -1236,7 +1310,7 @@ - + @@ -1248,12 +1322,13 @@ + - + @@ -1263,7 +1338,7 @@ - + @@ -1285,12 +1360,13 @@ + - + @@ -1300,10 +1376,10 @@ - + - + @@ -1311,69 +1387,62 @@ - + - + + - - - - - - - + + + + + - - - - + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1383,34 +1452,94 @@ - - + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -1420,8 +1549,8 @@ - - + + @@ -1430,7 +1559,7 @@ - + @@ -1442,12 +1571,13 @@ + - + @@ -1457,8 +1587,8 @@ - - + + @@ -1479,12 +1609,13 @@ + - + @@ -1499,8 +1630,8 @@ - - + + @@ -1521,46 +1652,13 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1569,9 +1667,14 @@ + + + + + - - + + @@ -1581,23 +1684,24 @@ - + - + + - + @@ -1606,9 +1710,14 @@ + + + + + - - + + @@ -1617,24 +1726,25 @@ - - + + - + + - + @@ -1643,23 +1753,18 @@ - - - - - - + - + - + @@ -1671,12 +1776,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -1685,18 +1850,23 @@ + + + + + - + - + - + @@ -1708,12 +1878,13 @@ + - + @@ -1723,34 +1894,35 @@ - + - + - - + + - + + - + @@ -1760,10 +1932,10 @@ - + - + @@ -1782,12 +1954,13 @@ + - + @@ -1797,10 +1970,10 @@ - + - + @@ -1808,180 +1981,48 @@ - + - + + - + - + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - + @@ -1991,7 +2032,7 @@ - + @@ -2001,7 +2042,7 @@ - + @@ -2009,7 +2050,7 @@ - + @@ -2022,7 +2063,7 @@ - + @@ -2032,7 +2073,7 @@ - + @@ -2040,7 +2081,7 @@ - + @@ -2053,7 +2094,7 @@ - + @@ -2063,7 +2104,7 @@ - + @@ -2071,7 +2112,7 @@ - + @@ -2084,7 +2125,7 @@ - + @@ -2094,7 +2135,7 @@ - + @@ -2102,7 +2143,7 @@ - + @@ -2115,7 +2156,7 @@ - + @@ -2125,7 +2166,7 @@ - + @@ -2133,7 +2174,7 @@ - + @@ -2146,7 +2187,7 @@ - + @@ -2156,7 +2197,7 @@ - + @@ -2164,7 +2205,7 @@ - + @@ -2177,7 +2218,7 @@ - + @@ -2187,7 +2228,7 @@ - + @@ -2195,7 +2236,7 @@ - + @@ -2208,7 +2249,7 @@ - + @@ -2218,7 +2259,7 @@ - + @@ -2226,7 +2267,7 @@ - + @@ -2239,7 +2280,7 @@ - + @@ -2249,7 +2290,7 @@ - + @@ -2257,7 +2298,7 @@ - + @@ -2270,7 +2311,7 @@ - + @@ -2280,7 +2321,7 @@ - + @@ -2288,7 +2329,7 @@ - + @@ -2301,7 +2342,7 @@ - + @@ -2311,7 +2352,7 @@ - + @@ -2319,7 +2360,7 @@ - + @@ -2338,7 +2379,7 @@ - + @@ -2346,83 +2387,41 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - + - - - + + + + - - - + + + + @@ -2430,46 +2429,41 @@ - + - - - - - - - - - + + + - + - - + + - + - - + + - + - - - + + + + @@ -2477,41 +2471,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -2519,41 +2513,46 @@ - + - - - - + + + - - + + - + - - + + - + - - - + + + + + + + + + - - - + + + @@ -2561,41 +2560,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -2603,7 +2602,7 @@ - + @@ -2613,8 +2612,8 @@ - - + + @@ -2624,41 +2623,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -2666,41 +2665,83 @@ - + - - + + + + + + + + + + + + + + - + - + - - + + - + + + + + + + + + + + + + + + + - + - - - + + + + + + + + + + + + + + + + + + @@ -2711,15 +2752,15 @@ - + - + - + @@ -2727,15 +2768,15 @@ - + - + - + @@ -2779,6 +2820,7 @@ + diff --git a/AutomatedTesting/ScriptCanvas/C12712455_ScriptCanvas_ShapeCastVerification.scriptcanvas b/AutomatedTesting/ScriptCanvas/C12712455_ScriptCanvas_ShapeCastVerification.scriptcanvas index ff9fe5c64c..b24a477a2e 100644 --- a/AutomatedTesting/ScriptCanvas/C12712455_ScriptCanvas_ShapeCastVerification.scriptcanvas +++ b/AutomatedTesting/ScriptCanvas/C12712455_ScriptCanvas_ShapeCastVerification.scriptcanvas @@ -3,7 +3,7 @@ - + @@ -16,21 +16,21 @@ - + - + - + - + - + @@ -39,23 +39,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + @@ -67,12 +121,13 @@ + - + @@ -87,7 +142,7 @@ - + @@ -109,12 +164,13 @@ + - + @@ -146,12 +202,13 @@ + - + @@ -183,6 +240,7 @@ + @@ -195,36 +253,24 @@ - + - - - - - - - - - - - - - - + + - + - + @@ -232,16 +278,7 @@ - - - - - - - - - - + @@ -292,6 +329,7 @@ + @@ -334,6 +372,7 @@ + @@ -371,6 +410,7 @@ + @@ -408,6 +448,7 @@ + @@ -457,21 +498,21 @@ - + - + - + - + @@ -480,18 +521,23 @@ + + + + + - + - + - + @@ -503,12 +549,13 @@ + - + @@ -523,7 +570,7 @@ - + @@ -545,12 +592,13 @@ + - + @@ -582,12 +630,13 @@ + - + @@ -619,6 +668,7 @@ + @@ -631,24 +681,36 @@ - + + + + + + + + + + + + + - - + + - + - + @@ -656,7 +718,16 @@ - + + + + + + + + + + @@ -702,6 +773,7 @@ + @@ -739,6 +811,7 @@ + @@ -781,6 +854,7 @@ + @@ -823,6 +897,7 @@ + @@ -865,6 +940,7 @@ + @@ -907,6 +983,7 @@ + @@ -949,6 +1026,7 @@ + @@ -991,6 +1069,7 @@ + @@ -1028,6 +1107,7 @@ + @@ -1065,6 +1145,7 @@ + @@ -1102,6 +1183,7 @@ + @@ -1139,6 +1221,7 @@ + @@ -1176,6 +1259,7 @@ + @@ -1213,6 +1297,7 @@ + @@ -1296,110 +1381,275 @@ - + - + - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - - + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -1414,7 +1664,7 @@ - + @@ -1436,12 +1686,13 @@ + - + @@ -1456,7 +1707,7 @@ - + @@ -1478,12 +1729,13 @@ + - + @@ -1492,8 +1744,13 @@ + + + + + - + @@ -1504,23 +1761,24 @@ - + - + + - + @@ -1529,8 +1787,89 @@ + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1552,6 +1891,7 @@ + @@ -1601,324 +1941,21 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + + + + + + + + + + @@ -1926,21 +1963,21 @@ - + - + - + @@ -1977,12 +2014,13 @@ + - + @@ -2019,12 +2057,13 @@ + - + @@ -2056,12 +2095,13 @@ + - + @@ -2093,6 +2133,7 @@ + @@ -2105,7 +2146,7 @@ - + @@ -2144,7 +2185,7 @@ - + @@ -2154,7 +2195,7 @@ - + @@ -2162,7 +2203,7 @@ - + @@ -2175,7 +2216,7 @@ - + @@ -2185,7 +2226,7 @@ - + @@ -2193,7 +2234,7 @@ - + @@ -2206,7 +2247,7 @@ - + @@ -2216,7 +2257,7 @@ - + @@ -2224,7 +2265,7 @@ - + @@ -2237,7 +2278,7 @@ - + @@ -2247,7 +2288,7 @@ - + @@ -2255,7 +2296,7 @@ - + @@ -2268,7 +2309,7 @@ - + @@ -2278,7 +2319,7 @@ - + @@ -2286,7 +2327,7 @@ - + @@ -2299,7 +2340,7 @@ - + @@ -2309,7 +2350,7 @@ - + @@ -2317,7 +2358,7 @@ - + @@ -2330,7 +2371,7 @@ - + @@ -2340,7 +2381,7 @@ - + @@ -2348,7 +2389,7 @@ - + @@ -2361,7 +2402,7 @@ - + @@ -2371,7 +2412,7 @@ - + @@ -2379,7 +2420,7 @@ - + @@ -2392,7 +2433,7 @@ - + @@ -2402,7 +2443,7 @@ - + @@ -2410,7 +2451,7 @@ - + @@ -2429,7 +2470,7 @@ - + @@ -2437,41 +2478,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -2479,20 +2520,22 @@ - + - - - + + + + - - - + + + + @@ -2503,17 +2546,15 @@ - - - - + + + - - - - + + + @@ -2521,41 +2562,62 @@ - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + - + - - - - + + + - - - - + + + @@ -2563,20 +2625,22 @@ - + - - - + + + + - - - + + + + @@ -2587,38 +2651,15 @@ - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - + + + @@ -2626,7 +2667,7 @@ - + @@ -2639,14 +2680,14 @@ - + - + @@ -2660,7 +2701,7 @@ - + @@ -2668,20 +2709,22 @@ - + - - - + + + + - - - + + + + @@ -2692,17 +2735,15 @@ - - - - + + + - - - - + + + @@ -2710,7 +2751,7 @@ - + @@ -2718,27 +2759,27 @@ - + - + - + - + @@ -2752,41 +2793,41 @@ - + - - - - + + + - - - - + + + - + - - - + + + + - - - + + + + @@ -2797,20 +2838,20 @@ - - + + - + - - + + diff --git a/AutomatedTesting/ScriptCanvas/C14195074_ScriptCanvas_PostUpdateEvent.scriptcanvas b/AutomatedTesting/ScriptCanvas/C14195074_ScriptCanvas_PostUpdateEvent.scriptcanvas index 988184109a..b9f438a4f3 100644 --- a/AutomatedTesting/ScriptCanvas/C14195074_ScriptCanvas_PostUpdateEvent.scriptcanvas +++ b/AutomatedTesting/ScriptCanvas/C14195074_ScriptCanvas_PostUpdateEvent.scriptcanvas @@ -3,7 +3,7 @@ - + @@ -16,21 +16,21 @@ - + - + - + - + - + @@ -39,23 +39,9 @@ - - - - - - - - - - - - - - - + @@ -76,12 +62,13 @@ + - + @@ -92,7 +79,7 @@ - + @@ -113,12 +100,13 @@ + - + @@ -128,7 +116,7 @@ - + @@ -150,12 +138,13 @@ + - + @@ -165,7 +154,7 @@ - + @@ -187,12 +176,13 @@ + - + @@ -202,8 +192,8 @@ - - + + @@ -215,7 +205,7 @@ - + @@ -224,12 +214,13 @@ + - + @@ -243,23 +234,9 @@ - - - - - - - - - - - - - - - - + + @@ -280,61 +257,51 @@ + - - - - - - - + + + + + - - - - - - - - + + + + + - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -344,7 +311,7 @@ - + @@ -354,10 +321,10 @@ - + - + @@ -366,12 +333,13 @@ + - + @@ -381,10 +349,10 @@ - + - + @@ -392,23 +360,24 @@ - + - + + - + @@ -418,43 +387,104 @@ - + - - + + - + - + - + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + @@ -462,21 +492,21 @@ - + - + - + - + @@ -513,12 +543,13 @@ + - + @@ -527,13 +558,8 @@ - - - - - - + @@ -544,23 +570,24 @@ - + - + + - + @@ -570,34 +597,35 @@ - + - + - - + + - + + - + @@ -629,6 +657,7 @@ + @@ -641,33 +670,21 @@ - + - - - - - - - - - - - - - + - + @@ -678,21 +695,21 @@ - + - + - + - + @@ -729,12 +746,13 @@ + - + @@ -743,8 +761,13 @@ + + + + + - + @@ -755,23 +778,24 @@ - + - + + - + @@ -781,34 +805,35 @@ - + - + - - + + - + + - + @@ -840,6 +865,7 @@ + @@ -852,21 +878,33 @@ - + + + + + + + + + + + + + - + - + @@ -877,21 +915,21 @@ - + - + - + - + - + @@ -901,8 +939,8 @@ - - + + @@ -923,12 +961,13 @@ + - + @@ -938,8 +977,8 @@ - - + + @@ -948,7 +987,7 @@ - + @@ -960,12 +999,13 @@ + - + @@ -975,34 +1015,66 @@ - - + + - - + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -1011,9 +1083,23 @@ + + + + + + + + + + + + + + - - + + @@ -1022,7 +1108,7 @@ - + @@ -1034,12 +1120,13 @@ + - + @@ -1049,8 +1136,8 @@ - - + + @@ -1059,7 +1146,7 @@ - + @@ -1071,12 +1158,13 @@ + - + @@ -1085,14 +1173,9 @@ - - - - - - - + + @@ -1101,24 +1184,25 @@ - - + + - + + - + @@ -1128,10 +1212,10 @@ - - + + - + @@ -1139,23 +1223,24 @@ - + - + + - + @@ -1165,8 +1250,8 @@ - - + + @@ -1187,12 +1272,13 @@ + - + @@ -1201,45 +1287,27 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + @@ -1249,93 +1317,52 @@ - - + + - + - + + - - + + - - + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - @@ -1343,7 +1370,7 @@ - + @@ -1390,6 +1417,7 @@ + @@ -1427,6 +1455,7 @@ + @@ -1513,6 +1542,7 @@ + @@ -1599,6 +1629,7 @@ + @@ -1680,6 +1711,7 @@ + @@ -1720,7 +1752,7 @@ - + @@ -1730,7 +1762,7 @@ - + @@ -1738,7 +1770,7 @@ - + @@ -1751,7 +1783,7 @@ - + @@ -1761,7 +1793,7 @@ - + @@ -1769,7 +1801,7 @@ - + @@ -1782,7 +1814,7 @@ - + @@ -1792,7 +1824,7 @@ - + @@ -1800,7 +1832,7 @@ - + @@ -1813,7 +1845,7 @@ - + @@ -1823,7 +1855,7 @@ - + @@ -1831,7 +1863,7 @@ - + @@ -1844,7 +1876,7 @@ - + @@ -1854,7 +1886,7 @@ - + @@ -1862,7 +1894,7 @@ - + @@ -1875,7 +1907,7 @@ - + @@ -1885,7 +1917,7 @@ - + @@ -1893,7 +1925,7 @@ - + @@ -1906,7 +1938,7 @@ - + @@ -1916,7 +1948,7 @@ - + @@ -1924,7 +1956,7 @@ - + @@ -1937,7 +1969,7 @@ - + @@ -1947,7 +1979,7 @@ - + @@ -1955,7 +1987,7 @@ - + @@ -1974,7 +2006,7 @@ - + @@ -1982,41 +2014,41 @@ - + - - - + + + + - - - + + + + - + - - - - + + + - - - - + + + @@ -2024,7 +2056,7 @@ - + @@ -2037,28 +2069,28 @@ - + - + - + - + @@ -2066,20 +2098,46 @@ - + - - - - - - - + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2087,7 +2145,7 @@ - + @@ -2123,46 +2181,20 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - - + @@ -2170,7 +2202,7 @@ - + @@ -2178,27 +2210,27 @@ - + - + - + - + @@ -2212,41 +2244,41 @@ - + - - - + + + + - - - + + + + - + - - - - + + + - - - - + + + @@ -2276,7 +2308,7 @@ - + @@ -2284,7 +2316,7 @@ - + @@ -2296,7 +2328,7 @@ - + diff --git a/AutomatedTesting/ScriptCanvas/C14902097_ScriptCanvas_PreUpdateEvent.scriptcanvas b/AutomatedTesting/ScriptCanvas/C14902097_ScriptCanvas_PreUpdateEvent.scriptcanvas index a5b927dfc1..7db4f3a35c 100644 --- a/AutomatedTesting/ScriptCanvas/C14902097_ScriptCanvas_PreUpdateEvent.scriptcanvas +++ b/AutomatedTesting/ScriptCanvas/C14902097_ScriptCanvas_PreUpdateEvent.scriptcanvas @@ -3,7 +3,7 @@ - + @@ -16,21 +16,21 @@ - + - + - + - + @@ -39,8 +39,13 @@ + + + + + - + @@ -51,23 +56,24 @@ - + - + + - + @@ -77,7 +83,7 @@ - + @@ -87,7 +93,7 @@ - + @@ -99,12 +105,13 @@ + - + @@ -114,11 +121,11 @@ - + - - + + @@ -136,21 +143,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + - + - + @@ -158,21 +219,21 @@ - + - + - + - + - + @@ -182,13 +243,22 @@ - + + + + + + + + + + - - + + @@ -198,23 +268,24 @@ - + - + + - + @@ -223,14 +294,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + @@ -239,24 +343,25 @@ - - + + - + + - + @@ -266,8 +371,8 @@ - - + + @@ -276,7 +381,7 @@ - + @@ -288,12 +393,13 @@ + - + @@ -303,8 +409,8 @@ - - + + @@ -316,7 +422,7 @@ - + @@ -325,48 +431,143 @@ + - - - - - - + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + + + + + + + + - + - - - - - - - + + + + + + + + + + + + + + - @@ -374,7 +575,7 @@ - + @@ -421,6 +622,7 @@ + @@ -458,6 +660,7 @@ + @@ -544,6 +747,7 @@ + @@ -630,6 +834,7 @@ + @@ -711,6 +916,7 @@ + @@ -749,21 +955,21 @@ - + - + - + - + - + @@ -772,23 +978,9 @@ - - - - - - - - - - - - - - - - + + @@ -809,12 +1001,13 @@ + - + @@ -824,8 +1017,8 @@ - - + + @@ -834,7 +1027,7 @@ - + @@ -846,12 +1039,13 @@ + - + @@ -861,34 +1055,66 @@ - - + + - - + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -897,9 +1123,14 @@ + + + + + - - + + @@ -908,24 +1139,25 @@ - - + + - + + - + @@ -934,9 +1166,14 @@ + + + + + - - + + @@ -945,24 +1182,25 @@ - - + + - + - + + - + @@ -972,63 +1210,45 @@ - + - + - - + + - + + - + - - - - - - - - - - - - - - - - - - - - + - + @@ -1038,59 +1258,61 @@ - - + + - + + - - + + - - - - - - - + + - + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + @@ -1098,7 +1320,7 @@ - + @@ -1144,6 +1366,7 @@ + @@ -1181,6 +1404,7 @@ + @@ -1218,6 +1442,7 @@ + @@ -1255,6 +1480,7 @@ + @@ -1292,6 +1518,7 @@ + @@ -1334,6 +1561,7 @@ + @@ -1371,6 +1599,7 @@ + @@ -1408,6 +1637,7 @@ + @@ -1445,6 +1675,7 @@ + @@ -1482,6 +1713,7 @@ + @@ -1536,226 +1768,27 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - + + - - - - - - - - - + + + - + @@ -1765,7 +1798,7 @@ - + @@ -1775,7 +1808,7 @@ - + @@ -1783,7 +1816,7 @@ - + @@ -1796,7 +1829,7 @@ - + @@ -1806,7 +1839,7 @@ - + @@ -1814,7 +1847,7 @@ - + @@ -1827,7 +1860,7 @@ - + @@ -1837,7 +1870,7 @@ - + @@ -1845,7 +1878,7 @@ - + @@ -1858,7 +1891,7 @@ - + @@ -1868,7 +1901,7 @@ - + @@ -1876,7 +1909,7 @@ - + @@ -1889,7 +1922,7 @@ - + @@ -1899,7 +1932,7 @@ - + @@ -1907,7 +1940,7 @@ - + @@ -1920,7 +1953,7 @@ - + @@ -1930,7 +1963,7 @@ - + @@ -1938,7 +1971,7 @@ - + @@ -1951,7 +1984,7 @@ - + @@ -1961,7 +1994,7 @@ - + @@ -1969,7 +2002,7 @@ - + @@ -1982,7 +2015,7 @@ - + @@ -1992,7 +2025,7 @@ - + @@ -2000,7 +2033,7 @@ - + @@ -2019,7 +2052,7 @@ - + @@ -2027,20 +2060,22 @@ - + - - - + + + + - - - + + + + @@ -2051,17 +2086,15 @@ - - - - + + + - - - - + + + @@ -2069,62 +2102,46 @@ - + - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - + - - + + - + - - + + - + - - - - + + + @@ -2132,41 +2149,41 @@ - + - - - + + + + - - - + + + + - + - - - - + + + - - - - + + + @@ -2174,41 +2191,41 @@ - + - - - + + + + - - - + + + + - + - - - - + + + - - - - + + + @@ -2216,46 +2233,62 @@ - + - - - + + + + + + + + + + + - + - - - - + + + - - - - - - - - - + + + + + + + + + + + + - - - + + + + + + + + + @@ -2263,20 +2296,22 @@ - + - - - + + + + - - - + + + + @@ -2287,17 +2322,15 @@ - - - - + + + - - - - + + + @@ -2336,11 +2369,11 @@ - + - + @@ -2348,15 +2381,15 @@ - + - + - + From cd978eaa93f208ceecffbce139e7f7750e81b02a Mon Sep 17 00:00:00 2001 From: amzn-sean <75276488+amzn-sean@users.noreply.github.com> Date: Thu, 22 Apr 2021 17:22:26 +0100 Subject: [PATCH 13/33] fix potential memory leak --- Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp b/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp index 1c91818eb5..75cf536403 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp +++ b/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp @@ -184,6 +184,7 @@ namespace PhysX if (sceneInterface == nullptr) { AZ_Error("PhysX Ragdoll", false, "Unable to Create Ragdoll, Physics Scene Interface is missing."); + delete ragdoll; return nullptr; } @@ -206,6 +207,7 @@ namespace PhysX else { AZ_Error("PhysX Ragdoll", false, "Failed to create collider shape for ragdoll node %s", nodeConfig.m_debugName.c_str()); + delete ragdoll; return nullptr; } } @@ -287,6 +289,7 @@ namespace PhysX else { AZ_Error("PhysX Ragdoll", false, "Failed to create joint for node index %i.", nodeIndex); + delete ragdoll; return nullptr; } } From 53b29cbca50daf045fe0ddf715e1edd825c98e48 Mon Sep 17 00:00:00 2001 From: Gene Walters Date: Thu, 22 Apr 2021 16:36:47 -0700 Subject: [PATCH 14/33] updating based on feedback --- Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h b/Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h index 9b174c0620..ca0f6d996d 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h +++ b/Gems/EMotionFX/Code/Source/Integration/Assets/AssetCommon.h @@ -38,7 +38,8 @@ namespace EMotionFX void ReleaseEMotionFXData() { - m_emfxNativeData = {}; + m_emfxNativeData.clear(); + m_emfxNativeData.shrink_to_fit(); } AZStd::vector m_emfxNativeData; From 9f0075c9dfeda0869a50d30c3a2916d15b40bdd2 Mon Sep 17 00:00:00 2001 From: amzn-sean <75276488+amzn-sean@users.noreply.github.com> Date: Fri, 23 Apr 2021 11:00:08 +0100 Subject: [PATCH 15/33] cleanup of create ragdoll ptr handling --- .../Code/Source/PhysXCharacters/API/CharacterUtils.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp b/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp index 75cf536403..893e622701 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp +++ b/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp @@ -177,14 +177,13 @@ namespace PhysX return nullptr; } - Ragdoll* ragdoll = aznew Ragdoll(sceneHandle); + AZStd::unique_ptr ragdoll = AZStd::make_unique(sceneHandle); ragdoll->SetParentIndices(configuration.m_parentIndices); auto* sceneInterface = AZ::Interface::Get(); if (sceneInterface == nullptr) { AZ_Error("PhysX Ragdoll", false, "Unable to Create Ragdoll, Physics Scene Interface is missing."); - delete ragdoll; return nullptr; } @@ -207,7 +206,6 @@ namespace PhysX else { AZ_Error("PhysX Ragdoll", false, "Failed to create collider shape for ragdoll node %s", nodeConfig.m_debugName.c_str()); - delete ragdoll; return nullptr; } } @@ -289,7 +287,6 @@ namespace PhysX else { AZ_Error("PhysX Ragdoll", false, "Failed to create joint for node index %i.", nodeIndex); - delete ragdoll; return nullptr; } } @@ -301,8 +298,8 @@ namespace PhysX } ragdoll->SetRootIndex(rootIndex); - - return ragdoll; + + return ragdoll.release(); } physx::PxD6JointDrive CreateD6JointDrive(float stiffness, float dampingRatio, float forceLimit) From 833ca2767de09fa1605f4fbf390347410f1afb82 Mon Sep 17 00:00:00 2001 From: daimini Date: Fri, 23 Apr 2021 20:14:17 -0700 Subject: [PATCH 16/33] Fix a bug with level save erasing link information on Instances. All changes to non-root container entities are now saved as patches in the link to the parent instance. --- .../PrefabEditorEntityOwnershipService.cpp | 13 ---------- .../Prefab/Instance/InstanceSerializer.cpp | 2 +- .../AzToolsFramework/Prefab/Link/Link.cpp | 4 +++ .../Prefab/PrefabPublicHandler.cpp | 25 +++++++++++++++---- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp index 34fd4a4941..81233069a9 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Entity/PrefabEditorEntityOwnershipService.cpp @@ -242,19 +242,6 @@ namespace AzToolsFramework return false; } } - else - { - // The template is already loaded, this is the case of either saving as same name or different name(loaded from before). - // Update the template with the changes - AzToolsFramework::Prefab::PrefabDom dom; - bool success = AzToolsFramework::Prefab::PrefabDomUtils::StoreInstanceInPrefabDom(*m_rootInstance, dom); - if (!success) - { - AZ_Error("Prefab", false, "Failed to convert current root instance into a DOM when saving file '%.*s'", AZ_STRING_ARG(filename)); - return false; - } - m_prefabSystemComponent->UpdatePrefabTemplate(templateId, dom); - } Prefab::TemplateId prevTemplateId = m_rootInstance->GetTemplateId(); m_rootInstance->SetTemplateId(templateId); diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceSerializer.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceSerializer.cpp index bd02f3cd9b..836140eb74 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceSerializer.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Instance/InstanceSerializer.cpp @@ -200,7 +200,7 @@ namespace AzToolsFramework } return context.Report(result, - result.GetProcessing() == JSR::Processing::Completed ? "Succesfully loaded instance information for prefab." : + result.GetProcessing() == JSR::Processing::Completed ? "Successfully loaded instance information for prefab." : "Failed to load instance information for prefab"); } diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Link/Link.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Link/Link.cpp index 621a00b0bf..4dd31814b7 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Link/Link.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/Link/Link.cpp @@ -230,6 +230,10 @@ namespace AzToolsFramework AZ_Assert(instanceDom.IsObject(), "Link Id '%u' cannot be added because the DOM of the instance is not an object.", m_id); instanceDom.AddMember(rapidjson::StringRef(PrefabDomUtils::LinkIdName), rapidjson::Value().SetUint64(m_id), allocator); } + else + { + linkIdReference->get().SetUint64(m_id); + } } } // namespace Prefab diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp index 0c826ae817..1e9cc35230 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Prefab/PrefabPublicHandler.cpp @@ -392,12 +392,27 @@ namespace AzToolsFramework if (patch.IsArray() && !patch.Empty() && beforeState.IsObject()) { - // Update the state of the entity - PrefabUndoEntityUpdate* state = aznew PrefabUndoEntityUpdate(AZStd::to_string(static_cast(entityId))); - state->SetParent(parentUndoBatch); - state->Capture(beforeState, afterState, entityId); + if (IsInstanceContainerEntity(entityId) && !IsLevelInstanceContainerEntity(entityId)) + { + m_instanceToTemplateInterface->AppendEntityAliasToPatchPaths(patch, entityId); + + // Save these changes as patches to the link + PrefabUndoLinkUpdate* linkUpdate = + aznew PrefabUndoLinkUpdate(AZStd::to_string(static_cast(entityId))); + linkUpdate->SetParent(parentUndoBatch); + linkUpdate->Capture(patch, owningInstance->get().GetLinkId()); - state->Redo(); + linkUpdate->Redo(); + } + else + { + // Update the state of the entity + PrefabUndoEntityUpdate* state = aznew PrefabUndoEntityUpdate(AZStd::to_string(static_cast(entityId))); + state->SetParent(parentUndoBatch); + state->Capture(beforeState, afterState, entityId); + + state->Redo(); + } } // Update the cache From fb369541cbef03274fc61af8e2b58c58731b11b0 Mon Sep 17 00:00:00 2001 From: antonmic Date: Sat, 24 Apr 2021 11:27:13 -0700 Subject: [PATCH 17/33] Changing specularF0 variables back to specularF0Factor --- .../Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl | 4 ++-- Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl | 4 ++-- .../Materials/Types/StandardMultilayerPBR_ForwardPass.azsl | 4 ++-- .../Assets/Materials/Types/StandardPBR_ForwardPass.azsl | 4 ++-- .../Atom/Features/PBR/Surfaces/BasePbrSurfaceData.azsli | 6 +++--- .../Atom/Features/PBR/Surfaces/EnhancedSurface.azsli | 6 +++--- .../ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli | 6 +++--- .../Atom/Features/PBR/Surfaces/StandardSurface.azsli | 6 +++--- .../TestData/Materials/Types/AutoBrick_ForwardPass.azsl | 4 ++-- .../TestData/Materials/Types/MinimalPBR_ForwardPass.azsl | 4 ++-- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl index de97a2f8d2..3b2a9b8e42 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl @@ -219,9 +219,9 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float // ------- Specular ------- float2 specularUv = IN.m_uv[MaterialSrg::m_specularF0MapUvIndex]; - float specularF0 = GetSpecularInput(MaterialSrg::m_specularF0Map, MaterialSrg::m_sampler, specularUv, MaterialSrg::m_specularF0Factor, o_specularF0_useTexture); + float specularF0Factor = GetSpecularInput(MaterialSrg::m_specularF0Map, MaterialSrg::m_sampler, specularUv, MaterialSrg::m_specularF0Factor, o_specularF0_useTexture); - surface.SetAlbedoAndSpecularF0(baseColor, specularF0, metallic); + surface.SetAlbedoAndSpecularF0(baseColor, specularF0Factor, metallic); // ------- Roughness ------- diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl index e59196c558..84095ac163 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.azsl @@ -295,9 +295,9 @@ PbrLightingOutput SkinPS_Common(VSOutput IN) // ------- Specular ------- float2 specularUv = IN.m_uv[MaterialSrg::m_specularF0MapUvIndex]; - float specularF0 = GetSpecularInput(MaterialSrg::m_specularF0Map, MaterialSrg::m_sampler, specularUv, MaterialSrg::m_specularF0Factor, o_specularF0_useTexture); + float specularF0Factor = GetSpecularInput(MaterialSrg::m_specularF0Map, MaterialSrg::m_sampler, specularUv, MaterialSrg::m_specularF0Factor, o_specularF0_useTexture); - surface.SetAlbedoAndSpecularF0(baseColor, specularF0); + surface.SetAlbedoAndSpecularF0(baseColor, specularF0Factor); // ------- Roughness ------- diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl index 9e9543e449..560c7ab7eb 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR_ForwardPass.azsl @@ -270,9 +270,9 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float float layer1_specularF0Factor = GetSpecularInput(MaterialSrg::m_layer1_m_specularF0Map, MaterialSrg::m_sampler, uvLayer1[MaterialSrg::m_layer1_m_specularF0MapUvIndex], MaterialSrg::m_layer1_m_specularF0Factor, o_layer1_o_specularF0_useTexture); float layer2_specularF0Factor = GetSpecularInput(MaterialSrg::m_layer2_m_specularF0Map, MaterialSrg::m_sampler, uvLayer2[MaterialSrg::m_layer2_m_specularF0MapUvIndex], MaterialSrg::m_layer2_m_specularF0Factor, o_layer2_o_specularF0_useTexture); float layer3_specularF0Factor = GetSpecularInput(MaterialSrg::m_layer3_m_specularF0Map, MaterialSrg::m_sampler, uvLayer3[MaterialSrg::m_layer3_m_specularF0MapUvIndex], MaterialSrg::m_layer3_m_specularF0Factor, o_layer3_o_specularF0_useTexture); - float specularF0 = BlendLayers(layer1_specularF0Factor, layer2_specularF0Factor, layer3_specularF0Factor, blendMaskValues); + float specularF0Factor = BlendLayers(layer1_specularF0Factor, layer2_specularF0Factor, layer3_specularF0Factor, blendMaskValues); - surface.SetAlbedoAndSpecularF0(baseColor, specularF0, metallic); + surface.SetAlbedoAndSpecularF0(baseColor, specularF0Factor, metallic); // ------- Roughness ------- diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl index f769033fd2..4989b56892 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl @@ -178,9 +178,9 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float // ------- Specular ------- float2 specularUv = IN.m_uv[MaterialSrg::m_specularF0MapUvIndex]; - float specularF0 = GetSpecularInput(MaterialSrg::m_specularF0Map, MaterialSrg::m_sampler, specularUv, MaterialSrg::m_specularF0Factor, o_specularF0_useTexture); + float specularF0Factor = GetSpecularInput(MaterialSrg::m_specularF0Map, MaterialSrg::m_sampler, specularUv, MaterialSrg::m_specularF0Factor, o_specularF0_useTexture); - surface.SetAlbedoAndSpecularF0(baseColor, specularF0, metallic); + surface.SetAlbedoAndSpecularF0(baseColor, specularF0Factor, metallic); // ------- Roughness ------- diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/BasePbrSurfaceData.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/BasePbrSurfaceData.azsli index d17f89707d..ecb2a2f09b 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/BasePbrSurfaceData.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/BasePbrSurfaceData.azsli @@ -43,7 +43,7 @@ class BasePbrSurfaceData void CalculateRoughnessA(); //! Sets albedo and specularF0 using metallic workflow - void SetAlbedoAndSpecularF0(float3 baseColor, float inSpecularF0, float metallic); + void SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor, float metallic); }; // ------- Functions ------- @@ -85,9 +85,9 @@ void BasePbrSurfaceData::CalculateRoughnessA() } } -void BasePbrSurfaceData::SetAlbedoAndSpecularF0(float3 baseColor, float inSpecularF0, float metallic) +void BasePbrSurfaceData::SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor, float metallic) { - float3 dielectricSpecularF0 = MaxDielectricSpecularF0 * inSpecularF0; + float3 dielectricSpecularF0 = MaxDielectricSpecularF0 * specularF0Factor; // Compute albedo and specularF0 based on metalness albedo = lerp(baseColor, float3(0.0f, 0.0f, 0.0f), metallic); diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli index 9d4163c474..6a8d785a97 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli @@ -41,7 +41,7 @@ class Surface //: BasePbrSurfaceData void CalculateRoughnessA(); //! Sets albedo and specularF0 using metallic workflow - void SetAlbedoAndSpecularF0(float3 baseColor, float inSpecularF0, float metallic); + void SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor, float metallic); }; @@ -80,9 +80,9 @@ void Surface::CalculateRoughnessA() } } -void Surface::SetAlbedoAndSpecularF0(float3 baseColor, float inSpecularF0, float metallic) +void Surface::SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor, float metallic) { - float3 dielectricSpecularF0 = MaxDielectricSpecularF0 * inSpecularF0; + float3 dielectricSpecularF0 = MaxDielectricSpecularF0 * specularF0Factor; // Compute albedo and specularF0 based on metalness albedo = lerp(baseColor, float3(0.0f, 0.0f, 0.0f), metallic); diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli index 5092414a11..ffbb12e09d 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli @@ -40,7 +40,7 @@ class Surface //: BasePbrSurfaceData void CalculateRoughnessA(); //! Sets albedo and specularF0 using metallic workflow - void SetAlbedoAndSpecularF0(float3 baseColor, float inSpecularF0); + void SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor); }; @@ -79,9 +79,9 @@ void Surface::CalculateRoughnessA() } } -void Surface::SetAlbedoAndSpecularF0(float3 baseColor, float inSpecularF0) +void Surface::SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor) { albedo = baseColor; - specularF0 = MaxDielectricSpecularF0 * inSpecularF0; + specularF0 = MaxDielectricSpecularF0 * specularF0Factor; } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli index e6ca84c19e..e5a0a0efad 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli @@ -40,7 +40,7 @@ class Surface //: BasePbrSurfaceData void CalculateRoughnessA(); //! Sets albedo and specularF0 using metallic workflow - void SetAlbedoAndSpecularF0(float3 baseColor, float inSpecularF0, float metallic); + void SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor, float metallic); }; @@ -79,9 +79,9 @@ void Surface::CalculateRoughnessA() } } -void Surface::SetAlbedoAndSpecularF0(float3 baseColor, float inSpecularF0, float metallic) +void Surface::SetAlbedoAndSpecularF0(float3 baseColor, float specularF0Factor, float metallic) { - float3 dielectricSpecularF0 = MaxDielectricSpecularF0 * inSpecularF0; + float3 dielectricSpecularF0 = MaxDielectricSpecularF0 * specularF0Factor; // Compute albedo and specularF0 based on metalness albedo = lerp(baseColor, float3(0.0f, 0.0f, 0.0f), metallic); diff --git a/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl b/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl index 1da4973b1a..3373c90a81 100644 --- a/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl +++ b/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl @@ -176,8 +176,8 @@ ForwardPassOutput AutoBrick_ForwardPassPS(VSOutput IN) // Albedo, SpecularF0 const float metallic = 0.0f; - const float specularF0 = 0.5f; - surface.SetAlbedoAndSpecularF0(baseColor, specularF0, metallic); + const float specularF0Factor = 0.5f; + surface.SetAlbedoAndSpecularF0(baseColor, specularF0Factor, metallic); // Clear Coat, Transmission surface.clearCoat.InitializeToZero(); diff --git a/Gems/Atom/TestData/TestData/Materials/Types/MinimalPBR_ForwardPass.azsl b/Gems/Atom/TestData/TestData/Materials/Types/MinimalPBR_ForwardPass.azsl index 57b1381f9c..96d5f05e6e 100644 --- a/Gems/Atom/TestData/TestData/Materials/Types/MinimalPBR_ForwardPass.azsl +++ b/Gems/Atom/TestData/TestData/Materials/Types/MinimalPBR_ForwardPass.azsl @@ -71,8 +71,8 @@ ForwardPassOutput MinimalPBR_MainPassPS(VSOutput IN) surface.CalculateRoughnessA(); // Albedo, SpecularF0 - const float specularF0 = 0.5f; - surface.SetAlbedoAndSpecularF0(MinimalPBRSrg::m_baseColor, specularF0, MinimalPBRSrg::m_metallic); + const float specularF0Factor = 0.5f; + surface.SetAlbedoAndSpecularF0(MinimalPBRSrg::m_baseColor, specularF0Factor, MinimalPBRSrg::m_metallic); // Clear Coat, Transmission surface.clearCoat.InitializeToZero(); From 4f05cbeca9d0242751fb23780b79a14329ebe278 Mon Sep 17 00:00:00 2001 From: dmcdiar Date: Sun, 25 Apr 2021 19:13:16 -0700 Subject: [PATCH 18/33] Validated reflection probe visibility state when changing the cubemap type. --- .../EditorReflectionProbeComponent.cpp | 20 ++++++++++++++++--- .../EditorReflectionProbeComponent.h | 3 +++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.cpp b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.cpp index eac4213867..976b8f4267 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.cpp +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.cpp @@ -53,16 +53,20 @@ namespace AZ ->Attribute(AZ::Edit::Attributes::ViewportIcon, "editor/icons/components/viewport/component_placeholder.png") ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c)) ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->Attribute(AZ::Edit::Attributes::Visibility, AZ::Edit::PropertyVisibility::ShowChildrenOnly) ->Attribute(AZ::Edit::Attributes::PrimaryAssetType, AZ::AzTypeInfo::Uuid()) - ->ClassElement(AZ::Edit::ClassElements::Group, "Cubemap") + ->ClassElement(AZ::Edit::ClassElements::Group, "Cubemap Bake") ->Attribute(AZ::Edit::Attributes::AutoExpand, true) - ->DataElement(AZ::Edit::UIHandlers::Default, &EditorReflectionProbeComponent::m_useBakedCubemap, "Use Baked Cubemap", "Selects between a cubemap that captures the environment at location in the scene or a preauthored cubemap") - ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorReflectionProbeComponent::OnUseBakedCubemapChanged) ->UIElement(AZ::Edit::UIHandlers::Button, "Bake Reflection Probe", "Bake Reflection Probe") ->Attribute(AZ::Edit::Attributes::NameLabelOverride, "") ->Attribute(AZ::Edit::Attributes::ButtonText, "Bake Reflection Probe") ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorReflectionProbeComponent::BakeReflectionProbe) ->Attribute(AZ::Edit::Attributes::Visibility, &EditorReflectionProbeComponent::GetBakedCubemapVisibilitySetting) + ->ClassElement(AZ::Edit::ClassElements::Group, "Cubemap") + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ->DataElement(AZ::Edit::UIHandlers::Default, &EditorReflectionProbeComponent::m_useBakedCubemap, "Use Baked Cubemap", "Selects between a cubemap that captures the environment at location in the scene or a preauthored cubemap") + ->Attribute(AZ::Edit::Attributes::ChangeValidate, &EditorReflectionProbeComponent::OnUseBakedCubemapValidate) + ->Attribute(AZ::Edit::Attributes::ChangeNotify, &EditorReflectionProbeComponent::OnUseBakedCubemapChanged) ->DataElement(AZ::Edit::UIHandlers::MultiLineEdit, &EditorReflectionProbeComponent::m_bakedCubeMapRelativePath, "Baked Cubemap Path", "Baked Cubemap Path") ->Attribute(AZ::Edit::Attributes::ReadOnly, true) ->Attribute(AZ::Edit::Attributes::Visibility, &EditorReflectionProbeComponent::GetBakedCubemapVisibilitySetting) @@ -188,6 +192,16 @@ namespace AZ return false; } + AZ::Outcome EditorReflectionProbeComponent::OnUseBakedCubemapValidate([[maybe_unused]] void* newValue, [[maybe_unused]] const AZ::Uuid& valueType) + { + if (!m_controller.m_featureProcessor) + { + return AZ::Failure(AZStd::string("This Reflection Probe entity is hidden, it must be visible in order to change the cubemap type.")); + } + + return AZ::Success(); + } + AZ::u32 EditorReflectionProbeComponent::OnUseBakedCubemapChanged() { // save setting to the configuration diff --git a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.h b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.h index 5b992ae5aa..eba9575ec4 100644 --- a/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.h +++ b/Gems/AtomLyIntegration/CommonFeatures/Code/Source/ReflectionProbe/EditorReflectionProbeComponent.h @@ -47,6 +47,9 @@ namespace AZ void DisplayEntityViewport(const AzFramework::ViewportInfo& viewportInfo, AzFramework::DebugDisplayRequests& debugDisplay) override; private: + // validation + AZ::Outcome OnUseBakedCubemapValidate(void* newValue, const AZ::Uuid& valueType); + // change notifications AZ::u32 OnUseBakedCubemapChanged(); AZ::u32 OnAuthoredCubemapChanged(); From ddd26c332188872947f39f577e108844edd1aa9b Mon Sep 17 00:00:00 2001 From: antonmic Date: Sun, 25 Apr 2021 23:22:02 -0700 Subject: [PATCH 19/33] addressed review feedback and resolved issues from merge with main --- .../Materials/Types/EnhancedPBR_ForwardPass.azsl | 5 ----- .../Materials/Types/StandardPBR_ForwardPass.azsl | 12 ++---------- .../Assets/Passes/ForwardSubsurfaceMSAA.pass | 5 ----- .../Common/Assets/Passes/OpaqueParent.pass | 7 ------- .../PBR/ForwardSubsurfacePassOutput.azsli | 6 ++---- .../Features/PBR/Lighting/EnhancedLighting.azsli | 8 ++------ .../Atom/Features/PBR/Lighting/SkinLighting.azsli | 8 ++------ .../Features/PBR/Lighting/StandardLighting.azsli | 4 ---- .../Features/PBR/Surfaces/EnhancedSurface.azsli | 3 +-- .../Atom/Features/PBR/Surfaces/SkinSurface.azsli | 3 +-- .../Features/PBR/Surfaces/StandardSurface.azsli | 3 +-- .../015_SubsurfaceScattering.material | 15 +-------------- .../Materials/Types/AutoBrick_ForwardPass.azsl | 2 +- 13 files changed, 13 insertions(+), 68 deletions(-) diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl index 3b2a9b8e42..36c8e81a94 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR_ForwardPass.azsl @@ -274,11 +274,6 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float float2 emissiveUv = IN.m_uv[MaterialSrg::m_emissiveMapUvIndex]; lightingData.emissiveLighting = GetEmissiveInput(MaterialSrg::m_emissiveMap, MaterialSrg::m_sampler, emissiveUv, MaterialSrg::m_emissiveIntensity, MaterialSrg::m_emissiveColor.rgb, o_emissiveEnabled, o_emissive_useTexture); - // ------- Occlusion ------- - - float2 occlusionUv = IN.m_uv[MaterialSrg::m_ambientOcclusionMapUvIndex]; - lightingData.occlusion = GetOcclusionInput(MaterialSrg::m_ambientOcclusionMap, MaterialSrg::m_sampler, occlusionUv, MaterialSrg::m_ambientOcclusionFactor, o_ambientOcclusion_useTexture); - // ------- Clearcoat ------- // [GFX TODO][ATOM-14603]: Clean up the double uses of these clear coat flags diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl index 4989b56892..d3bc72d162 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR_ForwardPass.azsl @@ -191,16 +191,8 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float // ------- Subsurface ------- - float2 subsurfaceUv = IN.m_uv[MaterialSrg::m_subsurfaceScatteringInfluenceMapUvIndex]; - float surfaceScatteringFactor = GetSubsurfaceInput(MaterialSrg::m_subsurfaceScatteringInfluenceMap, MaterialSrg::m_sampler, subsurfaceUv, MaterialSrg::m_subsurfaceScatteringFactor); - - // ------- Transmission ------- - - float2 transmissionUv = IN.m_uv[MaterialSrg::m_transmissionThicknessMapUvIndex]; - float4 transmissionTintThickness = GeTransmissionInput(MaterialSrg::m_transmissionThicknessMap, MaterialSrg::m_sampler, transmissionUv, MaterialSrg::m_transmissionTintThickness); - surface.transmission.tint = transmissionTintThickness.rgb; - surface.transmission.thickness = transmissionTintThickness.w; - surface.transmission.transmissionParams = MaterialSrg::m_transmissionParams; + float surfaceScatteringFactor = 0.0f; + surface.transmission.InitializeToZero(); // ------- Lighting Data ------- diff --git a/Gems/Atom/Feature/Common/Assets/Passes/ForwardSubsurfaceMSAA.pass b/Gems/Atom/Feature/Common/Assets/Passes/ForwardSubsurfaceMSAA.pass index ba09ff7a72..7c3c49a0c9 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/ForwardSubsurfaceMSAA.pass +++ b/Gems/Atom/Feature/Common/Assets/Passes/ForwardSubsurfaceMSAA.pass @@ -93,11 +93,6 @@ "SlotType": "InputOutput", "ScopeAttachmentUsage": "RenderTarget" }, - { - "Name": "ClearCoatNormalOutput", - "SlotType": "InputOutput", - "ScopeAttachmentUsage": "RenderTarget" - }, // Outputs... { "Name": "ScatterDistanceOutput", diff --git a/Gems/Atom/Feature/Common/Assets/Passes/OpaqueParent.pass b/Gems/Atom/Feature/Common/Assets/Passes/OpaqueParent.pass index cc262423e5..dda120e164 100644 --- a/Gems/Atom/Feature/Common/Assets/Passes/OpaqueParent.pass +++ b/Gems/Atom/Feature/Common/Assets/Passes/OpaqueParent.pass @@ -216,13 +216,6 @@ "Pass": "ForwardMSAAPass", "Attachment": "NormalOutput" } - }, - { - "LocalSlot": "ClearCoatNormalOutput", - "AttachmentRef": { - "Pass": "ForwardMSAAPass", - "Attachment": "ClearCoatNormalOutput" - } } ], "PassData": { diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/ForwardSubsurfacePassOutput.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/ForwardSubsurfacePassOutput.azsli index 4185b08571..351e33eaf5 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/ForwardSubsurfacePassOutput.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/ForwardSubsurfacePassOutput.azsli @@ -18,8 +18,7 @@ struct ForwardPassOutput 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; + float3 m_scatterDistance : SV_Target5; }; struct ForwardPassOutputWithDepth @@ -30,7 +29,6 @@ struct ForwardPassOutputWithDepth 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; + float3 m_scatterDistance : SV_Target5; float m_depth : SV_Depth; }; diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli index 47d75a1a9a..010de59ec9 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/EnhancedLighting.azsli @@ -93,7 +93,6 @@ struct PbrLightingOutput float4 m_albedo; float4 m_specularF0; float4 m_normal; - float4 m_clearCoatNormal; float3 m_scatterDistance; }; @@ -107,13 +106,10 @@ PbrLightingOutput GetPbrLightingOutput(Surface surface, LightingData lightingDat // 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; - lightingOutput.m_albedo.a = lightingData.occlusion; + 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; - // layout: (packedNormal.x, packedNormal.y, strength factor, clear coat roughness (not base material's roughness)) - lightingOutput.m_clearCoatNormal = float4(EncodeNormalSphereMap(surface.clearCoat.normal), o_clearCoat_feature_enabled ? surface.clearCoat.factor : 0.0, surface.clearCoat.roughness); - return lightingOutput; } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli index cd04e85516..9f18d43f8b 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/SkinLighting.azsli @@ -84,7 +84,6 @@ struct PbrLightingOutput float4 m_albedo; float4 m_specularF0; float4 m_normal; - float4 m_clearCoatNormal; float3 m_scatterDistance; }; @@ -98,13 +97,10 @@ PbrLightingOutput GetPbrLightingOutput(Surface surface, LightingData lightingDat // 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; - lightingOutput.m_albedo.a = lightingData.occlusion; + 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; - // layout: (packedNormal.x, packedNormal.y, strength factor, clear coat roughness (not base material's roughness)) - lightingOutput.m_clearCoatNormal = float4(EncodeNormalSphereMap(surface.clearCoat.normal), o_clearCoat_feature_enabled ? surface.clearCoat.factor : 0.0, surface.clearCoat.roughness); - return lightingOutput; } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli index ef0c15f073..45aabeede4 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Lighting/StandardLighting.azsli @@ -75,7 +75,6 @@ struct PbrLightingOutput float4 m_albedo; float4 m_specularF0; float4 m_normal; - float4 m_clearCoatNormal; float3 m_scatterDistance; }; @@ -94,9 +93,6 @@ PbrLightingOutput GetPbrLightingOutput(Surface surface, LightingData lightingDat lightingOutput.m_normal.rgb = EncodeNormalSignedOctahedron(surface.normal); lightingOutput.m_normal.a = o_specularF0_enableMultiScatterCompensation ? 1.0f : 0.0f; - // layout: (packedNormal.x, packedNormal.y, strength factor, clear coat roughness (not base material's roughness)) - lightingOutput.m_clearCoatNormal = float4(EncodeNormalSphereMap(surface.clearCoat.normal), o_clearCoat_feature_enabled ? surface.clearCoat.factor : 0.0, surface.clearCoat.roughness); - return lightingOutput; } diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli index 6a8d785a97..baa50436dc 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/EnhancedSurface.azsli @@ -17,9 +17,8 @@ #include #include -class Surface //: BasePbrSurfaceData +class Surface { - //BasePbrSurfaceData pbr; AnisotropicSurfaceData anisotropy; ClearCoatSurfaceData clearCoat; TransmissionSurfaceData transmission; diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli index ffbb12e09d..44a502b1b7 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/SkinSurface.azsli @@ -17,9 +17,8 @@ #include #include -class Surface //: BasePbrSurfaceData +class Surface { - //BasePbrSurfaceData pbr; ClearCoatSurfaceData clearCoat; TransmissionSurfaceData transmission; diff --git a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli index e5a0a0efad..bb63d27df0 100644 --- a/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli +++ b/Gems/Atom/Feature/Common/Assets/ShaderLib/Atom/Features/PBR/Surfaces/StandardSurface.azsli @@ -17,9 +17,8 @@ #include #include -class Surface //: BasePbrSurfaceData +class Surface { - //BasePbrSurfaceData pbr; ClearCoatSurfaceData clearCoat; TransmissionSurfaceData transmission; diff --git a/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/015_SubsurfaceScattering.material b/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/015_SubsurfaceScattering.material index 1e6d08ca4a..37a9b1144e 100644 --- a/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/015_SubsurfaceScattering.material +++ b/Gems/Atom/TestData/TestData/Materials/StandardPbrTestCases/015_SubsurfaceScattering.material @@ -4,15 +4,6 @@ "parentMaterial": "", "propertyLayoutVersion": 3, "properties": { - "emissive": { - "color": [ - 1.0, - 0.0, - 0.0, - 1.0 - ], - "intensity": 4.119999885559082 - }, "subsurfaceScattering": { "enableSubsurfaceScattering": true, "influenceMap": "TestData/Textures/checker8x8_512.png", @@ -23,11 +14,7 @@ 1.0 ], "scatterDistance": 40.0, - "subsurfaceScatterFactor": 1.0, - "thickness": 0.41999998688697817, - "transmissionMode": "ThinObject", - "transmissionScale": 6.599999904632568, - "useThicknessMap": false + "subsurfaceScatterFactor": 1.0 } } } diff --git a/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl b/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl index 3373c90a81..793b71b3af 100644 --- a/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl +++ b/Gems/Atom/TestData/TestData/Materials/Types/AutoBrick_ForwardPass.azsl @@ -193,7 +193,7 @@ ForwardPassOutput AutoBrick_ForwardPassPS(VSOutput IN) // Shadow lightingData.shadowCoords = IN.m_shadowCoords; - lightingData.occlusion = 1.0f - surfaceDepth * AutoBrickSrg::m_aoFactor; + lightingData.diffuseAmbientOcclusion = 1.0f - surfaceDepth * AutoBrickSrg::m_aoFactor; // Diffuse and Specular response lightingData.specularResponse = FresnelSchlickWithRoughness(lightingData.NdotV, surface.specularF0, surface.roughnessLinear); From 9d57095e1c3f9dfc6bc3139d954ff11a7d6e327c Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Mon, 26 Apr 2021 11:49:48 -0500 Subject: [PATCH 20/33] [LYN-3272] Added API for retrieving the number of selected entities. Updated InfoBar to use this new API. --- .../AzToolsFramework/API/ToolsApplicationAPI.h | 5 +++++ .../Application/ToolsApplication.cpp | 1 + .../Application/ToolsApplication.h | 1 + .../Tests/Entity/EditorEntitySelectionTests.cpp | 15 +++++++++++++++ Code/Sandbox/Editor/InfoBar.cpp | 9 +++++---- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/API/ToolsApplicationAPI.h b/Code/Framework/AzToolsFramework/AzToolsFramework/API/ToolsApplicationAPI.h index cca5d1b9e4..83e40474d6 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/API/ToolsApplicationAPI.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/API/ToolsApplicationAPI.h @@ -348,6 +348,11 @@ namespace AzToolsFramework */ virtual bool AreAnyEntitiesSelected() = 0; + /*! + * Returns the number of selected entities. + */ + virtual int GetSelectedEntitiesCount() = 0; + /*! * Retrieves the set of selected entities. * \return a list of entity Ids. diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.cpp b/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.cpp index 22c1390828..50315e9d7a 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.cpp +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.cpp @@ -395,6 +395,7 @@ namespace AzToolsFramework ->Event("MarkEntityDeselected", &ToolsApplicationRequests::MarkEntityDeselected) ->Event("IsSelected", &ToolsApplicationRequests::IsSelected) ->Event("AreAnyEntitiesSelected", &ToolsApplicationRequests::AreAnyEntitiesSelected) + ->Event("GetSelectedEntitiesCount", &ToolsApplicationRequests::GetSelectedEntitiesCount) ; behaviorContext->EBus("ToolsApplicationNotificationBus") diff --git a/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.h b/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.h index 0f038422ce..6c836ac888 100644 --- a/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.h +++ b/Code/Framework/AzToolsFramework/AzToolsFramework/Application/ToolsApplication.h @@ -101,6 +101,7 @@ namespace AzToolsFramework SourceControlFileInfo GetSceneSourceControlInfo() override; bool AreAnyEntitiesSelected() override { return !m_selectedEntities.empty(); } + int GetSelectedEntitiesCount() override { return m_selectedEntities.size(); } const EntityIdList& GetSelectedEntities() override { return m_selectedEntities; } const EntityIdList& GetHighlightedEntities() override { return m_highlightedEntities; } void SetSelectedEntities(const EntityIdList& selectedEntities) override; diff --git a/Code/Framework/AzToolsFramework/Tests/Entity/EditorEntitySelectionTests.cpp b/Code/Framework/AzToolsFramework/Tests/Entity/EditorEntitySelectionTests.cpp index 6625e56470..29f4ca25d8 100644 --- a/Code/Framework/AzToolsFramework/Tests/Entity/EditorEntitySelectionTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Entity/EditorEntitySelectionTests.cpp @@ -81,12 +81,17 @@ namespace UnitTest ToolsApplicationRequestBus::BroadcastResult( anyEntitySelected, &ToolsApplicationRequests::AreAnyEntitiesSelected); + int selectedEntitiesCount = 0; + ToolsApplicationRequestBus::BroadcastResult( + selectedEntitiesCount, &ToolsApplicationRequests::GetSelectedEntitiesCount); + EntityIdList selectedEntityIds; ToolsApplicationRequestBus::BroadcastResult( selectedEntityIds, &ToolsApplicationRequests::GetSelectedEntities); EXPECT_TRUE(testEntitySelected); EXPECT_TRUE(anyEntitySelected); + EXPECT_EQ(selectedEntitiesCount, 1); EXPECT_EQ(selectedEntityIds.size(), 1); EXPECT_EQ(selectedEntityIds.front(), testEntityId); @@ -105,6 +110,7 @@ namespace UnitTest EXPECT_FALSE(testEntitySelected); EXPECT_FALSE(anyEntitySelected); + EXPECT_EQ(selectedEntitiesCount, 0); EXPECT_TRUE(selectedEntityIds.empty()); } @@ -141,11 +147,16 @@ namespace UnitTest ToolsApplicationRequestBus::BroadcastResult( anyEntitySelected, &ToolsApplicationRequests::AreAnyEntitiesSelected); + int selectedEntitiesCount = 0; + ToolsApplicationRequestBus::BroadcastResult( + selectedEntitiesCount, &ToolsApplicationRequests::GetSelectedEntitiesCount); + EntityIdList actualSelectedEntityIds; ToolsApplicationRequestBus::BroadcastResult( actualSelectedEntityIds, &ToolsApplicationRequests::GetSelectedEntities); EXPECT_TRUE(anyEntitySelected); + EXPECT_EQ(selectedEntitiesCount, expectedSelectedEntityIds.size()); EXPECT_EQ(actualSelectedEntityIds.size(), expectedSelectedEntityIds.size()); for (auto& id : expectedSelectedEntityIds) { @@ -160,10 +171,14 @@ namespace UnitTest ToolsApplicationRequestBus::BroadcastResult( anyEntitySelected, &ToolsApplicationRequests::AreAnyEntitiesSelected); + ToolsApplicationRequestBus::BroadcastResult( + selectedEntitiesCount, &ToolsApplicationRequests::GetSelectedEntitiesCount); + ToolsApplicationRequestBus::BroadcastResult( actualSelectedEntityIds, &ToolsApplicationRequests::GetSelectedEntities); EXPECT_TRUE(anyEntitySelected); + EXPECT_EQ(selectedEntitiesCount, expectedSelectedEntityIds.size()); EXPECT_EQ(actualSelectedEntityIds.size(), expectedSelectedEntityIds.size()); for (auto& id : expectedSelectedEntityIds) { diff --git a/Code/Sandbox/Editor/InfoBar.cpp b/Code/Sandbox/Editor/InfoBar.cpp index a1a1f7b055..e6860c38c8 100644 --- a/Code/Sandbox/Editor/InfoBar.cpp +++ b/Code/Sandbox/Editor/InfoBar.cpp @@ -22,7 +22,6 @@ #include "Include/ITransformManipulator.h" #include "ActionManager.h" #include "Settings.h" -#include "Objects/SelectionGroup.h" #include "Include/IObjectManager.h" #include "MathConversion.h" @@ -191,10 +190,12 @@ void CInfoBar::IdleUpdate() Vec3 marker = GetIEditor()->GetMarkerPosition(); - CSelectionGroup* selection = GetIEditor()->GetSelection(); - if (selection->GetCount() != m_numSelected) + int selectedEntitiesCount = 0; + AzToolsFramework::ToolsApplicationRequestBus::BroadcastResult( + selectedEntitiesCount, &AzToolsFramework::ToolsApplicationRequests::GetSelectedEntitiesCount); + if (selectedEntitiesCount != m_numSelected) { - m_numSelected = selection->GetCount(); + m_numSelected = selectedEntitiesCount; updateUI = true; } From a1685ecca9fdd790a65d62166ccccbb41e99d86f Mon Sep 17 00:00:00 2001 From: jackalbe <23512001+jackalbe@users.noreply.github.com> Date: Mon, 26 Apr 2021 12:08:43 -0500 Subject: [PATCH 21/33] {LYN-2074} Add Animation data types Behavior for the scene graph (#253) {LYN-2074} Add Animation data types Behavior for the scene graph (#253) * https://jira.agscollab.com/browse/LYN-2074 * moved scene API color to centeralized location BlendShapeDataFace BlendShapeData --- .../GraphData/IMeshVertexColorData.h | 3 + .../SceneData/GraphData/AnimationData.cpp | 53 ++++++ .../SceneData/GraphData/AnimationData.h | 4 + .../SceneData/GraphData/BlendShapeData.cpp | 80 +++++++++ .../SceneData/GraphData/BlendShapeData.h | 2 + .../GraphData/MeshVertexColorData.cpp | 4 +- .../SceneData/ReflectionRegistrar.cpp | 8 +- .../GraphData/GraphDataBehaviorTests.cpp | 159 ++++++++++++++++++ 8 files changed, 308 insertions(+), 5 deletions(-) diff --git a/Code/Tools/SceneAPI/SceneCore/DataTypes/GraphData/IMeshVertexColorData.h b/Code/Tools/SceneAPI/SceneCore/DataTypes/GraphData/IMeshVertexColorData.h index f4b7a3165e..e2f53c33f9 100644 --- a/Code/Tools/SceneAPI/SceneCore/DataTypes/GraphData/IMeshVertexColorData.h +++ b/Code/Tools/SceneAPI/SceneCore/DataTypes/GraphData/IMeshVertexColorData.h @@ -97,6 +97,9 @@ namespace AZ }; } // DataTypes } // SceneAPI + + AZ_TYPE_INFO_SPECIALIZE(SceneAPI::DataTypes::Color, "{937E3BF8-5204-4D40-A8DA-C8F083C89F9F}"); + } // AZ namespace AZStd diff --git a/Code/Tools/SceneAPI/SceneData/GraphData/AnimationData.cpp b/Code/Tools/SceneAPI/SceneData/GraphData/AnimationData.cpp index 083adeff50..b54aa1e421 100644 --- a/Code/Tools/SceneAPI/SceneData/GraphData/AnimationData.cpp +++ b/Code/Tools/SceneAPI/SceneData/GraphData/AnimationData.cpp @@ -11,6 +11,8 @@ */ #include +#include +#include namespace AZ { @@ -18,6 +20,31 @@ namespace AZ { namespace GraphData { + void AnimationData::Reflect(ReflectContext* context) + { + SerializeContext* serializeContext = azrtti_cast(context); + if (serializeContext) + { + serializeContext->Class() + ->Version(1); + } + + BehaviorContext* behaviorContext = azrtti_cast(context); + if (behaviorContext) + { + behaviorContext->Class() + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Module, "scene") + ->Method("GetKeyFrameCount", &SceneAPI::DataTypes::IAnimationData::GetKeyFrameCount) + ->Method("GetKeyFrame", &SceneAPI::DataTypes::IAnimationData::GetKeyFrame) + ->Method("GetTimeStepBetweenFrames", &SceneAPI::DataTypes::IAnimationData::GetTimeStepBetweenFrames); + + behaviorContext->Class() + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Module, "scene"); + } + } + AnimationData::AnimationData() : m_timeStepBetweenFrames(1.0/30.0) // default value { @@ -61,6 +88,32 @@ namespace AZ } + void BlendShapeAnimationData::Reflect(ReflectContext* context) + { + SerializeContext* serializeContext = azrtti_cast(context); + if (serializeContext) + { + serializeContext->Class() + ->Version(1); + } + + BehaviorContext* behaviorContext = azrtti_cast(context); + if (behaviorContext) + { + behaviorContext->Class() + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Module, "scene") + ->Method("GetBlendShapeName", &SceneAPI::DataTypes::IBlendShapeAnimationData::GetBlendShapeName) + ->Method("GetKeyFrameCount", &SceneAPI::DataTypes::IBlendShapeAnimationData::GetKeyFrameCount) + ->Method("GetKeyFrame", &SceneAPI::DataTypes::IBlendShapeAnimationData::GetKeyFrame) + ->Method("GetTimeStepBetweenFrames", &SceneAPI::DataTypes::IBlendShapeAnimationData::GetTimeStepBetweenFrames); + + behaviorContext->Class() + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Module, "scene"); + } + } + BlendShapeAnimationData::BlendShapeAnimationData() : m_timeStepBetweenFrames(1 / 30.0) // default value { diff --git a/Code/Tools/SceneAPI/SceneData/GraphData/AnimationData.h b/Code/Tools/SceneAPI/SceneData/GraphData/AnimationData.h index 6f3f9a05f5..af44618878 100644 --- a/Code/Tools/SceneAPI/SceneData/GraphData/AnimationData.h +++ b/Code/Tools/SceneAPI/SceneData/GraphData/AnimationData.h @@ -30,6 +30,8 @@ namespace AZ public: AZ_RTTI(AnimationData, "{D350732E-4727-41C8-95E0-FBAF5F2AC074}", SceneAPI::DataTypes::IAnimationData); + static void Reflect(ReflectContext* context); + SCENE_DATA_API AnimationData(); SCENE_DATA_API ~AnimationData() override = default; SCENE_DATA_API virtual void AddKeyFrame(const SceneAPI::DataTypes::MatrixType& keyFrameTransform); @@ -53,6 +55,8 @@ namespace AZ public: AZ_RTTI(BlendShapeAnimationData, "{02766CCF-BDA7-46B6-9BB1-58A90C1AD6AA}", SceneAPI::DataTypes::IBlendShapeAnimationData); + static void Reflect(ReflectContext* context); + SCENE_DATA_API BlendShapeAnimationData(); SCENE_DATA_API ~BlendShapeAnimationData() override = default; SCENE_DATA_API void CloneAttributesFrom(const IGraphObject* sourceObject) override; diff --git a/Code/Tools/SceneAPI/SceneData/GraphData/BlendShapeData.cpp b/Code/Tools/SceneAPI/SceneData/GraphData/BlendShapeData.cpp index a26f07ae53..902928d404 100644 --- a/Code/Tools/SceneAPI/SceneData/GraphData/BlendShapeData.cpp +++ b/Code/Tools/SceneAPI/SceneData/GraphData/BlendShapeData.cpp @@ -12,9 +12,13 @@ #include #include +#include +#include namespace AZ { + AZ_TYPE_INFO_SPECIALIZE(SceneAPI::DataTypes::IBlendShapeData::Face, "{C972EC9A-3A5C-47CD-9A92-ECB4C0C0451C}"); + namespace SceneData { namespace GraphData @@ -23,6 +27,82 @@ namespace AZ BlendShapeData::~BlendShapeData() = default; + void BlendShapeData::Reflect(ReflectContext* context) + { + SerializeContext* serializeContext = azrtti_cast(context); + if (serializeContext) + { + serializeContext->Class() + ->Version(1); + } + + BehaviorContext* behaviorContext = azrtti_cast(context); + if (behaviorContext) + { + behaviorContext->Class() + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Module, "scene") + ->Method("GetUsedControlPointCount", &SceneAPI::DataTypes::IBlendShapeData::GetUsedControlPointCount) + ->Method("GetControlPointIndex", &SceneAPI::DataTypes::IBlendShapeData::GetControlPointIndex) + ->Method("GetUsedPointIndexForControlPoint", &SceneAPI::DataTypes::IBlendShapeData::GetUsedPointIndexForControlPoint) + ->Method("GetVertexCount", &SceneAPI::DataTypes::IBlendShapeData::GetVertexCount) + ->Method("GetFaceCount", &SceneAPI::DataTypes::IBlendShapeData::GetFaceCount) + ->Method("GetFaceInfo", &SceneAPI::DataTypes::IBlendShapeData::GetFaceInfo) + ->Method("GetPosition", &SceneAPI::DataTypes::IBlendShapeData::GetPosition) + ->Method("GetNormal", &SceneAPI::DataTypes::IBlendShapeData::GetNormal) + ->Method("GetFaceVertexIndex", &SceneAPI::DataTypes::IBlendShapeData::GetFaceVertexIndex); + + behaviorContext->Class("BlendShapeDataFace") + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Module, "scene") + ->Method("GetVertexIndex", [](const SceneAPI::DataTypes::IBlendShapeData::Face& self, int index) + { + if (index >= 0 && index < 3) + { + return self.vertexIndex[index]; + } + return aznumeric_cast(0); + }); + + behaviorContext->Class() + ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) + ->Attribute(AZ::Script::Attributes::Module, "scene") + ->Method("GetUV", &BlendShapeData::GetUV) + ->Method("GetTangent", [](const BlendShapeData& self, size_t index) + { + if (index < self.GetTangents().size()) + { + return self.GetTangents().at(index); + } + AZ_Error("SceneGraphData", false, "Cannot get to tangent at index(%zu)", index); + return Vector4::CreateZero(); + }) + ->Method("GetBitangent", [](const BlendShapeData& self, size_t index) + { + if (index < self.GetBitangents().size()) + { + return self.GetBitangents().at(index); + } + AZ_Error("SceneGraphData", false, "Cannot get to bitangents at index(%zu)", index); + return Vector3::CreateZero(); + }) + ->Method("GetColor", [](const BlendShapeData& self, AZ::u8 colorSetIndex, AZ::u8 colorIndex) + { + SceneAPI::DataTypes::Color color(0,0,0,0); + if (colorSetIndex < MaxNumColorSets) + { + const AZStd::vector& colorChannel = self.GetColors(colorSetIndex); + if (colorIndex < colorChannel.size()) + { + return colorChannel[colorIndex]; + } + } + AZ_Error("SceneGraphData", false, "Cannot get to color setIndex(%d) at colorIndex(%d)", colorSetIndex, colorIndex); + return color; + }); + } + } + void BlendShapeData::AddPosition(const Vector3& position) { m_positions.push_back(position); diff --git a/Code/Tools/SceneAPI/SceneData/GraphData/BlendShapeData.h b/Code/Tools/SceneAPI/SceneData/GraphData/BlendShapeData.h index 0626b6b6cf..9ae287da46 100644 --- a/Code/Tools/SceneAPI/SceneData/GraphData/BlendShapeData.h +++ b/Code/Tools/SceneAPI/SceneData/GraphData/BlendShapeData.h @@ -31,6 +31,8 @@ namespace AZ public: AZ_RTTI(BlendShapeData, "{FF875C22-2E4F-4CE3-BA49-09BF78C70A09}", SceneAPI::DataTypes::IBlendShapeData) + SCENE_DATA_API static void Reflect(ReflectContext* context); + // Maximum number of color sets matches limitation set in assImp (AI_MAX_NUMBER_OF_COLOR_SETS) static constexpr AZ::u8 MaxNumColorSets = 8; // Maximum number of uv sets matches limitation set in assImp (AI_MAX_NUMBER_OF_TEXTURECOORDS) diff --git a/Code/Tools/SceneAPI/SceneData/GraphData/MeshVertexColorData.cpp b/Code/Tools/SceneAPI/SceneData/GraphData/MeshVertexColorData.cpp index fe3cede475..a5ed4132ea 100644 --- a/Code/Tools/SceneAPI/SceneData/GraphData/MeshVertexColorData.cpp +++ b/Code/Tools/SceneAPI/SceneData/GraphData/MeshVertexColorData.cpp @@ -16,8 +16,6 @@ namespace AZ { - AZ_TYPE_INFO_SPECIALIZE(SceneAPI::DataTypes::Color, "{937E3BF8-5204-4D40-A8DA-C8F083C89F9F}"); - namespace SceneData { namespace GraphData @@ -40,7 +38,7 @@ namespace AZ ->Method("GetCount", &MeshVertexColorData::GetCount ) ->Method("GetColor", &MeshVertexColorData::GetColor); - behaviorContext->Class("MeshVertexColor") + behaviorContext->Class("VertexColor") ->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common) ->Attribute(AZ::Script::Attributes::Module, "scene") ->Property("red", BehaviorValueGetter(&AZ::SceneAPI::DataTypes::Color::red), nullptr) diff --git a/Code/Tools/SceneAPI/SceneData/ReflectionRegistrar.cpp b/Code/Tools/SceneAPI/SceneData/ReflectionRegistrar.cpp index 6a04e071d7..a9e0c7b1a5 100644 --- a/Code/Tools/SceneAPI/SceneData/ReflectionRegistrar.cpp +++ b/Code/Tools/SceneAPI/SceneData/ReflectionRegistrar.cpp @@ -81,8 +81,9 @@ namespace AZ SceneData::SceneNodeSelectionList::Reflect(context); // Graph objects - context->Class()->Version(1); - context->Class()->Version(1); + AZ::SceneData::GraphData::AnimationData::Reflect(context); + AZ::SceneData::GraphData::BlendShapeAnimationData::Reflect(context); + AZ::SceneData::GraphData::BlendShapeData::Reflect(context); AZ::SceneData::GraphData::BoneData::Reflect(context); AZ::SceneData::GraphData::MaterialData::Reflect(context); AZ::SceneData::GraphData::MeshData::Reflect(context); @@ -107,6 +108,9 @@ namespace AZ AZ::SceneData::GraphData::MeshVertexUVData::Reflect(context); AZ::SceneData::GraphData::MeshVertexTangentData::Reflect(context); AZ::SceneData::GraphData::MeshVertexBitangentData::Reflect(context); + AZ::SceneData::GraphData::AnimationData::Reflect(context); + AZ::SceneData::GraphData::BlendShapeAnimationData::Reflect(context); + AZ::SceneData::GraphData::BlendShapeData::Reflect(context); } } // namespace SceneAPI } // namespace AZ diff --git a/Code/Tools/SceneAPI/SceneData/Tests/GraphData/GraphDataBehaviorTests.cpp b/Code/Tools/SceneAPI/SceneData/Tests/GraphData/GraphDataBehaviorTests.cpp index 404950b4c0..79c6cfea7e 100644 --- a/Code/Tools/SceneAPI/SceneData/Tests/GraphData/GraphDataBehaviorTests.cpp +++ b/Code/Tools/SceneAPI/SceneData/Tests/GraphData/GraphDataBehaviorTests.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include namespace AZ { @@ -101,6 +103,53 @@ namespace AZ tangentData->SetTangentSetIndex(2); return true; } + else if (data.get_type_info().m_id == azrtti_typeid()) + { + auto* animationData = AZStd::any_cast(&data); + animationData->ReserveKeyFrames(3); + animationData->AddKeyFrame(DataTypes::MatrixType::CreateFromValue(1.0)); + animationData->AddKeyFrame(DataTypes::MatrixType::CreateFromValue(2.0)); + animationData->AddKeyFrame(DataTypes::MatrixType::CreateFromValue(3.0)); + animationData->SetTimeStepBetweenFrames(4.0); + return true; + } + else if (data.get_type_info().m_id == azrtti_typeid()) + { + auto* blendShapeAnimationData = AZStd::any_cast(&data); + blendShapeAnimationData->SetBlendShapeName("mockBlendShapeName"); + blendShapeAnimationData->ReserveKeyFrames(3); + blendShapeAnimationData->AddKeyFrame(1.0); + blendShapeAnimationData->AddKeyFrame(2.0); + blendShapeAnimationData->AddKeyFrame(3.0); + blendShapeAnimationData->SetTimeStepBetweenFrames(4.0); + return true; + } + else if (data.get_type_info().m_id == azrtti_typeid()) + { + auto* blendShapeData = AZStd::any_cast(&data); + blendShapeData->AddPosition({ 1.0, 2.0, 3.0 }); + blendShapeData->AddPosition({ 2.0, 3.0, 4.0 }); + blendShapeData->AddPosition({ 3.0, 4.0, 5.0 }); + blendShapeData->AddNormal({ 0.1, 0.2, 0.3 }); + blendShapeData->AddNormal({ 0.2, 0.3, 0.4 }); + blendShapeData->AddNormal({ 0.3, 0.4, 0.5 }); + blendShapeData->AddTangentAndBitangent(Vector4{ 0.1f, 0.2f, 0.3f, 0.4f }, { 0.0, 0.1, 0.2 }); + blendShapeData->AddTangentAndBitangent(Vector4{ 0.2f, 0.3f, 0.4f, 0.5f }, { 0.1, 0.2, 0.3 }); + blendShapeData->AddTangentAndBitangent(Vector4{ 0.3f, 0.4f, 0.5f, 0.6f }, { 0.2, 0.3, 0.4 }); + blendShapeData->AddUV(Vector2{ 0.9, 0.8 }, 0); + blendShapeData->AddUV(Vector2{ 0.7, 0.7 }, 1); + blendShapeData->AddUV(Vector2{ 0.6, 0.6 }, 2); + blendShapeData->AddColor(DataTypes::Color{ 0.1, 0.2, 0.3, 0.4 }, 0); + blendShapeData->AddColor(DataTypes::Color{ 0.2, 0.3, 0.4, 0.5 }, 1); + blendShapeData->AddColor(DataTypes::Color{ 0.3, 0.4, 0.5, 0.6 }, 2); + blendShapeData->AddFace({ 0, 1, 2 }); + blendShapeData->AddFace({ 1, 2, 0 }); + blendShapeData->AddFace({ 2, 0, 1 }); + blendShapeData->SetVertexIndexToControlPointIndexMap(0, 1); + blendShapeData->SetVertexIndexToControlPointIndexMap(1, 2); + blendShapeData->SetVertexIndexToControlPointIndexMap(2, 0); + return true; + } return false; } @@ -296,6 +345,116 @@ namespace AZ ExpectExecute("TestExpectIntegerEquals(meshVertexTangentData:GetTangentSetIndex(), 2)"); ExpectExecute("TestExpectTrue(meshVertexTangentData:GetTangentSpace(), MeshVertexTangentData.EMotionFX)"); } + + TEST_F(GrapDatahBehaviorScriptTest, SceneGraph_AnimationData_AccessWorks) + { + ExpectExecute("animationData = AnimationData()"); + ExpectExecute("TestExpectTrue(animationData ~= nil)"); + ExpectExecute("MockGraphData.FillData(animationData)"); + ExpectExecute("TestExpectIntegerEquals(animationData:GetKeyFrameCount(), 3)"); + ExpectExecute("TestExpectFloatEquals(animationData:GetTimeStepBetweenFrames(), 4.0)"); + ExpectExecute("TestExpectFloatEquals(animationData:GetKeyFrame(0).basisX.x, 1.0)"); + ExpectExecute("TestExpectFloatEquals(animationData:GetKeyFrame(1).basisX.y, 2.0)"); + ExpectExecute("TestExpectFloatEquals(animationData:GetKeyFrame(2).basisX.z, 3.0)"); + } + + TEST_F(GrapDatahBehaviorScriptTest, SceneGraph_BlendShapeAnimationData_AccessWorks) + { + ExpectExecute("blendShapeAnimationData = BlendShapeAnimationData()"); + ExpectExecute("TestExpectTrue(blendShapeAnimationData ~= nil)"); + ExpectExecute("MockGraphData.FillData(blendShapeAnimationData)"); + ExpectExecute("TestExpectTrue(blendShapeAnimationData:GetBlendShapeName() == 'mockBlendShapeName')"); + ExpectExecute("TestExpectIntegerEquals(blendShapeAnimationData:GetKeyFrameCount(), 3)"); + ExpectExecute("TestExpectFloatEquals(blendShapeAnimationData:GetKeyFrame(0), 1.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeAnimationData:GetKeyFrame(1), 2.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeAnimationData:GetKeyFrame(2), 3.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeAnimationData:GetTimeStepBetweenFrames(), 4.0)"); + } + + TEST_F(GrapDatahBehaviorScriptTest, SceneGraph_BlendShapeData_AccessWorks) + { + ExpectExecute("blendShapeData = BlendShapeData()"); + ExpectExecute("TestExpectTrue(blendShapeData ~= nil)"); + ExpectExecute("MockGraphData.FillData(blendShapeData)"); + ExpectExecute("TestExpectIntegerEquals(blendShapeData:GetUsedControlPointCount(), 3)"); + ExpectExecute("TestExpectIntegerEquals(blendShapeData:GetVertexCount(), 3)"); + ExpectExecute("TestExpectIntegerEquals(blendShapeData:GetFaceCount(), 3)"); + ExpectExecute("TestExpectIntegerEquals(blendShapeData:GetFaceVertexIndex(0, 2), 2)"); + ExpectExecute("TestExpectIntegerEquals(blendShapeData:GetFaceVertexIndex(1, 0), 1)"); + ExpectExecute("TestExpectIntegerEquals(blendShapeData:GetFaceVertexIndex(2, 1), 0)"); + ExpectExecute("TestExpectIntegerEquals(blendShapeData:GetControlPointIndex(0), 1)"); + ExpectExecute("TestExpectIntegerEquals(blendShapeData:GetControlPointIndex(1), 2)"); + ExpectExecute("TestExpectIntegerEquals(blendShapeData:GetControlPointIndex(2), 0)"); + ExpectExecute("TestExpectIntegerEquals(blendShapeData:GetUsedPointIndexForControlPoint(0), 2)"); + ExpectExecute("TestExpectIntegerEquals(blendShapeData:GetUsedPointIndexForControlPoint(1), 0)"); + ExpectExecute("TestExpectIntegerEquals(blendShapeData:GetUsedPointIndexForControlPoint(2), 1)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetPosition(0).x, 1.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetPosition(0).y, 2.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetPosition(0).z, 3.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetPosition(1).x, 2.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetPosition(1).y, 3.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetPosition(1).z, 4.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetPosition(2).x, 3.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetPosition(2).y, 4.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetPosition(2).z, 5.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetNormal(0).x, 0.1)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetNormal(0).y, 0.2)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetNormal(0).z, 0.3)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetNormal(1).x, 0.2)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetNormal(1).y, 0.3)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetNormal(1).z, 0.4)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetNormal(2).x, 0.3)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetNormal(2).y, 0.4)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetNormal(2).z, 0.5)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetFaceInfo(0):GetVertexIndex(0), 0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetFaceInfo(0):GetVertexIndex(1), 1)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetFaceInfo(0):GetVertexIndex(2), 2)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetFaceInfo(1):GetVertexIndex(0), 1)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetFaceInfo(1):GetVertexIndex(1), 2)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetFaceInfo(1):GetVertexIndex(2), 0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetFaceInfo(2):GetVertexIndex(0), 2)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetFaceInfo(2):GetVertexIndex(1), 0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetFaceInfo(2):GetVertexIndex(2), 1)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetUV(0, 0).x, 0.9)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetUV(0, 0).y, 0.8)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetUV(0, 1).x, 0.7)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetUV(0, 1).y, 0.7)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetUV(0, 2).x, 0.6)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetUV(0, 2).y, 0.6)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetColor(0, 0).red, 0.1)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetColor(0, 0).green, 0.2)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetColor(0, 0).blue, 0.3)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetColor(0, 0).alpha, 0.4)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetColor(1, 0).red, 0.2)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetColor(1, 0).green, 0.3)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetColor(1, 0).blue, 0.4)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetColor(1, 0).alpha, 0.5)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetColor(2, 0).red, 0.3)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetColor(2, 0).green, 0.4)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetColor(2, 0).blue, 0.5)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetColor(2, 0).alpha, 0.6)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetTangent(0).x, 0.1)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetTangent(0).y, 0.2)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetTangent(0).z, 0.3)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetTangent(0).w, 0.4)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetTangent(1).x, 0.2)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetTangent(1).y, 0.3)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetTangent(1).z, 0.4)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetTangent(1).w, 0.5)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetTangent(2).x, 0.3)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetTangent(2).y, 0.4)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetTangent(2).z, 0.5)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetTangent(2).w, 0.6)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetBitangent(0).x, 0.0)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetBitangent(0).y, 0.1)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetBitangent(0).z, 0.2)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetBitangent(1).x, 0.1)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetBitangent(1).y, 0.2)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetBitangent(1).z, 0.3)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetBitangent(2).x, 0.2)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetBitangent(2).y, 0.3)"); + ExpectExecute("TestExpectFloatEquals(blendShapeData:GetBitangent(2).z, 0.4)"); + } } } } From 818c2526c9460f3c59549b2f6c54d0606b57fe13 Mon Sep 17 00:00:00 2001 From: Benjamin Jillich <43751992+amzn-jillich@users.noreply.github.com> Date: Mon, 26 Apr 2021 19:53:39 +0200 Subject: [PATCH 22/33] [LYN-3306] EMotionFX: Client sample asset does not animate with simple motion component (#313) * Removed discrepancy between editor and game simple motion components which led to an animation being played in the game one while the editor component looked broken for animations with root joints animated only. * Sharing a new in-place attribute between the game and editor components that lets users control whether positional and rotational changes shall be applied onto root joints or not. --- .../Components/SimpleMotionComponent.cpp | 13 +++++++++---- .../Integration/Components/SimpleMotionComponent.h | 7 ++++--- .../Components/EditorSimpleMotionComponent.cpp | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Gems/EMotionFX/Code/Source/Integration/Components/SimpleMotionComponent.cpp b/Gems/EMotionFX/Code/Source/Integration/Components/SimpleMotionComponent.cpp index d60ecf622e..2e0ca16af2 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Components/SimpleMotionComponent.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Components/SimpleMotionComponent.cpp @@ -43,6 +43,7 @@ namespace EMotionFX ->Field("BlendIn", &Configuration::m_blendInTime) ->Field("BlendOut", &Configuration::m_blendOutTime) ->Field("PlayOnActivation", &Configuration::m_playOnActivation) + ->Field("InPlace", &Configuration::m_inPlace) ; AZ::EditContext* editContext = serializeContext->GetEditContext(); @@ -61,7 +62,9 @@ namespace EMotionFX ->Attribute(AZ::Edit::Attributes::Min, 0.0f) ->DataElement(AZ::Edit::UIHandlers::Default, &Configuration::m_blendOutTime, "Blend Out Time", "Determines the blend out time in seconds") ->Attribute(AZ::Edit::Attributes::Min, 0.0f) - ->DataElement(AZ::Edit::UIHandlers::Default, &Configuration::m_playOnActivation, "Play on active", "Playing animation immediately after activition.") + ->DataElement(AZ::Edit::UIHandlers::Default, &Configuration::m_playOnActivation, "Play on active", "Playing animation immediately after activation.") + ->DataElement(AZ::Edit::UIHandlers::Default, &Configuration::m_inPlace, "In-place", + "Plays the animation in-place and removes any positional and rotational changes from root joints.") ; } } @@ -128,6 +131,7 @@ namespace EMotionFX , m_blendInTime(0.0f) , m_blendOutTime(0.0f) , m_playOnActivation(true) + , m_inPlace(false) { } @@ -235,7 +239,7 @@ namespace EMotionFX void SimpleMotionComponent::PlayMotion() { - m_motionInstance = PlayMotionInternal(m_actorInstance.get(), m_configuration, /*deleteOnZeroWeight*/true, /*inPlace*/false); + m_motionInstance = PlayMotionInternal(m_actorInstance.get(), m_configuration, /*deleteOnZeroWeight*/true); } void SimpleMotionComponent::RemoveMotionInstanceFromActor(EMotionFX::MotionInstance* motionInstance) @@ -425,7 +429,7 @@ namespace EMotionFX return m_configuration.m_blendOutTime; } - EMotionFX::MotionInstance* SimpleMotionComponent::PlayMotionInternal(const EMotionFX::ActorInstance* actorInstance, const SimpleMotionComponent::Configuration& cfg, bool deleteOnZeroWeight, bool inPlace) + EMotionFX::MotionInstance* SimpleMotionComponent::PlayMotionInternal(const EMotionFX::ActorInstance* actorInstance, const SimpleMotionComponent::Configuration& cfg, bool deleteOnZeroWeight) { if (!actorInstance || !cfg.m_motionAsset.IsReady()) { @@ -439,6 +443,7 @@ namespace EMotionFX auto* motionAsset = cfg.m_motionAsset.GetAs(); if (!motionAsset) + { AZ_Error("EMotionFX", motionAsset, "Motion asset is not valid."); return nullptr; @@ -456,7 +461,7 @@ namespace EMotionFX info.mCanOverwrite = false; info.mBlendInTime = cfg.m_blendInTime; info.mBlendOutTime = cfg.m_blendOutTime; - info.mInPlace = inPlace; + info.mInPlace = cfg.m_inPlace; return actorInstance->GetMotionSystem()->PlayMotion(motionAsset->m_emfxMotion.get(), &info); } diff --git a/Gems/EMotionFX/Code/Source/Integration/Components/SimpleMotionComponent.h b/Gems/EMotionFX/Code/Source/Integration/Components/SimpleMotionComponent.h index 4e3173a3b8..5f5066b9bb 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Components/SimpleMotionComponent.h +++ b/Gems/EMotionFX/Code/Source/Integration/Components/SimpleMotionComponent.h @@ -46,7 +46,7 @@ namespace EMotionFX struct Configuration { AZ_TYPE_INFO(Configuration, "{DA661C5F-E79E-41C3-B055-5F5A4E353F84}") - Configuration(); + Configuration(); AZ::Data::Asset m_motionAsset; ///< Assigned motion asset bool m_loop; ///< Toggles looping of the motion @@ -56,7 +56,8 @@ namespace EMotionFX float m_playspeed; ///< Determines the rate at which the motion is played float m_blendInTime; ///< Determines the blend in time in seconds. float m_blendOutTime; ///< Determines the blend out time in seconds. - bool m_playOnActivation; ///< Determines if the motion should be played immediately + bool m_playOnActivation; ///< Determines if the motion should be played immediately + bool m_inPlace; ///< Determines if the motion should be played in-place. static void Reflect(AZ::ReflectContext* context); }; @@ -121,7 +122,7 @@ namespace EMotionFX void RemoveMotionInstanceFromActor(EMotionFX::MotionInstance* motionInstance); - static EMotionFX::MotionInstance* PlayMotionInternal(const EMotionFX::ActorInstance* actorInstance, const SimpleMotionComponent::Configuration& cfg, bool deleteOnZeroWeight, bool inPlace); + static EMotionFX::MotionInstance* PlayMotionInternal(const EMotionFX::ActorInstance* actorInstance, const SimpleMotionComponent::Configuration& cfg, bool deleteOnZeroWeight); Configuration m_configuration; ///< Component configuration. EMotionFXPtr m_actorInstance; ///< Associated actor instance (retrieved from Actor Component). diff --git a/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorSimpleMotionComponent.cpp b/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorSimpleMotionComponent.cpp index 228a82856d..1d09b3e255 100644 --- a/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorSimpleMotionComponent.cpp +++ b/Gems/EMotionFX/Code/Source/Integration/Editor/Components/EditorSimpleMotionComponent.cpp @@ -170,7 +170,7 @@ namespace EMotionFX // The Editor allows scrubbing back and forth on animation blending transitions, so don't delete // motion instances if it's blend weight is zero. // The Editor preview should preview the motion in place to prevent off center movement. - m_motionInstance = SimpleMotionComponent::PlayMotionInternal(m_actorInstance, m_configuration, /*deleteOnZeroWeight*/false, /*inPlace*/true); + m_motionInstance = SimpleMotionComponent::PlayMotionInternal(m_actorInstance, m_configuration, /*deleteOnZeroWeight*/false); } } From 5d2db78f7469f41290a7b0af3a5dcacb949b562e Mon Sep 17 00:00:00 2001 From: Chris Galvan Date: Mon, 26 Apr 2021 13:25:55 -0500 Subject: [PATCH 23/33] [LYN-3272] Added missing call in unit test. --- .../Tests/Entity/EditorEntitySelectionTests.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Code/Framework/AzToolsFramework/Tests/Entity/EditorEntitySelectionTests.cpp b/Code/Framework/AzToolsFramework/Tests/Entity/EditorEntitySelectionTests.cpp index 29f4ca25d8..66ccf09aaf 100644 --- a/Code/Framework/AzToolsFramework/Tests/Entity/EditorEntitySelectionTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Entity/EditorEntitySelectionTests.cpp @@ -105,6 +105,9 @@ namespace UnitTest ToolsApplicationRequestBus::BroadcastResult( anyEntitySelected, &ToolsApplicationRequests::AreAnyEntitiesSelected); + ToolsApplicationRequestBus::BroadcastResult( + selectedEntitiesCount, &ToolsApplicationRequests::GetSelectedEntitiesCount); + ToolsApplicationRequestBus::BroadcastResult( selectedEntityIds, &ToolsApplicationRequests::GetSelectedEntities); From e5b50677480b5b9080ed40cb06adc0ca8899852a Mon Sep 17 00:00:00 2001 From: bosnichd Date: Mon, 26 Apr 2021 13:15:32 -0600 Subject: [PATCH 24/33] Change LOAD_LEGACY_RENDERER_FOR_EDITOR from true -> false (#315) Change LOAD_LEGACY_RENDERER_FOR_EDITOR from true -> false, and added some null checks to protect against gEnv->pRenderer and gEnv->p3DEngine now being null in the editor as well as the launcher. --- Code/CryEngine/CrySystem/SystemInit.cpp | 2 +- Code/Sandbox/Editor/EditorViewportWidget.cpp | 16 ++++++++----- .../Editor/Material/MaterialManager.cpp | 16 +++++++++---- .../Source/Rendering/EditorLightComponent.cpp | 15 +++++++++++- .../Code/Source/Rendering/LightInstance.cpp | 24 ++++++++++++------- 5 files changed, 52 insertions(+), 21 deletions(-) diff --git a/Code/CryEngine/CrySystem/SystemInit.cpp b/Code/CryEngine/CrySystem/SystemInit.cpp index cd8ce36beb..fcbf0b8215 100644 --- a/Code/CryEngine/CrySystem/SystemInit.cpp +++ b/Code/CryEngine/CrySystem/SystemInit.cpp @@ -247,7 +247,7 @@ CUNIXConsole* pUnixConsole; #define LOCALIZATION_TRANSLATIONS_LIST_FILE_NAME "Libs/Localization/localization.xml" -#define LOAD_LEGACY_RENDERER_FOR_EDITOR true // If you set this to false you must for now also set 'ed_useAtomNativeViewport' to true (see /Code/Sandbox/Editor/ViewManager.cpp) +#define LOAD_LEGACY_RENDERER_FOR_EDITOR false // If you set this to true you must also set 'ed_useAtomNativeViewport' to false (see /Code/Sandbox/Editor/ViewManager.cpp) #define LOAD_LEGACY_RENDERER_FOR_LAUNCHER false ////////////////////////////////////////////////////////////////////////// diff --git a/Code/Sandbox/Editor/EditorViewportWidget.cpp b/Code/Sandbox/Editor/EditorViewportWidget.cpp index a656c27d98..25588e85a7 100644 --- a/Code/Sandbox/Editor/EditorViewportWidget.cpp +++ b/Code/Sandbox/Editor/EditorViewportWidget.cpp @@ -232,7 +232,6 @@ int EditorViewportWidget::OnCreate() { m_renderer = GetIEditor()->GetRenderer(); m_engine = GetIEditor()->Get3DEngine(); - assert(m_engine); CreateRenderContext(); @@ -793,8 +792,14 @@ void EditorViewportWidget::OnRender() // This is necessary so that automated editor tests using the null renderer to test systems like dynamic vegetation // are still able to manipulate the current logical camera position, even if nothing is rendered. GetIEditor()->GetSystem()->SetViewCamera(m_Camera); - GetIEditor()->GetRenderer()->SetCamera(gEnv->pSystem->GetViewCamera()); - m_engine->RenderWorld(0, SRenderingPassInfo::CreateGeneralPassRenderingInfo(m_Camera), __FUNCTION__); + if (GetIEditor()->GetRenderer()) + { + GetIEditor()->GetRenderer()->SetCamera(gEnv->pSystem->GetViewCamera()); + } + if (m_engine) + { + m_engine->RenderWorld(0, SRenderingPassInfo::CreateGeneralPassRenderingInfo(m_Camera), __FUNCTION__); + } return; } @@ -886,7 +891,7 @@ void EditorViewportWidget::OnBeginPrepareRender() fov = 2 * atanf((h * tan(fov / 2)) / maxTargetHeight); } } - m_Camera.SetFrustum(w, h, fov, fNearZ, gEnv->p3DEngine->GetMaxViewDistance()); + m_Camera.SetFrustum(w, h, fov, fNearZ); } GetIEditor()->GetSystem()->SetViewCamera(m_Camera); @@ -2606,8 +2611,7 @@ bool EditorViewportWidget::GetActiveCameraPosition(AZ::Vector3& cameraPos) { if (GetIEditor()->IsInGameMode()) { - const Vec3 camPos = m_engine->GetRenderingCamera().GetPosition(); - cameraPos = LYVec3ToAZVec3(camPos); + cameraPos = m_renderViewport->GetViewportContext()->GetCameraTransform().GetTranslation(); } else { diff --git a/Code/Sandbox/Editor/Material/MaterialManager.cpp b/Code/Sandbox/Editor/Material/MaterialManager.cpp index dee903dfe4..3c21a74d97 100644 --- a/Code/Sandbox/Editor/Material/MaterialManager.cpp +++ b/Code/Sandbox/Editor/Material/MaterialManager.cpp @@ -525,6 +525,11 @@ void CMaterialManager::OnEditorNotifyEvent(EEditorNotifyEvent event) ////////////////////////////////////////////////////////////////////////// void CMaterialManager::ReloadDirtyMaterials() { + if (!GetIEditor()->Get3DEngine()) + { + return; + } + IMaterialManager* runtimeMaterialManager = GetIEditor()->Get3DEngine()->GetMaterialManager(); uint32 mtlCount = 0; @@ -743,12 +748,15 @@ int CMaterialManager::GetHighlightFlags(CMaterial* pMaterial) const result |= eHighlight_NoSurfaceType; } - if (ISurfaceTypeManager* pSurfaceManager = GetIEditor()->Get3DEngine()->GetMaterialManager()->GetSurfaceTypeManager()) + if (GetIEditor()->Get3DEngine()) { - const ISurfaceType* pSurfaceType = pSurfaceManager->GetSurfaceTypeByName(surfaceTypeName.toUtf8().data()); - if (pSurfaceType && pSurfaceType->GetBreakability() != 0) + if (ISurfaceTypeManager* pSurfaceManager = GetIEditor()->Get3DEngine()->GetMaterialManager()->GetSurfaceTypeManager()) { - result |= eHighlight_Breakable; + const ISurfaceType* pSurfaceType = pSurfaceManager->GetSurfaceTypeByName(surfaceTypeName.toUtf8().data()); + if (pSurfaceType && pSurfaceType->GetBreakability() != 0) + { + result |= eHighlight_Breakable; + } } } diff --git a/Gems/LmbrCentral/Code/Source/Rendering/EditorLightComponent.cpp b/Gems/LmbrCentral/Code/Source/Rendering/EditorLightComponent.cpp index f46f60dd7b..e9ac845a88 100644 --- a/Gems/LmbrCentral/Code/Source/Rendering/EditorLightComponent.cpp +++ b/Gems/LmbrCentral/Code/Source/Rendering/EditorLightComponent.cpp @@ -805,7 +805,10 @@ namespace LmbrCentral AzToolsFramework::EditorEvents::Bus::Handler::BusDisconnect(); AZ::TransformNotificationBus::Handler::BusDisconnect(); - gEnv->p3DEngine->FreeRenderNodeState(&m_cubemapPreview); + if (gEnv->p3DEngine) + { + gEnv->p3DEngine->FreeRenderNodeState(&m_cubemapPreview); + } m_light.DestroyRenderLight(); m_light.SetEntity(AZ::EntityId()); @@ -903,6 +906,11 @@ namespace LmbrCentral void EditorLightComponent::OnViewCubemapChanged() { + if (!gEnv->p3DEngine) + { + return; + } + if (m_viewCubemap) { gEnv->p3DEngine->RegisterEntity(&m_cubemapPreview); @@ -1944,6 +1952,11 @@ namespace LmbrCentral AzToolsFramework::EditorRequestBus::BroadcastResult(m_editor, &AzToolsFramework::EditorRequests::GetEditor); } + if (!m_editor->Get3DEngine()) + { + return; + } + if (!m_materialManager) { m_materialManager = m_editor->Get3DEngine()->GetMaterialManager(); diff --git a/Gems/LmbrCentral/Code/Source/Rendering/LightInstance.cpp b/Gems/LmbrCentral/Code/Source/Rendering/LightInstance.cpp index d3564f228d..0c5da629ed 100644 --- a/Gems/LmbrCentral/Code/Source/Rendering/LightInstance.cpp +++ b/Gems/LmbrCentral/Code/Source/Rendering/LightInstance.cpp @@ -136,13 +136,16 @@ namespace const char* texturePath = configuration.m_projectorTexture.GetAssetPath().c_str(); const int flags = FT_DONT_STREAM; - lightParams.m_pLightImage = gEnv->pRenderer->EF_LoadTexture(texturePath, flags); - - if (!lightParams.m_pLightImage || !lightParams.m_pLightImage->IsTextureLoaded()) + if (gEnv->pRenderer) { - GetISystem()->Warning(VALIDATOR_MODULE_RENDERER, VALIDATOR_WARNING, 0, texturePath, - "Light projector texture not found: %s", texturePath); - lightParams.m_pLightImage = gEnv->pRenderer->EF_LoadTexture("Textures/defaults/red.dds", flags); + lightParams.m_pLightImage = gEnv->pRenderer->EF_LoadTexture(texturePath, flags); + + if (!lightParams.m_pLightImage || !lightParams.m_pLightImage->IsTextureLoaded()) + { + GetISystem()->Warning(VALIDATOR_MODULE_RENDERER, VALIDATOR_WARNING, 0, texturePath, + "Light projector texture not found: %s", texturePath); + lightParams.m_pLightImage = gEnv->pRenderer->EF_LoadTexture("Textures/defaults/red.dds", flags); + } } } break; @@ -180,8 +183,11 @@ namespace diffuseMap.insert(dotPos, "_diff"); } - lightParams.SetSpecularCubemap(gEnv->pRenderer->EF_LoadCubemapTexture(specularMap.c_str(), FT_DONT_STREAM)); - lightParams.SetDiffuseCubemap(gEnv->pRenderer->EF_LoadCubemapTexture(diffuseMap.c_str(), FT_DONT_STREAM)); + if (gEnv->pRenderer) + { + lightParams.SetSpecularCubemap(gEnv->pRenderer->EF_LoadCubemapTexture(specularMap.c_str(), FT_DONT_STREAM)); + lightParams.SetDiffuseCubemap(gEnv->pRenderer->EF_LoadCubemapTexture(diffuseMap.c_str(), FT_DONT_STREAM)); + } if (lightParams.GetDiffuseCubemap() && lightParams.GetSpecularCubemap()) { @@ -401,7 +407,7 @@ namespace LmbrCentral template void LightInstance::CreateRenderLightInternal(const ConfigurationType& configuration, ConfigToLightParamsFunc configToLightParams) { - if (m_renderLight || !configuration.m_visible) + if (m_renderLight || !configuration.m_visible || !gEnv->p3DEngine) { return; } From 764cd52c267494077d2c3a4e671594ba1cccbf54 Mon Sep 17 00:00:00 2001 From: AMZN-AlexOteiza <82234181+AMZN-AlexOteiza@users.noreply.github.com> Date: Mon, 26 Apr 2021 21:06:01 +0100 Subject: [PATCH 25/33] Fixed whitebox tests using correct imports Fixed whitebox tests using correct imports Co-authored-by: aljanru --- .../Gem/PythonTests/CMakeLists.txt | 33 +++++++++---------- ...C28798177_WhiteBox_AddComponentToEntity.py | 10 ++++-- .../C28798205_WhiteBox_SetInvisible.py | 10 ++++-- .../C29279329_WhiteBox_SetDefaultShape.py | 10 ++++-- 4 files changed, 37 insertions(+), 26 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/CMakeLists.txt b/AutomatedTesting/Gem/PythonTests/CMakeLists.txt index 9a46f656cf..260d5ea1b1 100644 --- a/AutomatedTesting/Gem/PythonTests/CMakeLists.txt +++ b/AutomatedTesting/Gem/PythonTests/CMakeLists.txt @@ -95,23 +95,22 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS) endif() ## White Box ## -# DISABLED - See LYN-2663 -#if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS) -# ly_add_pytest( -# NAME AutomatedTesting::WhiteBoxTests -# TEST_SUITE main -# TEST_SERIAL -# PATH ${CMAKE_CURRENT_LIST_DIR}/WhiteBox/TestSuite_Active.py -# TIMEOUT 3600 -# RUNTIME_DEPENDENCIES -# Legacy::Editor -# Legacy::CryRenderNULL -# AZ::AssetProcessor -# AutomatedTesting.Assets -# COMPONENT -# WhiteBox -# ) -#endif() +if(PAL_TRAIT_BUILD_TESTS_SUPPORTED AND PAL_TRAIT_BUILD_HOST_TOOLS) + ly_add_pytest( + NAME AutomatedTesting::WhiteBoxTests + TEST_SUITE main + TEST_SERIAL + PATH ${CMAKE_CURRENT_LIST_DIR}/WhiteBox/TestSuite_Active.py + TIMEOUT 3600 + RUNTIME_DEPENDENCIES + Legacy::Editor + Legacy::CryRenderNULL + AZ::AssetProcessor + AutomatedTesting.Assets + COMPONENT + WhiteBox + ) +endif() ## NvCloth ## # [TODO LYN-1928] Enable when AutomatedTesting runs with Atom diff --git a/AutomatedTesting/Gem/PythonTests/WhiteBox/C28798177_WhiteBox_AddComponentToEntity.py b/AutomatedTesting/Gem/PythonTests/WhiteBox/C28798177_WhiteBox_AddComponentToEntity.py index 252126674c..dabc04575f 100755 --- a/AutomatedTesting/Gem/PythonTests/WhiteBox/C28798177_WhiteBox_AddComponentToEntity.py +++ b/AutomatedTesting/Gem/PythonTests/WhiteBox/C28798177_WhiteBox_AddComponentToEntity.py @@ -22,10 +22,10 @@ class Tests(): # fmt:on -def run(): +def C28798177_WhiteBox_AddComponentToEntity(): import os import sys - import WhiteBoxInit as init + from Gems.WhiteBox.Editor.Scripts import WhiteBoxInit as init import ImportPathHelper as imports imports.init() @@ -58,4 +58,8 @@ def run(): if __name__ == "__main__": - run() + import ImportPathHelper as imports + imports.init() + + from editor_python_test_tools.utils import Report + Report.start_test(C28798177_WhiteBox_AddComponentToEntity) diff --git a/AutomatedTesting/Gem/PythonTests/WhiteBox/C28798205_WhiteBox_SetInvisible.py b/AutomatedTesting/Gem/PythonTests/WhiteBox/C28798205_WhiteBox_SetInvisible.py index b7c6719721..18a5c3164e 100755 --- a/AutomatedTesting/Gem/PythonTests/WhiteBox/C28798205_WhiteBox_SetInvisible.py +++ b/AutomatedTesting/Gem/PythonTests/WhiteBox/C28798205_WhiteBox_SetInvisible.py @@ -22,13 +22,13 @@ class Tests(): # fmt:on -def run(): +def C28798205_WhiteBox_SetInvisible(): # note: This automated test does not fully replicate the test case in Test Rail as it's # not currently possible using the Hydra API to get an EntityComponentIdPair at runtime, # in future game_mode will be activated and a runtime White Box Component queried import os import sys - import WhiteBoxInit as init + from Gems.WhiteBox.Editor.Scripts import WhiteBoxInit as init import ImportPathHelper as imports import editor_python_test_tools.hydra_editor_utils as hydra imports.init() @@ -68,4 +68,8 @@ def run(): if __name__ == "__main__": - run() + import ImportPathHelper as imports + imports.init() + + from editor_python_test_tools.utils import Report + Report.start_test(C28798205_WhiteBox_SetInvisible) diff --git a/AutomatedTesting/Gem/PythonTests/WhiteBox/C29279329_WhiteBox_SetDefaultShape.py b/AutomatedTesting/Gem/PythonTests/WhiteBox/C29279329_WhiteBox_SetDefaultShape.py index 0b0a081186..e892285dde 100755 --- a/AutomatedTesting/Gem/PythonTests/WhiteBox/C29279329_WhiteBox_SetDefaultShape.py +++ b/AutomatedTesting/Gem/PythonTests/WhiteBox/C29279329_WhiteBox_SetDefaultShape.py @@ -26,10 +26,10 @@ class Tests(): critical_shape_check = ("Default shape has more than 0 sides", "default shape has 0 sides") -def run(): +def C29279329_WhiteBox_SetDefaultShape(): import os import sys - import WhiteBoxInit as init + from Gems.WhiteBox.Editor.Scripts import WhiteBoxInit as init import ImportPathHelper as imports imports.init() @@ -107,4 +107,8 @@ def run(): if __name__ == "__main__": - run() + import ImportPathHelper as imports + imports.init() + + from editor_python_test_tools.utils import Report + Report.start_test(C29279329_WhiteBox_SetDefaultShape) From f76b69d480b2491bbe1ff8e31ea015f9b9d55966 Mon Sep 17 00:00:00 2001 From: mbalfour Date: Mon, 26 Apr 2021 16:15:25 -0500 Subject: [PATCH 26/33] Added a handful of null checks to let new level creation succeed. --- Code/Sandbox/Editor/GameExporter.cpp | 48 ++++++++++++++++++---------- Code/Sandbox/Editor/Mission.cpp | 7 ++-- Code/Sandbox/Editor/ShaderCache.cpp | 1 + 3 files changed, 37 insertions(+), 19 deletions(-) diff --git a/Code/Sandbox/Editor/GameExporter.cpp b/Code/Sandbox/Editor/GameExporter.cpp index 00836018cf..9039fca70d 100644 --- a/Code/Sandbox/Editor/GameExporter.cpp +++ b/Code/Sandbox/Editor/GameExporter.cpp @@ -139,7 +139,10 @@ bool CGameExporter::Export(unsigned int flags, [[maybe_unused]] EEndian eExportE // Make sure we unload any unused CGFs before exporting so that they don't end up in // the level data. - pEditor->Get3DEngine()->FreeUnusedCGFResources(); + if (pEditor->Get3DEngine()) + { + pEditor->Get3DEngine()->FreeUnusedCGFResources(); + } CCryEditDoc* pDocument = pEditor->GetDocument(); @@ -282,7 +285,7 @@ void CGameExporter::ExportVisAreas(const char* pszGamePath, EEndian eExportEndia SHotUpdateInfo exportInfo; I3DEngine* p3DEngine = pEditor->Get3DEngine(); - if (eExportEndian == GetPlatformEndian()) // skip second export, this data is common for PC and consoles + if (p3DEngine && (eExportEndian == GetPlatformEndian())) // skip second export, this data is common for PC and consoles { std::vector* pTempBrushTable = NULL; std::vector<_smart_ptr>* pTempMatsTable = NULL; @@ -367,25 +370,28 @@ void CGameExporter::ExportLevelData(const QString& path, bool bExportMission) QString missionFileName; QString currentMissionFileName; I3DEngine* p3DEngine = pEditor->Get3DEngine(); - for (int i = 0; i < pDocument->GetMissionCount(); i++) + if (p3DEngine) { - CMission* pMission = pDocument->GetMission(i); + for (int i = 0; i < pDocument->GetMissionCount(); i++) + { + CMission* pMission = pDocument->GetMission(i); - QString name = pMission->GetName(); - name.replace(' ', '_'); - missionFileName = QStringLiteral("Mission_%1.xml").arg(name); + QString name = pMission->GetName(); + name.replace(' ', '_'); + missionFileName = QStringLiteral("Mission_%1.xml").arg(name); - XmlNodeRef missionDescNode = missionsNode->newChild("Mission"); - missionDescNode->setAttr("Name", pMission->GetName().toUtf8().data()); - missionDescNode->setAttr("File", missionFileName.toUtf8().data()); - missionDescNode->setAttr("CGFCount", p3DEngine->GetLoadedObjectCount()); + XmlNodeRef missionDescNode = missionsNode->newChild("Mission"); + missionDescNode->setAttr("Name", pMission->GetName().toUtf8().data()); + missionDescNode->setAttr("File", missionFileName.toUtf8().data()); + missionDescNode->setAttr("CGFCount", p3DEngine->GetLoadedObjectCount()); - int nProgressBarRange = m_numExportedMaterials / 10 + p3DEngine->GetLoadedObjectCount(); - missionDescNode->setAttr("ProgressBarRange", nProgressBarRange); + int nProgressBarRange = m_numExportedMaterials / 10 + p3DEngine->GetLoadedObjectCount(); + missionDescNode->setAttr("ProgressBarRange", nProgressBarRange); - if (pMission == pCurrentMission) - { - currentMissionFileName = missionFileName; + if (pMission == pCurrentMission) + { + currentMissionFileName = missionFileName; + } } } @@ -413,7 +419,10 @@ void CGameExporter::ExportLevelData(const QString& path, bool bExportMission) XmlNodeRef missionNode = rootAction->createNode("Mission"); pCurrentMission->Export(missionNode, objectsNode); - missionNode->setAttr("CGFCount", p3DEngine->GetLoadedObjectCount()); + if (p3DEngine) + { + missionNode->setAttr("CGFCount", p3DEngine->GetLoadedObjectCount()); + } //if (!CFileUtil::OverwriteFile( path+currentMissionFileName )) // return; @@ -483,6 +492,11 @@ void CGameExporter::ExportLevelInfo(const QString& path) ////////////////////////////////////////////////////////////////////////// void CGameExporter::ExportMapInfo(XmlNodeRef& node) { + if (!GetIEditor()->Get3DEngine()) + { + return; + } + XmlNodeRef info = node->newChild("LevelInfo"); IEditor* pEditor = GetIEditor(); diff --git a/Code/Sandbox/Editor/Mission.cpp b/Code/Sandbox/Editor/Mission.cpp index 57f2033f3b..b9668f1c80 100644 --- a/Code/Sandbox/Editor/Mission.cpp +++ b/Code/Sandbox/Editor/Mission.cpp @@ -212,8 +212,11 @@ void CMission::SyncContent(bool bRetrieve, bool bIgnoreObjects, [[maybe_unused]] else { // Save time of day. - m_timeOfDay = XmlHelpers::CreateXmlNode("TimeOfDay"); - GetIEditor()->Get3DEngine()->GetTimeOfDay()->Serialize(m_timeOfDay, false); + if (GetIEditor()->Get3DEngine()) + { + m_timeOfDay = XmlHelpers::CreateXmlNode("TimeOfDay"); + GetIEditor()->Get3DEngine()->GetTimeOfDay()->Serialize(m_timeOfDay, false); + } if (!bIgnoreObjects) { diff --git a/Code/Sandbox/Editor/ShaderCache.cpp b/Code/Sandbox/Editor/ShaderCache.cpp index 5a5b0d8f58..3beeb9a7c4 100644 --- a/Code/Sandbox/Editor/ShaderCache.cpp +++ b/Code/Sandbox/Editor/ShaderCache.cpp @@ -138,6 +138,7 @@ bool CLevelShaderCache::SaveBuffer(QString& textBuffer) void CLevelShaderCache::Update() { IRenderer* pRenderer = gEnv->pRenderer; + if (pRenderer) { QString buf; char* str = NULL; From c415fcc0b42dd42c349be98fc050de57ba396885 Mon Sep 17 00:00:00 2001 From: Aaron Ruiz Mora Date: Tue, 27 Apr 2021 10:00:27 +0100 Subject: [PATCH 27/33] Cloth will override all the vertices of the mesh and do CPU skinning on the non-simulated vertices when the optimization 'remove static particles' is enabled --- .../ClothComponentMesh/ActorClothSkinning.cpp | 191 ++++++++++-------- .../ClothComponentMesh/ActorClothSkinning.h | 29 ++- .../ClothComponentMesh/ClothComponentMesh.cpp | 49 +++-- Gems/NvCloth/Code/Source/Utils/AssetHelper.h | 3 + .../Code/Source/Utils/MeshAssetHelper.cpp | 9 + .../ActorClothSkinningTest.cpp | 24 +-- 6 files changed, 179 insertions(+), 126 deletions(-) diff --git a/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ActorClothSkinning.cpp b/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ActorClothSkinning.cpp index ffbba25ee0..0baa385f44 100644 --- a/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ActorClothSkinning.cpp +++ b/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ActorClothSkinning.cpp @@ -33,7 +33,6 @@ namespace NvCloth AZ::EntityId entityId, const MeshNodeInfo& meshNodeInfo, const size_t numSimParticles, - const AZStd::vector& meshRemappedVertices, AZStd::vector& skinningData) { AZ::Data::Asset modelAsset; @@ -115,14 +114,7 @@ namespace NvCloth for (int vertexIndex = 0; vertexIndex < subMeshInfo.m_numVertices; ++vertexIndex) { - const int skinnedDataIndex = meshRemappedVertices[subMeshInfo.m_verticesFirstIndex + vertexIndex]; - if (skinnedDataIndex < 0) - { - // Removed particle - continue; - } - - SkinningInfo& skinningInfo = skinningData[skinnedDataIndex]; + SkinningInfo& skinningInfo = skinningData[subMeshInfo.m_verticesFirstIndex + vertexIndex]; skinningInfo.m_jointIndices.resize(influenceCount); skinningInfo.m_jointWeights.resize(influenceCount); @@ -208,19 +200,17 @@ namespace NvCloth { } + protected: // ActorClothSkinning overrides ... void UpdateSkinning() override; - void ApplySkinning( - const AZStd::vector& originalPositions, - AZStd::vector& positions) override; + bool HasSkinningTransformData() override; + void ComputeVertexSkinnningTransform(const SkinningInfo& skinningInfo) override; + AZ::Vector3 ComputeSkinningPosition(const AZ::Vector3& originalPosition) override; + AZ::Vector3 ComputeSkinningVector(const AZ::Vector3& originalVector) override; private: - AZ::Vector3 ComputeSkinnedPosition( - const AZ::Vector3& originalPosition, - const SkinningInfo& skinningInfo, - const AZ::Matrix3x4* skinningMatrices); - const AZ::Matrix3x4* m_skinningMatrices = nullptr; + AZ::Matrix3x4 m_vertexSkinningTransform = AZ::Matrix3x4::CreateIdentity(); }; void ActorClothSkinningLinear::UpdateSkinning() @@ -230,35 +220,14 @@ namespace NvCloth m_skinningMatrices = Internal::ObtainSkinningMatrices(m_entityId); } - void ActorClothSkinningLinear::ApplySkinning( - const AZStd::vector& originalPositions, - AZStd::vector& positions) + bool ActorClothSkinningLinear::HasSkinningTransformData() { - if (!m_skinningMatrices) - { - return; - } - - AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Cloth); - - for (size_t index = 0; index < originalPositions.size(); ++index) - { - const AZ::Vector3 skinnedPosition = ComputeSkinnedPosition( - originalPositions[index].GetAsVector3(), - m_skinningData[index], - m_skinningMatrices); - - // Avoid overwriting the w component - positions[index].Set(skinnedPosition, positions[index].GetW()); - } + return m_skinningMatrices != nullptr; } - AZ::Vector3 ActorClothSkinningLinear::ComputeSkinnedPosition( - const AZ::Vector3& originalPosition, - const SkinningInfo& skinningInfo, - const AZ::Matrix3x4* skinningMatrices) + void ActorClothSkinningLinear::ComputeVertexSkinnningTransform(const SkinningInfo& skinningInfo) { - AZ::Matrix3x4 clothSkinningMatrix = AZ::Matrix3x4::CreateZero(); + m_vertexSkinningTransform = AZ::Matrix3x4::CreateZero(); for (size_t weightIndex = 0; weightIndex < skinningInfo.m_jointWeights.size(); ++weightIndex) { const AZ::u16 jointIndex = skinningInfo.m_jointIndices[weightIndex]; @@ -273,11 +242,19 @@ namespace NvCloth // This way the skinning results are much similar to the skinning performed in GPU. for (int i = 0; i < 3; ++i) { - clothSkinningMatrix.SetRow(i, clothSkinningMatrix.GetRow(i) + skinningMatrices[jointIndex].GetRow(i) * jointWeight); + m_vertexSkinningTransform.SetRow(i, m_vertexSkinningTransform.GetRow(i) + m_skinningMatrices[jointIndex].GetRow(i) * jointWeight); } } + } - return clothSkinningMatrix * originalPosition; + AZ::Vector3 ActorClothSkinningLinear::ComputeSkinningPosition(const AZ::Vector3& originalPosition) + { + return m_vertexSkinningTransform * originalPosition; + } + + AZ::Vector3 ActorClothSkinningLinear::ComputeSkinningVector(const AZ::Vector3& originalVector) + { + return (m_vertexSkinningTransform * AZ::Vector4::CreateFromVector3AndFloat(originalVector, 0.0f)).GetAsVector3().GetNormalized(); } // Specialized class that applies dual quaternion blending skinning @@ -290,22 +267,19 @@ namespace NvCloth { } + protected: // ActorClothSkinning overrides ... void UpdateSkinning() override; - void ApplySkinning( - const AZStd::vector& originalPositions, - AZStd::vector& positions) override; + bool HasSkinningTransformData() override; + void ComputeVertexSkinnningTransform(const SkinningInfo& skinningInfo) override; + AZ::Vector3 ComputeSkinningPosition(const AZ::Vector3& originalPosition) override; + AZ::Vector3 ComputeSkinningVector(const AZ::Vector3& originalVector) override; private: - AZ::Vector3 ComputeSkinnedPosition( - const AZ::Vector3& originalPosition, - const SkinningInfo& skinningInfo, - const AZStd::unordered_map& skinningDualQuaternions); - AZStd::unordered_map m_skinningDualQuaternions; + DualQuat m_vertexSkinningTransform = DualQuat(type_identity::IDENTITY); }; - void ActorClothSkinningDualQuaternion::UpdateSkinning() { AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Cloth); @@ -313,35 +287,14 @@ namespace NvCloth m_skinningDualQuaternions = Internal::ObtainSkinningDualQuaternions(m_entityId, m_jointIndices); } - void ActorClothSkinningDualQuaternion::ApplySkinning( - const AZStd::vector& originalPositions, - AZStd::vector& positions) + bool ActorClothSkinningDualQuaternion::HasSkinningTransformData() { - if (m_skinningDualQuaternions.empty()) - { - return; - } - - AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Cloth); - - for (size_t index = 0; index < originalPositions.size(); ++index) - { - const AZ::Vector3 skinnedPosition = ComputeSkinnedPosition( - originalPositions[index].GetAsVector3(), - m_skinningData[index], - m_skinningDualQuaternions); - - // Avoid overwriting the w component - positions[index].Set(skinnedPosition, positions[index].GetW()); - } + return !m_skinningDualQuaternions.empty(); } - AZ::Vector3 ActorClothSkinningDualQuaternion::ComputeSkinnedPosition( - const AZ::Vector3& originalPosition, - const SkinningInfo& skinningInfo, - const AZStd::unordered_map& skinningDualQuaternions) + void ActorClothSkinningDualQuaternion::ComputeVertexSkinnningTransform(const SkinningInfo& skinningInfo) { - DualQuat clothSkinningDualQuaternion(type_zero::ZERO); + m_vertexSkinningTransform = DualQuat(type_zero::ZERO); for (size_t weightIndex = 0; weightIndex < skinningInfo.m_jointWeights.size(); ++weightIndex) { const AZ::u16 jointIndex = skinningInfo.m_jointIndices[weightIndex]; @@ -352,21 +305,28 @@ namespace NvCloth continue; } - clothSkinningDualQuaternion += skinningDualQuaternions.at(jointIndex) * jointWeight; + m_vertexSkinningTransform += m_skinningDualQuaternions.at(jointIndex) * jointWeight; } - clothSkinningDualQuaternion.Normalize(); + m_vertexSkinningTransform.Normalize(); + } + + AZ::Vector3 ActorClothSkinningDualQuaternion::ComputeSkinningPosition(const AZ::Vector3& originalPosition) + { + return LYVec3ToAZVec3(m_vertexSkinningTransform * AZVec3ToLYVec3(originalPosition)); + } - return LYVec3ToAZVec3(clothSkinningDualQuaternion * AZVec3ToLYVec3(originalPosition)); + AZ::Vector3 ActorClothSkinningDualQuaternion::ComputeSkinningVector(const AZ::Vector3& originalVector) + { + return LYVec3ToAZVec3(m_vertexSkinningTransform.nq * AZVec3ToLYVec3(originalVector)).GetNormalized(); } AZStd::unique_ptr ActorClothSkinning::Create( AZ::EntityId entityId, const MeshNodeInfo& meshNodeInfo, - const size_t numSimParticles, - const AZStd::vector& meshRemappedVertices) + const size_t numSimParticles) { AZStd::vector skinningData; - if (!Internal::ObtainSkinningData(entityId, meshNodeInfo, numSimParticles, meshRemappedVertices, skinningData)) + if (!Internal::ObtainSkinningData(entityId, meshNodeInfo, numSimParticles, skinningData)) { return nullptr; } @@ -427,6 +387,69 @@ namespace NvCloth { } + void ActorClothSkinning::ApplySkinning( + const AZStd::vector& originalPositions, + AZStd::vector& positions, + const AZStd::vector& meshRemappedVertices) + { + if (!HasSkinningTransformData() || + originalPositions.empty() || + originalPositions.size() != positions.size() || + m_skinningData.size() != meshRemappedVertices.size()) + { + return; + } + + AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Cloth); + + AZStd::unordered_set skinnedIndices; + for (size_t index = 0; index < meshRemappedVertices.size(); ++index) + { + const int remappedIndex = meshRemappedVertices[index]; + if (remappedIndex >= 0 && !skinnedIndices.contains(remappedIndex)) + { + ComputeVertexSkinnningTransform(m_skinningData[index]); + + const AZ::Vector3 skinnedPosition = ComputeSkinningPosition(originalPositions[remappedIndex].GetAsVector3()); + positions[remappedIndex].Set(skinnedPosition, positions[remappedIndex].GetW()); // Avoid overwriting the w component + + skinnedIndices.emplace(remappedIndex); // Avoid computing this index again + } + } + } + + void ActorClothSkinning::ApplySkinninOnRemovedVertices( + const MeshClothInfo& originalData, + ClothComponentMesh::RenderData& renderData, + const AZStd::vector& meshRemappedVertices) + { + if (!HasSkinningTransformData() || + originalData.m_particles.empty() || + originalData.m_particles.size() != renderData.m_particles.size() || + originalData.m_particles.size() != m_skinningData.size() || + m_skinningData.size() != meshRemappedVertices.size()) + { + return; + } + + AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Cloth); + + for (size_t index = 0; index < originalData.m_particles.size(); ++index) + { + if (meshRemappedVertices[index] < 0) + { + ComputeVertexSkinnningTransform(m_skinningData[index]); + + const AZ::Vector3 skinnedPosition = ComputeSkinningPosition(originalData.m_particles[index].GetAsVector3()); + renderData.m_particles[index].Set(skinnedPosition, renderData.m_particles[index].GetW()); // Avoid overwriting the w component + + renderData.m_tangents[index] = ComputeSkinningVector(originalData.m_tangents[index]); + renderData.m_bitangents[index] = ComputeSkinningVector(originalData.m_bitangents[index]); + renderData.m_normals[index] = ComputeSkinningVector(originalData.m_normals[index]); + } + } + } + void ActorClothSkinning::UpdateActorVisibility() { bool isVisible = true; diff --git a/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ActorClothSkinning.h b/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ActorClothSkinning.h index 8fd77c9347..8cf139c75a 100644 --- a/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ActorClothSkinning.h +++ b/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ActorClothSkinning.h @@ -16,6 +16,8 @@ #include +#include + namespace NvCloth { struct MeshNodeInfo; @@ -42,8 +44,7 @@ namespace NvCloth static AZStd::unique_ptr Create( AZ::EntityId entityId, const MeshNodeInfo& meshNodeInfo, - const size_t numSimParticles, - const AZStd::vector& meshRemappedVertices); + const size_t numSimParticles); explicit ActorClothSkinning(AZ::EntityId entityId); @@ -52,9 +53,17 @@ namespace NvCloth //! Applies skinning to a list of positions. //! @note w components are not affected. - virtual void ApplySkinning( + void ApplySkinning( const AZStd::vector& originalPositions, - AZStd::vector& positions) = 0; + AZStd::vector& positions, + const AZStd::vector& meshRemappedVertices); + + //! Applies skinning to a list of positions and vectors whose vertices + //! have not been used for simulation (remapped index is negative). + void ApplySkinninOnRemovedVertices( + const MeshClothInfo& originalData, + ClothComponentMesh::RenderData& renderData, + const AZStd::vector& meshRemappedVertices); //! Updates visibility variables. void UpdateActorVisibility(); @@ -66,6 +75,18 @@ namespace NvCloth bool WasActorVisible() const; protected: + //! Returns true if it has valid skinning trasform data. + virtual bool HasSkinningTransformData() = 0; + + //! Computes the skinnning transformation to apply to a vertex data. + virtual void ComputeVertexSkinnningTransform(const SkinningInfo& skinningInfo) = 0; + + //! Computes skinning on a position. + virtual AZ::Vector3 ComputeSkinningPosition(const AZ::Vector3& originalPosition) = 0; + + //! Computes skinning on a vector. + virtual AZ::Vector3 ComputeSkinningVector(const AZ::Vector3& originalVector) = 0; + AZ::EntityId m_entityId; // Skinning information of all particles diff --git a/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ClothComponentMesh.cpp b/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ClothComponentMesh.cpp index f1d088823f..740518b61a 100644 --- a/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ClothComponentMesh.cpp +++ b/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ClothComponentMesh.cpp @@ -166,6 +166,13 @@ namespace NvCloth // Initialize render data m_renderDataBufferIndex = 0; + { + auto& renderData = GetRenderData(); + renderData.m_particles = m_meshClothInfo.m_particles; + renderData.m_tangents = m_meshClothInfo.m_tangents; + renderData.m_bitangents = m_meshClothInfo.m_bitangents; + renderData.m_normals = m_meshClothInfo.m_normals; + } UpdateRenderData(m_cloth->GetParticles()); // Copy the first initialized element to the rest of the buffer for (AZ::u32 i = 1; i < RenderDataBufferSize; ++i) @@ -177,7 +184,7 @@ namespace NvCloth m_actorClothColliders = ActorClothColliders::Create(m_entityId); // It will return a valid instance if it's an actor with skinning data. - m_actorClothSkinning = ActorClothSkinning::Create(m_entityId, m_meshNodeInfo, m_cloth->GetParticles().size(), m_meshRemappedVertices); + m_actorClothSkinning = ActorClothSkinning::Create(m_entityId, m_meshNodeInfo, m_meshClothInfo.m_particles.size()); m_numberOfClothSkinningUpdates = 0; m_clothConstraints = ClothConstraints::Create( @@ -356,7 +363,7 @@ namespace NvCloth { // Update skinning for all particles and apply it to cloth AZStd::vector particles = m_cloth->GetParticles(); - m_actorClothSkinning->ApplySkinning(m_cloth->GetInitialParticles(), particles); + m_actorClothSkinning->ApplySkinning(m_cloth->GetInitialParticles(), particles, m_meshRemappedVertices); m_cloth->SetParticles(AZStd::move(particles)); m_cloth->DiscardParticleDelta(); } @@ -372,8 +379,8 @@ namespace NvCloth if (m_actorClothSkinning) { - m_actorClothSkinning->ApplySkinning(m_clothConstraints->GetMotionConstraints(), m_motionConstraints); - m_actorClothSkinning->ApplySkinning(m_clothConstraints->GetSeparationConstraints(), m_separationConstraints); + m_actorClothSkinning->ApplySkinning(m_clothConstraints->GetMotionConstraints(), m_motionConstraints, m_meshRemappedVertices); + m_actorClothSkinning->ApplySkinning(m_clothConstraints->GetSeparationConstraints(), m_separationConstraints, m_meshRemappedVertices); } m_cloth->GetClothConfigurator()->SetMotionConstraints(m_motionConstraints); @@ -392,6 +399,14 @@ namespace NvCloth return; } + auto& renderData = GetRenderData(); + + if (m_config.m_removeStaticTriangles && m_actorClothSkinning) + { + // Apply skinning to the non-simulated part of the mesh. + m_actorClothSkinning->ApplySkinninOnRemovedVertices(m_meshClothInfo, renderData, m_meshRemappedVertices); + } + // Calculate normals of the cloth particles (simplified mesh). AZStd::vector normals; [[maybe_unused]] bool normalsCalculated = @@ -401,19 +416,10 @@ namespace NvCloth // Copy particles and normals to render data. // Since cloth's vertices were welded together, // the full mesh will result in smooth normals. - auto& renderData = GetRenderData(); - renderData.m_particles.resize_no_construct(m_meshRemappedVertices.size()); - renderData.m_normals.resize_no_construct(m_meshRemappedVertices.size()); for (size_t index = 0; index < m_meshRemappedVertices.size(); ++index) { const int remappedIndex = m_meshRemappedVertices[index]; - if (remappedIndex < 0) - { - // Removed particle. Assign initial values to have something valid during tangents and bitangents calculation. - renderData.m_particles[index] = m_meshClothInfo.m_particles[index]; - renderData.m_normals[index] = AZ::Vector3::CreateAxisZ(); - } - else + if (remappedIndex >= 0) { renderData.m_particles[index] = particles[remappedIndex]; renderData.m_normals[index] = normals[remappedIndex]; @@ -505,8 +511,8 @@ namespace NvCloth } const AZ::RPI::ModelLodAsset::Mesh& subMesh = modelLodAsset->GetMeshes()[subMeshInfo.m_primitiveIndex]; - int numVertices = subMeshInfo.m_numVertices; - int firstVertex = subMeshInfo.m_verticesFirstIndex; + const int numVertices = subMeshInfo.m_numVertices; + const int firstVertex = subMeshInfo.m_verticesFirstIndex; if (subMesh.GetVertexCount() != numVertices) { AZ_Error("ClothComponentMesh", false, @@ -540,12 +546,6 @@ namespace NvCloth { const int renderVertexIndex = firstVertex + index; - if (m_meshRemappedVertices[renderVertexIndex] < 0) - { - // Removed particle from simulation - continue; - } - const SimParticleFormat& renderParticle = renderParticles[renderVertexIndex]; destVerticesBuffer[index].Set( renderParticle.GetX(), @@ -604,10 +604,7 @@ namespace NvCloth m_meshClothInfo.m_particles, m_meshClothInfo.m_indices, meshSimplifiedParticles, meshSimplifiedIndices, m_meshRemappedVertices, - // [TODO LYN-1890] - // Since blend weights cannot be controlled per instance with Atom, - // this additional mesh optimization is not possible at the moment. - false /*m_config.m_removeStaticTriangles*/); + m_config.m_removeStaticTriangles); if (meshSimplifiedParticles.empty() || meshSimplifiedIndices.empty()) { diff --git a/Gems/NvCloth/Code/Source/Utils/AssetHelper.h b/Gems/NvCloth/Code/Source/Utils/AssetHelper.h index 9630eeb5e1..4c73282008 100644 --- a/Gems/NvCloth/Code/Source/Utils/AssetHelper.h +++ b/Gems/NvCloth/Code/Source/Utils/AssetHelper.h @@ -65,6 +65,9 @@ namespace NvCloth AZStd::vector m_uvs; AZStd::vector m_motionConstraints; AZStd::vector m_backstopData; //!< X contains offset, Y contains radius. + AZStd::vector m_tangents; + AZStd::vector m_bitangents; + AZStd::vector m_normals; }; //! Interface to obtain cloth information from inside an Asset. diff --git a/Gems/NvCloth/Code/Source/Utils/MeshAssetHelper.cpp b/Gems/NvCloth/Code/Source/Utils/MeshAssetHelper.cpp index fa8d6e5455..00ce77c176 100644 --- a/Gems/NvCloth/Code/Source/Utils/MeshAssetHelper.cpp +++ b/Gems/NvCloth/Code/Source/Utils/MeshAssetHelper.cpp @@ -12,6 +12,8 @@ #include +#include + #include namespace NvCloth @@ -224,6 +226,13 @@ namespace NvCloth meshClothInfo.m_indices.insert(meshClothInfo.m_indices.end(), sourceIndices.begin(), sourceIndices.end()); } + // Calculate tangent space for the mesh. + [[maybe_unused]] bool tangentSpaceCalculated = + AZ::Interface::Get()->CalculateTangentSpace( + meshClothInfo.m_particles, meshClothInfo.m_indices, meshClothInfo.m_uvs, + meshClothInfo.m_tangents, meshClothInfo.m_bitangents, meshClothInfo.m_normals); + AZ_Assert(tangentSpaceCalculated, "Failed to calculate tangent space."); + return true; } } // namespace NvCloth diff --git a/Gems/NvCloth/Code/Tests/Components/ClothComponentMesh/ActorClothSkinningTest.cpp b/Gems/NvCloth/Code/Tests/Components/ClothComponentMesh/ActorClothSkinningTest.cpp index 2977cfce8c..75cff2da04 100644 --- a/Gems/NvCloth/Code/Tests/Components/ClothComponentMesh/ActorClothSkinningTest.cpp +++ b/Gems/NvCloth/Code/Tests/Components/ClothComponentMesh/ActorClothSkinningTest.cpp @@ -98,7 +98,7 @@ namespace UnitTest { AZ::EntityId entityId; AZStd::unique_ptr actorClothSkinning = - NvCloth::ActorClothSkinning::Create(entityId, {}, 0, {}); + NvCloth::ActorClothSkinning::Create(entityId, {}, 0); EXPECT_TRUE(actorClothSkinning.get() == nullptr); } @@ -107,7 +107,7 @@ namespace UnitTest { AZ::EntityId entityId; AZStd::unique_ptr actorClothSkinning = - NvCloth::ActorClothSkinning::Create(entityId, MeshNodeInfo, MeshRemappedVertices.size(), MeshRemappedVertices); + NvCloth::ActorClothSkinning::Create(entityId, MeshNodeInfo, MeshRemappedVertices.size()); EXPECT_TRUE(actorClothSkinning.get() == nullptr); } @@ -122,7 +122,7 @@ namespace UnitTest } AZStd::unique_ptr actorClothSkinning = - NvCloth::ActorClothSkinning::Create(m_actorComponent->GetEntityId(), {}, 0, {}); + NvCloth::ActorClothSkinning::Create(m_actorComponent->GetEntityId(), {}, 0); EXPECT_TRUE(actorClothSkinning.get() == nullptr); } @@ -139,7 +139,7 @@ namespace UnitTest } AZStd::unique_ptr actorClothSkinning = - NvCloth::ActorClothSkinning::Create(m_actorComponent->GetEntityId(), MeshNodeInfo, MeshVertices.size(), MeshRemappedVertices); + NvCloth::ActorClothSkinning::Create(m_actorComponent->GetEntityId(), MeshNodeInfo, MeshVertices.size()); EXPECT_TRUE(actorClothSkinning.get() == nullptr); } @@ -156,7 +156,7 @@ namespace UnitTest } AZStd::unique_ptr actorClothSkinning = - NvCloth::ActorClothSkinning::Create(m_actorComponent->GetEntityId(), MeshNodeInfo, MeshVertices.size(), MeshRemappedVertices); + NvCloth::ActorClothSkinning::Create(m_actorComponent->GetEntityId(), MeshNodeInfo, MeshVertices.size()); EXPECT_TRUE(actorClothSkinning.get() != nullptr); } @@ -184,7 +184,7 @@ namespace UnitTest } AZStd::unique_ptr actorClothSkinning = - NvCloth::ActorClothSkinning::Create(actorComponent->GetEntityId(), MeshNodeInfo, MeshVertices.size(), MeshRemappedVertices); + NvCloth::ActorClothSkinning::Create(actorComponent->GetEntityId(), MeshNodeInfo, MeshVertices.size()); ASSERT_TRUE(actorClothSkinning.get() != nullptr); const AZStd::vector clothParticles = {{ @@ -195,7 +195,7 @@ namespace UnitTest AZStd::vector skinnedClothParticles(clothParticles.size(), NvCloth::SimParticleFormat(0.0f, 0.0f, 0.0f, 1.0f)); actorClothSkinning->UpdateSkinning(); - actorClothSkinning->ApplySkinning(clothParticles, skinnedClothParticles); + actorClothSkinning->ApplySkinning(clothParticles, skinnedClothParticles, MeshRemappedVertices); EXPECT_THAT(skinnedClothParticles, ::testing::Pointwise(ContainerIsCloseTolerance(Tolerance), clothParticles)); @@ -208,7 +208,7 @@ namespace UnitTest AZStd::vector newSkinnedClothParticles(clothParticles.size(), NvCloth::SimParticleFormat(0.0f, 0.0f, 0.0f, 1.0f)); actorClothSkinning->UpdateSkinning(); - actorClothSkinning->ApplySkinning(clothParticles, newSkinnedClothParticles); + actorClothSkinning->ApplySkinning(clothParticles, newSkinnedClothParticles, MeshRemappedVertices); const AZ::Transform diffTransform = AZ::Transform::CreateRotationY(AZ::DegToRad(90.0f)); const AZStd::vector clothParticlesResult = {{ @@ -245,7 +245,7 @@ namespace UnitTest } AZStd::unique_ptr actorClothSkinning = - NvCloth::ActorClothSkinning::Create(m_actorComponent->GetEntityId(), MeshNodeInfo, MeshVertices.size(), MeshRemappedVertices); + NvCloth::ActorClothSkinning::Create(m_actorComponent->GetEntityId(), MeshNodeInfo, MeshVertices.size()); ASSERT_TRUE(actorClothSkinning.get() != nullptr); const AZStd::vector clothParticles = {{ @@ -256,7 +256,7 @@ namespace UnitTest AZStd::vector skinnedClothParticles(clothParticles.size(), NvCloth::SimParticleFormat(0.0f, 0.0f, 0.0f, 1.0f)); actorClothSkinning->UpdateSkinning(); - actorClothSkinning->ApplySkinning(clothParticles, skinnedClothParticles); + actorClothSkinning->ApplySkinning(clothParticles, skinnedClothParticles, MeshRemappedVertices); EXPECT_THAT(skinnedClothParticles, ::testing::Pointwise(ContainerIsCloseTolerance(Tolerance), clothParticles)); @@ -271,7 +271,7 @@ namespace UnitTest AZStd::vector newSkinnedClothParticles(clothParticles.size(), NvCloth::SimParticleFormat(0.0f, 0.0f, 0.0f, 1.0f)); actorClothSkinning->UpdateSkinning(); - actorClothSkinning->ApplySkinning(clothParticles, newSkinnedClothParticles); + actorClothSkinning->ApplySkinning(clothParticles, newSkinnedClothParticles, MeshRemappedVertices); const AZStd::vector clothParticlesResult = {{ NvCloth::SimParticleFormat(-48.4177f, -31.9446f, 45.2279f, 1.0f), @@ -294,7 +294,7 @@ namespace UnitTest } AZStd::unique_ptr actorClothSkinning = - NvCloth::ActorClothSkinning::Create(m_actorComponent->GetEntityId(), MeshNodeInfo, MeshVertices.size(), MeshRemappedVertices); + NvCloth::ActorClothSkinning::Create(m_actorComponent->GetEntityId(), MeshNodeInfo, MeshVertices.size()); ASSERT_TRUE(actorClothSkinning.get() != nullptr); EXPECT_FALSE(actorClothSkinning->IsActorVisible()); From 7f1e3b4054a71202b00a57b52e15114cd7ad4601 Mon Sep 17 00:00:00 2001 From: Aaron Ruiz Mora Date: Tue, 27 Apr 2021 13:56:31 +0100 Subject: [PATCH 28/33] Moving largeworlds's failing tests to sandbox --- .../dyn_veg/test_DynamicSliceInstanceSpawner.py | 2 +- .../largeworlds/dyn_veg/test_EmptyInstanceSpawner.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DynamicSliceInstanceSpawner.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DynamicSliceInstanceSpawner.py index c5b8046f73..f0673a9438 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DynamicSliceInstanceSpawner.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_DynamicSliceInstanceSpawner.py @@ -41,7 +41,7 @@ class TestDynamicSliceInstanceSpawner(object): return console @pytest.mark.test_case_id("C28851763") - @pytest.mark.SUITE_main + @pytest.mark.SUITE_sandbox @pytest.mark.parametrize("launcher_platform", ['windows_editor']) def test_DynamicSliceInstanceSpawner_DynamicSliceSpawnerWorks(self, request, editor, level, workspace, project, launcher_platform): diff --git a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_EmptyInstanceSpawner.py b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_EmptyInstanceSpawner.py index a7f221b780..fc8c31fc7b 100755 --- a/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_EmptyInstanceSpawner.py +++ b/AutomatedTesting/Gem/PythonTests/largeworlds/dyn_veg/test_EmptyInstanceSpawner.py @@ -36,8 +36,13 @@ class TestEmptyInstanceSpawner(object): file_system.delete([os.path.join(workspace.paths.engine_root(), project, "Levels", level)], True, True) - @pytest.mark.test_case_id("C28851762") + # Main suite needs at least one test @pytest.mark.SUITE_main + def test_EmptyInstanceSpawner_Dummy(self, request, editor, level, workspace, project, launcher_platform): + pass + + @pytest.mark.test_case_id("C28851762") + @pytest.mark.SUITE_sandbox def test_EmptyInstanceSpawner_EmptySpawnerWorks(self, request, editor, level, launcher_platform): cfg_args = [level] From 95a44c481ad42f059f926f21072cedbc12210a3c Mon Sep 17 00:00:00 2001 From: amzn-sean <75276488+amzn-sean@users.noreply.github.com> Date: Tue, 27 Apr 2021 14:17:05 +0100 Subject: [PATCH 29/33] fixed errors from main merge --- .../Gem/PythonTests/physics/TestSuite_Periodic.py | 2 ++ .../DebugDraw/Code/Source/DebugDrawSystemComponent.cpp | 9 ++++++--- .../Code/Source/PhysXCharacters/API/CharacterUtils.cpp | 10 ++++++++-- Gems/PhysXDebug/Code/Source/SystemComponent.cpp | 6 +++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py b/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py index ad8ae6481f..50eb36e31d 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py +++ b/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py @@ -269,6 +269,8 @@ class TestAutomation(TestAutomationBase): from . import C18977601_Material_FrictionCombinePriority as test_module self._run_test(request, workspace, editor, test_module) + @pytest.mark.xfail( + reason="Something with the CryRenderer disabling is causeing this test to fail now.") @revert_physics_config def test_C13895144_Ragdoll_ChangeLevel(self, request, workspace, editor, launcher_platform): from . import C13895144_Ragdoll_ChangeLevel as test_module diff --git a/Gems/DebugDraw/Code/Source/DebugDrawSystemComponent.cpp b/Gems/DebugDraw/Code/Source/DebugDrawSystemComponent.cpp index 0a1dd366e6..545dc7d2f9 100644 --- a/Gems/DebugDraw/Code/Source/DebugDrawSystemComponent.cpp +++ b/Gems/DebugDraw/Code/Source/DebugDrawSystemComponent.cpp @@ -443,9 +443,12 @@ namespace DebugDraw AZ::TransformBus::EventResult(sphereElement.m_worldLocation, sphereElement.m_targetEntityId, &AZ::TransformBus::Events::GetWorldTranslation); } - ColorB lyColor(sphereElement.m_color.ToU32()); - Vec3 worldLocation(AZVec3ToLYVec3(sphereElement.m_worldLocation)); - gEnv->pRenderer->GetIRenderAuxGeom()->DrawSphere(worldLocation, sphereElement.m_radius, lyColor, true); + if (gEnv->pRenderer) + { + ColorB lyColor(sphereElement.m_color.ToU32()); + Vec3 worldLocation(AZVec3ToLYVec3(sphereElement.m_worldLocation)); + gEnv->pRenderer->GetIRenderAuxGeom()->DrawSphere(worldLocation, sphereElement.m_radius, lyColor, true); + } } removeExpiredDebugElementsFromVector(m_activeSpheres); diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp b/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp index 893e622701..fb55e8865d 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp +++ b/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp @@ -197,9 +197,15 @@ namespace PhysX if (colliderNodeConfig) { AZStd::vector> shapes; - for (const auto& shapeConfig : colliderNodeConfig->m_shapes) + for (const auto [colliderConfig, shapeConfig] : colliderNodeConfig->m_shapes) { - if (auto shape = AZStd::make_shared(*shapeConfig.first, *shapeConfig.second)) + if (colliderConfig == nullptr || shapeConfig == nullptr) + { + AZ_Error("PhysX Ragdoll", false, "Failed to create collider shape for ragdoll node %s", nodeConfig.m_debugName.c_str()); + return nullptr; + } + + if (auto shape = AZStd::make_shared(*colliderConfig, *shapeConfig)) { shapes.emplace_back(shape); } diff --git a/Gems/PhysXDebug/Code/Source/SystemComponent.cpp b/Gems/PhysXDebug/Code/Source/SystemComponent.cpp index 0d26d1cbc0..77b0959008 100644 --- a/Gems/PhysXDebug/Code/Source/SystemComponent.cpp +++ b/Gems/PhysXDebug/Code/Source/SystemComponent.cpp @@ -511,13 +511,13 @@ namespace PhysXDebug void SystemComponent::RenderBuffers() { - if (gEnv && !m_linePoints.empty()) + if (gEnv && gEnv->pRenderer && !m_linePoints.empty()) { AZ_Assert(m_linePoints.size() == m_lineColors.size(), "Lines: Expected an equal number of points to colors."); gEnv->pRenderer->GetIRenderAuxGeom()->DrawLines(m_linePoints.begin(), m_linePoints.size(), m_lineColors.begin(), 1.0f); } - if (gEnv && !m_trianglePoints.empty()) + if (gEnv && gEnv->pRenderer && !m_trianglePoints.empty()) { AZ_Assert(m_trianglePoints.size() == m_triangleColors.size(), "Triangles: Expected an equal number of points to colors."); gEnv->pRenderer->GetIRenderAuxGeom()->DrawTriangles(m_trianglePoints.begin(), m_trianglePoints.size(), m_triangleColors.begin()); @@ -829,7 +829,7 @@ namespace PhysXDebug { AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::Physics); - if (m_settings.m_visualizationEnabled && m_culling.m_boxWireframe) + if (gEnv && gEnv->pRenderer && m_settings.m_visualizationEnabled && m_culling.m_boxWireframe) { ColorB wireframeColor = MapOriginalPhysXColorToUserDefinedValues(1); AABB lyAABB(AZAabbToLyAABB(cullingBoxAabb)); From 5e50fc2961c010389fc908612afce783f7a19e7f Mon Sep 17 00:00:00 2001 From: amzn-sean <75276488+amzn-sean@users.noreply.github.com> Date: Tue, 27 Apr 2021 14:39:18 +0100 Subject: [PATCH 30/33] fix build failure --- AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py | 2 +- Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py b/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py index 50eb36e31d..39ed85a65a 100755 --- a/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py +++ b/AutomatedTesting/Gem/PythonTests/physics/TestSuite_Periodic.py @@ -270,7 +270,7 @@ class TestAutomation(TestAutomationBase): self._run_test(request, workspace, editor, test_module) @pytest.mark.xfail( - reason="Something with the CryRenderer disabling is causeing this test to fail now.") + reason="Something with the CryRenderer disabling is causing this test to fail now.") @revert_physics_config def test_C13895144_Ragdoll_ChangeLevel(self, request, workspace, editor, launcher_platform): from . import C13895144_Ragdoll_ChangeLevel as test_module diff --git a/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp b/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp index fb55e8865d..d1502a0c65 100644 --- a/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp +++ b/Gems/PhysX/Code/Source/PhysXCharacters/API/CharacterUtils.cpp @@ -197,7 +197,7 @@ namespace PhysX if (colliderNodeConfig) { AZStd::vector> shapes; - for (const auto [colliderConfig, shapeConfig] : colliderNodeConfig->m_shapes) + for (const auto& [colliderConfig, shapeConfig] : colliderNodeConfig->m_shapes) { if (colliderConfig == nullptr || shapeConfig == nullptr) { From 00fca9489c2471dab42154c6b9b6ba60d01170d3 Mon Sep 17 00:00:00 2001 From: Aaron Ruiz Mora Date: Tue, 27 Apr 2021 14:52:10 +0100 Subject: [PATCH 31/33] Fix editor crashing by protecting gEnv->g3DEngine --- Code/Sandbox/Editor/EditorViewportWidget.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Code/Sandbox/Editor/EditorViewportWidget.cpp b/Code/Sandbox/Editor/EditorViewportWidget.cpp index 25588e85a7..9ce567c91e 100644 --- a/Code/Sandbox/Editor/EditorViewportWidget.cpp +++ b/Code/Sandbox/Editor/EditorViewportWidget.cpp @@ -2428,7 +2428,10 @@ void EditorViewportWidget::SetDefaultCamera() return; } ResetToViewSourceType(ViewSourceType::None); - gEnv->p3DEngine->GetPostEffectBaseGroup()->SetParam("Dof_Active", 0.0f); + if (gEnv->p3DEngine) + { + gEnv->p3DEngine->GetPostEffectBaseGroup()->SetParam("Dof_Active", 0.0f); + } GetViewManager()->SetCameraObjectId(m_cameraObjectId); SetName(m_defaultViewName); SetViewTM(m_defaultViewTM); From d20fb50c9d9447ecb5fa5ae369dee9f2d73e101c Mon Sep 17 00:00:00 2001 From: Aaron Ruiz Mora Date: Tue, 27 Apr 2021 14:52:33 +0100 Subject: [PATCH 32/33] Cloth CPU Skinning using MCore DualQuaternions instead of Cry DualQuat --- .../ClothComponentMesh/ActorClothSkinning.cpp | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ActorClothSkinning.cpp b/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ActorClothSkinning.cpp index 0baa385f44..c295eca188 100644 --- a/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ActorClothSkinning.cpp +++ b/Gems/NvCloth/Code/Source/Components/ClothComponentMesh/ActorClothSkinning.cpp @@ -10,15 +10,13 @@ * */ -#include // Needed for DualQuat -#include - #include #include // Needed to access the Mesh information inside Actor. #include #include +#include #include #include @@ -171,7 +169,7 @@ namespace NvCloth return transformData->GetSkinningMatrices(); } - AZStd::unordered_map ObtainSkinningDualQuaternions( + AZStd::unordered_map ObtainSkinningDualQuaternions( AZ::EntityId entityId, const AZStd::vector& jointIndices) { @@ -181,10 +179,10 @@ namespace NvCloth return {}; } - AZStd::unordered_map skinningDualQuaternions; + AZStd::unordered_map skinningDualQuaternions; for (AZ::u16 jointIndex : jointIndices) { - skinningDualQuaternions.emplace(jointIndex, AZMatrix3x4ToLYMatrix3x4(skinningMatrices[jointIndex])); + skinningDualQuaternions.emplace(jointIndex, MCore::DualQuaternion(AZ::Transform::CreateFromMatrix3x4(skinningMatrices[jointIndex]))); } return skinningDualQuaternions; } @@ -276,8 +274,8 @@ namespace NvCloth AZ::Vector3 ComputeSkinningVector(const AZ::Vector3& originalVector) override; private: - AZStd::unordered_map m_skinningDualQuaternions; - DualQuat m_vertexSkinningTransform = DualQuat(type_identity::IDENTITY); + AZStd::unordered_map m_skinningDualQuaternions; + MCore::DualQuaternion m_vertexSkinningTransform; }; void ActorClothSkinningDualQuaternion::UpdateSkinning() @@ -294,7 +292,7 @@ namespace NvCloth void ActorClothSkinningDualQuaternion::ComputeVertexSkinnningTransform(const SkinningInfo& skinningInfo) { - m_vertexSkinningTransform = DualQuat(type_zero::ZERO); + m_vertexSkinningTransform = MCore::DualQuaternion(AZ::Quaternion::CreateZero(), AZ::Quaternion::CreateZero()); for (size_t weightIndex = 0; weightIndex < skinningInfo.m_jointWeights.size(); ++weightIndex) { const AZ::u16 jointIndex = skinningInfo.m_jointIndices[weightIndex]; @@ -312,12 +310,12 @@ namespace NvCloth AZ::Vector3 ActorClothSkinningDualQuaternion::ComputeSkinningPosition(const AZ::Vector3& originalPosition) { - return LYVec3ToAZVec3(m_vertexSkinningTransform * AZVec3ToLYVec3(originalPosition)); + return m_vertexSkinningTransform.TransformPoint(originalPosition); } AZ::Vector3 ActorClothSkinningDualQuaternion::ComputeSkinningVector(const AZ::Vector3& originalVector) { - return LYVec3ToAZVec3(m_vertexSkinningTransform.nq * AZVec3ToLYVec3(originalVector)).GetNormalized(); + return m_vertexSkinningTransform.TransformVector(originalVector).GetNormalized(); } AZStd::unique_ptr ActorClothSkinning::Create( From fc3a48bb26916618fdb77bfb2023bcde5eff5540 Mon Sep 17 00:00:00 2001 From: rhongAMZ <69218254+rhongAMZ@users.noreply.github.com> Date: Tue, 27 Apr 2021 09:07:34 -0700 Subject: [PATCH 33/33] EMFX: Fix a crash when deleting blend tree node (#331) --- Gems/EMotionFX/Code/EMotionFX/Source/BlendTree.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gems/EMotionFX/Code/EMotionFX/Source/BlendTree.cpp b/Gems/EMotionFX/Code/EMotionFX/Source/BlendTree.cpp index 02d286a1d0..3eb4aad119 100644 --- a/Gems/EMotionFX/Code/EMotionFX/Source/BlendTree.cpp +++ b/Gems/EMotionFX/Code/EMotionFX/Source/BlendTree.cpp @@ -303,7 +303,8 @@ namespace EMotionFX if (GetFinalNode() == nodeToRemove) { - SetFinalNodeId(AnimGraphNodeId::InvalidId); + m_finalNodeId = AnimGraphNodeId::InvalidId; + m_finalNode = nullptr; } // call it for all children