diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR.materialtype b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR.materialtype index c635f94d56..a71fc65e2a 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR.materialtype +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/EnhancedPBR.materialtype @@ -1465,14 +1465,9 @@ "file": "./EnhancedPBR_DepthPass_WithPS.shader", "tag": "DepthPass_WithPS" }, - // [GFX TODO][ATOM-4726] Use an "isSkinnedMesh" external material property and a functor that enables/disables the appropriate motion-vector shader { - "file": "Shaders/MotionVector/StaticMeshMotionVector.shader", - "tag": "StaticMeshMotionVector" - }, - { - "file": "Shaders/MotionVector/SkinnedMeshMotionVector.shader", - "tag": "SkinnedMeshMotionVector" + "file": "Shaders/MotionVector/MeshMotionVector.shader", + "tag": "MeshMotionVector" }, // Used by the light culling system to produce accurate depth bounds for this object when it uses blended transparency { @@ -1669,4 +1664,3 @@ "UV1": "Unwrapped" } } - diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.materialtype b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.materialtype index dfe2fad60f..fe86576cf8 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.materialtype +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/Skin.materialtype @@ -980,14 +980,9 @@ "file": "Shaders/Depth/DepthPass.shader", "tag": "DepthPass" }, - // [GFX TODO][ATOM-4726] Use an "isSkinnedMesh" external material property and a functor that enables/disables the appropriate motion-vector shader { - "file": "Shaders/MotionVector/StaticMeshMotionVector.shader", - "tag": "StaticMeshMotionVector" - }, - { - "file": "Shaders/MotionVector/SkinnedMeshMotionVector.shader", - "tag": "SkinnedMeshMotionVector" + "file": "Shaders/MotionVector/MeshMotionVector.shader", + "tag": "MeshMotionVector" } ], "functors": [ diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR.materialtype b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR.materialtype index d9a21e7662..bccb530eb4 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR.materialtype +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardMultilayerPBR.materialtype @@ -2632,14 +2632,9 @@ "file": "./StandardMultilayerPBR_DepthPass_WithPS.shader", "tag": "DepthPass_WithPS" }, - // [GFX TODO][ATOM-4726] Use an "isSkinnedMesh" external material property and a functor that enables/disables the appropriate motion-vector shader { - "file": "Shaders/MotionVector/StaticMeshMotionVector.shader", - "tag": "StaticMeshMotionVector" - }, - { - "file": "Shaders/MotionVector/SkinnedMeshMotionVector.shader", - "tag": "SkinnedMeshMotionVector" + "file": "Shaders/MotionVector/MeshMotionVector.shader", + "tag": "MeshMotionVector" } ], "functors": [ @@ -3103,4 +3098,3 @@ "UV1": "Unwrapped" } } - diff --git a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR.materialtype b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR.materialtype index fd2c74dae0..93220973df 100644 --- a/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR.materialtype +++ b/Gems/Atom/Feature/Common/Assets/Materials/Types/StandardPBR.materialtype @@ -1030,14 +1030,9 @@ "file": "./StandardPBR_DepthPass_WithPS.shader", "tag": "DepthPass_WithPS" }, - // [GFX TODO][ATOM-4726] Use an "isSkinnedMesh" external material property and a functor that enables/disables the appropriate motion-vector shader { - "file": "Shaders/MotionVector/StaticMeshMotionVector.shader", - "tag": "StaticMeshMotionVector" - }, - { - "file": "Shaders/MotionVector/SkinnedMeshMotionVector.shader", - "tag": "SkinnedMeshMotionVector" + "file": "Shaders/MotionVector/MeshMotionVector.shader", + "tag": "MeshMotionVector" }, // Used by the light culling system to produce accurate depth bounds for this object when it uses blended transparency { @@ -1187,4 +1182,3 @@ "UV1": "Unwrapped" } } - diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/MeshMotionVector.azsl b/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/MeshMotionVector.azsl new file mode 100644 index 0000000000..3fb3fc0fd8 --- /dev/null +++ b/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/MeshMotionVector.azsl @@ -0,0 +1,86 @@ +/* +* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or +* its licensors. +* +* For complete copyright and license terms please see the LICENSE at the root of this +* distribution (the "License"). All use of this software is governed by the License, +* or, if provided, by the license below or the license accompanying this file. Do not +* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* +*/ + +#include +#include + +#include +#include + +struct VSInput +{ + float3 m_position : POSITION; + + // This gets set automatically by the system at runtime only if it's available. + // There is a soft naming convention that associates this with o_prevPosition_isBound, which will be set to true whenever m_optional_prevPosition is available. + // (search "m_optional_" in ShaderVariantAssetBuilder for details on the naming convention). + // [GFX TODO][ATOM-14475]: Come up with a more elegant way to associate the isBound flag with the input stream. + // Vertex position of last frame to capture small scale motion due to vertex animation + float3 m_optional_prevPosition : POSITIONT; +}; + +struct VSOutput +{ + float4 m_position : SV_Position; + float3 m_worldPos : TEXCOORD0; + float3 m_worldPosPrev: TEXCOORD1; +}; + +struct PSOutput +{ + float2 m_motion : SV_Target0; +}; + +// Indicates whether the vertex input struct's "m_optional_prevPosition" is bound. If false, it is not safe to read from m_optional_prevPosition. +// This option gets set automatically by the system at runtime; there is a soft naming convention that associates it with m_optional_prevPosition. +// (search "m_optional_" in ShaderVariantAssetBuilder for details on the naming convention). +// [GFX TODO][ATOM-14475]: Come up with a more elegant way to associate the isBound flag with the input stream. +option bool o_prevPosition_isBound; + +VSOutput MainVS(VSInput IN) +{ + VSOutput OUT; + + OUT.m_worldPos = mul(SceneSrg::GetObjectToWorldMatrix(ObjectSrg::m_objectId), float4(IN.m_position, 1.0)).xyz; + OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(OUT.m_worldPos, 1.0)); + + if (o_prevPosition_isBound) + { + OUT.m_worldPosPrev = mul(SceneSrg::GetObjectToWorldMatrixPrev(ObjectSrg::m_objectId), float4(IN.m_optional_prevPosition, 1.0)).xyz; + } + else + { + OUT.m_worldPosPrev = mul(SceneSrg::GetObjectToWorldMatrixPrev(ObjectSrg::m_objectId), float4(IN.m_position, 1.0)).xyz; + } + + return OUT; +} + +PSOutput MainPS(VSOutput IN) +{ + PSOutput OUT; + + // Current clip position + float4 clipPos = mul(ViewSrg::m_viewProjectionMatrix, float4(IN.m_worldPos, 1.0)); + + // Reprojected last frame's clip position, for skinned mesh it also implies last key frame + float4 clipPosPrev = mul(ViewSrg::m_viewProjectionPrevMatrix, float4(IN.m_worldPosPrev, 1.0)); + + float2 motion = (clipPos.xy / clipPos.w - clipPosPrev.xy / clipPosPrev.w) * 0.5; + + OUT.m_motion = motion; + + // Flip y to line up with uv coordinates + OUT.m_motion.y = -OUT.m_motion.y; + + return OUT; +} diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/StaticMeshMotionVector.shader b/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/MeshMotionVector.shader similarity index 89% rename from Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/StaticMeshMotionVector.shader rename to Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/MeshMotionVector.shader index 0d580b1b10..c585060f3d 100644 --- a/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/StaticMeshMotionVector.shader +++ b/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/MeshMotionVector.shader @@ -1,5 +1,5 @@ { - "Source" : "StaticMeshMotionVector", + "Source" : "MeshMotionVector", "DepthStencilState" : { "Depth" : { "Enable" : true, "CompareFunc" : "GreaterEqual" } diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/MeshMotionVectorCommon.azsli b/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/MeshMotionVectorCommon.azsli deleted file mode 100644 index ff2758af87..0000000000 --- a/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/MeshMotionVectorCommon.azsli +++ /dev/null @@ -1,49 +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. -* -*/ - -#include -#include - -#include -#include - -struct VSOutput -{ - float4 m_position : SV_Position; - float3 m_worldPos : TEXCOORD0; - float3 m_worldPosPrev: TEXCOORD1; -}; - -struct PSOutput -{ - float2 m_motion : SV_Target0; -}; - -PSOutput MainPS(VSOutput IN) -{ - PSOutput OUT; - - // Current clip position - float4 clipPos = mul(ViewSrg::m_viewProjectionMatrix, float4(IN.m_worldPos, 1.0)); - - // Reprojected last frame's clip position, for skinned mesh it also implies last key frame - float4 clipPosPrev = mul(ViewSrg::m_viewProjectionPrevMatrix, float4(IN.m_worldPosPrev, 1.0)); - - float2 motion = (clipPos.xy / clipPos.w - clipPosPrev.xy / clipPosPrev.w) * 0.5; - - OUT.m_motion = motion; - - // Flip y to line up with uv coordinates - OUT.m_motion.y = -OUT.m_motion.y; - - return OUT; -} diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/SkinnedMeshMotionVector.azsl b/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/SkinnedMeshMotionVector.azsl deleted file mode 100644 index dcbba22b2a..0000000000 --- a/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/SkinnedMeshMotionVector.azsl +++ /dev/null @@ -1,34 +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. -* -*/ - -#include "./MeshMotionVectorCommon.azsli" - -struct VSInput -{ - float3 m_position : POSITION; - // Vertex position of last frame to capture small scale motion due to vertex animation - float3 m_prevPosition : POSITIONT; -}; - -VSOutput MainVS(VSInput IN) -{ - VSOutput OUT; - - OUT.m_worldPos = mul(SceneSrg::GetObjectToWorldMatrix(ObjectSrg::m_objectId), float4(IN.m_position, 1.0)).xyz; - OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(OUT.m_worldPos, 1.0)); - OUT.m_worldPosPrev = mul(SceneSrg::GetObjectToWorldMatrixPrev(ObjectSrg::m_objectId), float4(IN.m_prevPosition, 1.0)).xyz; - - return OUT; -} - - - diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/SkinnedMeshMotionVector.shader b/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/SkinnedMeshMotionVector.shader deleted file mode 100644 index 66d2fd88c5..0000000000 --- a/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/SkinnedMeshMotionVector.shader +++ /dev/null @@ -1,24 +0,0 @@ -{ - "Source" : "SkinnedMeshMotionVector", - - "DepthStencilState" : { - "Depth" : { "Enable" : true, "CompareFunc" : "GreaterEqual" } - }, - - "DrawList" : "motion", - - "ProgramSettings": - { - "EntryPoints": - [ - { - "name": "MainVS", - "type": "Vertex" - }, - { - "name": "MainPS", - "type": "Fragment" - } - ] - } -} diff --git a/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/StaticMeshMotionVector.azsl b/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/StaticMeshMotionVector.azsl deleted file mode 100644 index 11bc528f3b..0000000000 --- a/Gems/Atom/Feature/Common/Assets/Shaders/MotionVector/StaticMeshMotionVector.azsl +++ /dev/null @@ -1,32 +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. -* -*/ - -#include "./MeshMotionVectorCommon.azsli" - -struct VSInput -{ - float3 m_position : POSITION; -}; - -VSOutput MainVS(VSInput IN) -{ - VSOutput OUT; - - OUT.m_worldPos = mul(SceneSrg::GetObjectToWorldMatrix(ObjectSrg::m_objectId), float4(IN.m_position, 1.0)).xyz; - OUT.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(OUT.m_worldPos, 1.0)); - OUT.m_worldPosPrev = mul(SceneSrg::GetObjectToWorldMatrixPrev(ObjectSrg::m_objectId), float4(IN.m_position, 1.0)).xyz; - - return OUT; -} - - - 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 3dfabc586a..6a2721d4af 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 @@ -354,11 +354,8 @@ set(FILES Shaders/MorphTargets/MorphTargetSRG.azsli Shaders/MotionVector/CameraMotionVector.azsl Shaders/MotionVector/CameraMotionVector.shader - Shaders/MotionVector/MeshMotionVectorCommon.azsli - Shaders/MotionVector/SkinnedMeshMotionVector.azsl - Shaders/MotionVector/SkinnedMeshMotionVector.shader - Shaders/MotionVector/StaticMeshMotionVector.azsl - Shaders/MotionVector/StaticMeshMotionVector.shader + Shaders/MotionVector/MeshMotionVector.azsl + Shaders/MotionVector/MeshMotionVector.shader Shaders/PostProcessing/AcesOutputTransformLut.azsl Shaders/PostProcessing/AcesOutputTransformLut.shader Shaders/PostProcessing/ApplyShaperLookupTable.azsl diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessor.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessor.h index f1156cfe37..391a60a68d 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessor.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessor.h @@ -72,7 +72,6 @@ namespace AZ void UpdateDrawPackets(bool forceUpdate = false); void BuildCullable(); void UpdateCullBounds(const TransformServiceFeatureProcessor* transformService); - void SelectMotionVectorShader(Data::Instance material); void UpdateObjectSrg(); bool MaterialRequiresForwardPassIblSpecular(Data::Instance material) const; diff --git a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessorInterface.h b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessorInterface.h index d5a6ac1c3e..7cf9ab9685 100644 --- a/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessorInterface.h +++ b/Gems/Atom/Feature/Common/Code/Include/Atom/Feature/Mesh/MeshFeatureProcessorInterface.h @@ -32,7 +32,6 @@ namespace AZ using RequiresCloneCallback = AZStd::function& modelAsset)>; Data::Asset m_modelAsset; - bool m_isSkinnedMeshWithMotion = false; bool m_isRayTracingEnabled = true; bool m_useForwardPassIblSpecular = false; RequiresCloneCallback m_requiresCloneCallback = {}; diff --git a/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp b/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp index f51defc0f3..7867faf02a 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/Mesh/MeshFeatureProcessor.cpp @@ -158,11 +158,6 @@ namespace AZ MeshHandle meshDataHandle = m_meshData.emplace(); meshDataHandle->m_descriptor = descriptor; - - // Always disable ray tracing flag on skinned meshes - // [GFX TODO][ATOM-13067] Enable raytracing on skinned meshes - meshDataHandle->m_descriptor.m_isRayTracingEnabled &= !descriptor.m_isSkinnedMeshWithMotion; - meshDataHandle->m_scene = GetParentScene(); meshDataHandle->m_materialAssignments = materials; meshDataHandle->m_objectId = m_transformService->ReserveObjectId(); @@ -665,8 +660,6 @@ namespace AZ } } - SelectMotionVectorShader(material); - // setup the mesh draw packet RPI::MeshDrawPacket drawPacket(modelLod, meshIndex, material, m_shaderResourceGroup, materialAssignment.m_matModUvOverrides); @@ -1091,29 +1084,6 @@ namespace AZ m_cullBoundsNeedsUpdate = false; } - void MeshDataInstance::SelectMotionVectorShader(Data::Instance material) - { - // Two motion vector shaders are defined in the material for static mesh (only animated by transform matrix) - // and skinned mesh (per vertex animation) respectively, it's because they have different input signatures - // (skinned mesh needs two streaming channels while static mesh only needs one) that cannot be addressed by shader option - // itself. Therefore this function is used to pick one to use and disable the other one depending on the type of the mesh - // so it won't cause errors due to missing input streaming channel. - - //[GFX TODO][ATOM-4726] Replace this with a "isSkinnedMesh" external material property and a functor that enables/disables the appropriate shader - for (auto& shaderItem : material->GetShaderCollection()) - { - if (shaderItem.GetShaderAsset()->GetName() == Name{ "StaticMeshMotionVector" } && m_descriptor.m_isSkinnedMeshWithMotion) - { - shaderItem.SetEnabled(false); - } - - if (shaderItem.GetShaderAsset()->GetName() == Name{ "SkinnedMeshMotionVector" } && (!m_descriptor.m_isSkinnedMeshWithMotion)) - { - shaderItem.SetEnabled(false); - } - } - } - void MeshDataInstance::UpdateObjectSrg() { if (!m_shaderResourceGroup) diff --git a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Material/Material.h b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Material/Material.h index fa1bb57166..6cffe4a47d 100644 --- a/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Material/Material.h +++ b/Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Material/Material.h @@ -105,7 +105,6 @@ namespace AZ ChangeId GetCurrentChangeId() const; //! Return the set of shaders to be run by this material. - ShaderCollection& GetShaderCollection(); const ShaderCollection& GetShaderCollection() const; //! Attempts to set the value of a system-level shader option that is controlled by this material. diff --git a/Gems/Atom/RPI/Code/Source/RPI.Public/Material/Material.cpp b/Gems/Atom/RPI/Code/Source/RPI.Public/Material/Material.cpp index 3302190156..3f376ccf25 100644 --- a/Gems/Atom/RPI/Code/Source/RPI.Public/Material/Material.cpp +++ b/Gems/Atom/RPI/Code/Source/RPI.Public/Material/Material.cpp @@ -164,11 +164,6 @@ namespace AZ Data::AssetBus::Handler::BusDisconnect(); } - ShaderCollection& Material::GetShaderCollection() - { - return m_shaderCollection; - } - const ShaderCollection& Material::GetShaderCollection() const { return m_shaderCollection; diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.cpp b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.cpp index f4d4144796..29dee12489 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.cpp +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Source/AtomActorInstance.cpp @@ -628,7 +628,10 @@ namespace AZ { MeshHandleDescriptor meshDescriptor; meshDescriptor.m_modelAsset = m_skinnedMeshInstance->m_model->GetModelAsset(); - meshDescriptor.m_isSkinnedMeshWithMotion = true; + + // [GFX TODO][ATOM-13067] Enable raytracing on skinned meshes + meshDescriptor.m_isRayTracingEnabled = false; + m_meshHandle = AZStd::make_shared( m_meshFeatureProcessor->AcquireMesh(meshDescriptor, materials)); }