[ATOM-14344][ATOM-13908] Merging skinned and static mesh motion shaders using an optional vertex stream (#1491)
[ATOM-14344][ATOM-13908] Merging skinned and static mesh motion shaders using an optional vertext stream. This removes the log spam "Mesh does not have all the required input streams. Missing 'POSITIONT0'." and allows Material::GetShaderCollection() to be const only as it was intended. The MeshFeatureProcessor also no longer needs to decide which motion vector shader to use, and therefore no longer has m_skinnedMeshWithMotion in the descriptor to acquire a mesh.
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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": [
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <scenesrg.srgi>
|
||||
#include <viewsrg.srgi>
|
||||
|
||||
#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
|
||||
#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
|
||||
|
||||
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;
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"Source" : "StaticMeshMotionVector",
|
||||
"Source" : "MeshMotionVector",
|
||||
|
||||
"DepthStencilState" : {
|
||||
"Depth" : { "Enable" : true, "CompareFunc" : "GreaterEqual" }
|
||||
@@ -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 <scenesrg.srgi>
|
||||
#include <viewsrg.srgi>
|
||||
|
||||
#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
|
||||
#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
{
|
||||
"Source" : "SkinnedMeshMotionVector",
|
||||
|
||||
"DepthStencilState" : {
|
||||
"Depth" : { "Enable" : true, "CompareFunc" : "GreaterEqual" }
|
||||
},
|
||||
|
||||
"DrawList" : "motion",
|
||||
|
||||
"ProgramSettings":
|
||||
{
|
||||
"EntryPoints":
|
||||
[
|
||||
{
|
||||
"name": "MainVS",
|
||||
"type": "Vertex"
|
||||
},
|
||||
{
|
||||
"name": "MainPS",
|
||||
"type": "Fragment"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -72,7 +72,6 @@ namespace AZ
|
||||
void UpdateDrawPackets(bool forceUpdate = false);
|
||||
void BuildCullable();
|
||||
void UpdateCullBounds(const TransformServiceFeatureProcessor* transformService);
|
||||
void SelectMotionVectorShader(Data::Instance<RPI::Material> material);
|
||||
void UpdateObjectSrg();
|
||||
bool MaterialRequiresForwardPassIblSpecular(Data::Instance<RPI::Material> material) const;
|
||||
|
||||
|
||||
-1
@@ -32,7 +32,6 @@ namespace AZ
|
||||
using RequiresCloneCallback = AZStd::function<bool(const Data::Asset<RPI::ModelAsset>& modelAsset)>;
|
||||
|
||||
Data::Asset<RPI::ModelAsset> m_modelAsset;
|
||||
bool m_isSkinnedMeshWithMotion = false;
|
||||
bool m_isRayTracingEnabled = true;
|
||||
bool m_useForwardPassIblSpecular = false;
|
||||
RequiresCloneCallback m_requiresCloneCallback = {};
|
||||
|
||||
@@ -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<RPI::Material> 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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -164,11 +164,6 @@ namespace AZ
|
||||
Data::AssetBus::Handler::BusDisconnect();
|
||||
}
|
||||
|
||||
ShaderCollection& Material::GetShaderCollection()
|
||||
{
|
||||
return m_shaderCollection;
|
||||
}
|
||||
|
||||
const ShaderCollection& Material::GetShaderCollection() const
|
||||
{
|
||||
return m_shaderCollection;
|
||||
|
||||
@@ -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<MeshFeatureProcessorInterface::MeshHandle>(
|
||||
m_meshFeatureProcessor->AcquireMesh(meshDescriptor, materials));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user