Merge branch 'main' into Atom/dmcdiar/ATOM-15517
This commit is contained in:
@@ -30,25 +30,7 @@ namespace AZ
|
||||
constexpr const char* PerContextSrgName = "PerContextSrg";
|
||||
constexpr const char* PerDrawSrgName = "PerDrawSrg";
|
||||
};
|
||||
|
||||
bool CompareTargetBlendState(const RHI::TargetBlendState& firstState, const RHI::TargetBlendState& secondState)
|
||||
{
|
||||
return !(firstState.m_enable != secondState.m_enable
|
||||
|| firstState.m_blendOp != secondState.m_blendOp
|
||||
|| firstState.m_blendDest != secondState.m_blendDest
|
||||
|| firstState.m_blendSource != secondState.m_blendSource
|
||||
|| firstState.m_blendAlphaDest != secondState.m_blendAlphaDest
|
||||
|| firstState.m_blendAlphaOp != secondState.m_blendAlphaOp
|
||||
|| firstState.m_blendAlphaSource != secondState.m_blendAlphaSource);
|
||||
}
|
||||
|
||||
bool CompareDepthState(const RHI::DepthState& firstState, const RHI::DepthState& secondState)
|
||||
{
|
||||
return !(firstState.m_enable != secondState.m_enable
|
||||
|| firstState.m_func != secondState.m_func
|
||||
|| firstState.m_writeMask != secondState.m_writeMask);
|
||||
}
|
||||
|
||||
|
||||
void DynamicDrawContext::MultiStates::UpdateHash(const DrawStateOptions& drawStateOptions)
|
||||
{
|
||||
if (!m_isDirty)
|
||||
@@ -70,9 +52,19 @@ namespace AZ
|
||||
seed = TypeHash64(m_depthState.m_writeMask, seed);
|
||||
}
|
||||
|
||||
if (RHI::CheckBitsAny(drawStateOptions, DrawStateOptions::EnableStencil))
|
||||
if (RHI::CheckBitsAny(drawStateOptions, DrawStateOptions::StencilState))
|
||||
{
|
||||
seed = TypeHash64(m_enableStencil, seed);
|
||||
seed = TypeHash64(m_stencilState.m_enable, seed);
|
||||
seed = TypeHash64(m_stencilState.m_readMask, seed);
|
||||
seed = TypeHash64(m_stencilState.m_writeMask, seed);
|
||||
seed = TypeHash64(m_stencilState.m_frontFace.m_failOp, seed);
|
||||
seed = TypeHash64(m_stencilState.m_frontFace.m_depthFailOp, seed);
|
||||
seed = TypeHash64(m_stencilState.m_frontFace.m_passOp, seed);
|
||||
seed = TypeHash64(m_stencilState.m_frontFace.m_func, seed);
|
||||
seed = TypeHash64(m_stencilState.m_backFace.m_failOp, seed);
|
||||
seed = TypeHash64(m_stencilState.m_backFace.m_depthFailOp, seed);
|
||||
seed = TypeHash64(m_stencilState.m_backFace.m_passOp, seed);
|
||||
seed = TypeHash64(m_stencilState.m_backFace.m_func, seed);
|
||||
}
|
||||
|
||||
if (RHI::CheckBitsAny(drawStateOptions, DrawStateOptions::FaceCullMode))
|
||||
@@ -203,7 +195,7 @@ namespace AZ
|
||||
m_currentStates.m_cullMode = m_pipelineState->ConstDescriptor().m_renderStates.m_rasterState.m_cullMode;
|
||||
m_currentStates.m_topology = m_pipelineState->ConstDescriptor().m_inputStreamLayout.GetTopology();
|
||||
m_currentStates.m_depthState = m_pipelineState->ConstDescriptor().m_renderStates.m_depthStencilState.m_depth;
|
||||
m_currentStates.m_enableStencil = m_pipelineState->ConstDescriptor().m_renderStates.m_depthStencilState.m_stencil.m_enable;
|
||||
m_currentStates.m_stencilState = m_pipelineState->ConstDescriptor().m_renderStates.m_depthStencilState.m_stencil;
|
||||
m_currentStates.m_blendState0 = m_pipelineState->ConstDescriptor().m_renderStates.m_blendState.m_targets[0];
|
||||
m_currentStates.UpdateHash(m_drawStateOptions);
|
||||
|
||||
@@ -291,7 +283,7 @@ namespace AZ
|
||||
{
|
||||
if (RHI::CheckBitsAny(m_drawStateOptions, DrawStateOptions::DepthState))
|
||||
{
|
||||
if (!CompareDepthState(m_currentStates.m_depthState, depthState))
|
||||
if (!(m_currentStates.m_depthState == depthState))
|
||||
{
|
||||
m_currentStates.m_depthState = depthState;
|
||||
m_currentStates.m_isDirty = true;
|
||||
@@ -303,19 +295,19 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
void DynamicDrawContext::SetEnableStencil(bool enable)
|
||||
void DynamicDrawContext::SetStencilState(RHI::StencilState stencilState)
|
||||
{
|
||||
if (RHI::CheckBitsAny(m_drawStateOptions, DrawStateOptions::EnableStencil))
|
||||
if (RHI::CheckBitsAny(m_drawStateOptions, DrawStateOptions::StencilState))
|
||||
{
|
||||
if (m_currentStates.m_enableStencil != enable)
|
||||
if (!(m_currentStates.m_stencilState == stencilState))
|
||||
{
|
||||
m_currentStates.m_enableStencil = enable;
|
||||
m_currentStates.m_stencilState = stencilState;
|
||||
m_currentStates.m_isDirty = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AZ_Warning("RHI", false, "Can't set SetEnableStencil if DrawVariation::EnableStencil wasn't enabled");
|
||||
AZ_Warning("RHI", false, "Can't set SetStencilState if DrawVariation::StencilState wasn't enabled");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -340,7 +332,7 @@ namespace AZ
|
||||
{
|
||||
if (RHI::CheckBitsAny(m_drawStateOptions, DrawStateOptions::BlendMode))
|
||||
{
|
||||
if (!CompareTargetBlendState(m_currentStates.m_blendState0, blendState))
|
||||
if (!(m_currentStates.m_blendState0 == blendState))
|
||||
{
|
||||
m_currentStates.m_blendState0 = blendState;
|
||||
m_currentStates.m_isDirty = true;
|
||||
@@ -695,9 +687,9 @@ namespace AZ
|
||||
{
|
||||
m_pipelineState->RenderStatesOverlay().m_depthStencilState.m_depth = m_currentStates.m_depthState;
|
||||
}
|
||||
if (RHI::CheckBitsAny(m_drawStateOptions, DrawStateOptions::EnableStencil))
|
||||
if (RHI::CheckBitsAny(m_drawStateOptions, DrawStateOptions::StencilState))
|
||||
{
|
||||
m_pipelineState->RenderStatesOverlay().m_depthStencilState.m_stencil.m_enable = m_currentStates.m_enableStencil;
|
||||
m_pipelineState->RenderStatesOverlay().m_depthStencilState.m_stencil = m_currentStates.m_stencilState;
|
||||
}
|
||||
if (RHI::CheckBitsAny(m_drawStateOptions, DrawStateOptions::FaceCullMode))
|
||||
{
|
||||
|
||||
@@ -140,8 +140,9 @@ namespace AZ
|
||||
bool Model::LocalRayIntersection(const AZ::Vector3& rayStart, const AZ::Vector3& dir, float& distance, AZ::Vector3& normal) const
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(Debug::ProfileCategory::AzRender);
|
||||
float firstHit;
|
||||
const int result = Intersect::IntersectRayAABB2(rayStart, dir.GetReciprocal(), m_aabb, firstHit, distance);
|
||||
float start;
|
||||
float end;
|
||||
const int result = Intersect::IntersectRayAABB2(rayStart, dir.GetReciprocal(), m_aabb, start, end);
|
||||
if (Intersect::ISECT_RAY_AABB_NONE != result)
|
||||
{
|
||||
if (ModelAsset* modelAssetPtr = m_modelAsset.Get())
|
||||
@@ -164,7 +165,9 @@ namespace AZ
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Model::RayIntersection(const AZ::Transform& modelTransform, const AZ::Vector3& nonUniformScale, const AZ::Vector3& rayStart, const AZ::Vector3& dir, float& distanceFactor, AZ::Vector3& normal) const
|
||||
bool Model::RayIntersection(
|
||||
const AZ::Transform& modelTransform, const AZ::Vector3& nonUniformScale, const AZ::Vector3& rayStart, const AZ::Vector3& dir,
|
||||
float& distanceFactor, AZ::Vector3& normal) const
|
||||
{
|
||||
AZ_PROFILE_FUNCTION(Debug::ProfileCategory::AzRender);
|
||||
const AZ::Vector3 clampedScale = nonUniformScale.GetMax(AZ::Vector3(AZ::MinTransformScale));
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
#include <AzCore/std/numeric.h>
|
||||
#include <AzCore/std/limits.h>
|
||||
#include <Atom/RPI.Reflect/Model/ModelKdTree.h>
|
||||
#include <AzCore/Math/IntersectSegment.h>
|
||||
|
||||
@@ -191,10 +192,10 @@ namespace AZ
|
||||
|
||||
if (ModelLodAsset* lodAssetPtr = model->GetLodAssets()[0].Get())
|
||||
{
|
||||
AZ_Warning("ModelKdTree", lodAssetPtr->GetMeshes().size() <= std::numeric_limits<AZ::u8>::max() + 1,
|
||||
AZ_Warning("ModelKdTree", lodAssetPtr->GetMeshes().size() <= AZStd::numeric_limits<AZ::u8>::max() + 1,
|
||||
"KdTree generation doesn't support models with greater than 256 meshes. RayIntersection results will be incorrect "
|
||||
"unless the meshes are merged or broken up into multiple models");
|
||||
const size_t size = AZStd::min<size_t>(lodAssetPtr->GetMeshes().size(), std::numeric_limits<AZ::u8>::max() + 1);
|
||||
const size_t size = AZStd::min<size_t>(lodAssetPtr->GetMeshes().size(), AZStd::numeric_limits<AZ::u8>::max() + 1);
|
||||
m_meshes.reserve(size);
|
||||
AZStd::transform(
|
||||
lodAssetPtr->GetMeshes().begin(), AZStd::next(lodAssetPtr->GetMeshes().begin(), size),
|
||||
@@ -204,20 +205,42 @@ namespace AZ
|
||||
}
|
||||
}
|
||||
|
||||
bool ModelKdTree::RayIntersection(const AZ::Vector3& raySrc, const AZ::Vector3& rayDir, float& distance, AZ::Vector3& normal) const
|
||||
bool ModelKdTree::RayIntersection(
|
||||
const AZ::Vector3& raySrc, const AZ::Vector3& rayDir, float& distanceNormalized, AZ::Vector3& normal) const
|
||||
{
|
||||
return RayIntersectionRecursively(m_pRootNode.get(), raySrc, rayDir, distance, normal);
|
||||
float closestDistanceNormalized = AZStd::numeric_limits<float>::max();
|
||||
if (RayIntersectionRecursively(m_pRootNode.get(), raySrc, rayDir, closestDistanceNormalized, normal))
|
||||
{
|
||||
distanceNormalized = closestDistanceNormalized;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ModelKdTree::RayIntersectionRecursively(ModelKdTreeNode* pNode, const AZ::Vector3& raySrc, const AZ::Vector3& rayDir, float& distance, AZ::Vector3& normal) const
|
||||
bool ModelKdTree::RayIntersectionRecursively(
|
||||
ModelKdTreeNode* pNode,
|
||||
const AZ::Vector3& raySrc,
|
||||
const AZ::Vector3& rayDir,
|
||||
float& distanceNormalized,
|
||||
AZ::Vector3& normal) const
|
||||
{
|
||||
using Intersect::IntersectRayAABB2;
|
||||
using Intersect::IntersectSegmentTriangleCCW;
|
||||
using Intersect::ISECT_RAY_AABB_NONE;
|
||||
|
||||
if (!pNode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float start, end;
|
||||
if (AZ::Intersect::IntersectRayAABB2(raySrc, rayDir.GetReciprocal(), pNode->GetBoundBox(), start, end) == Intersect::ISECT_RAY_AABB_NONE)
|
||||
if (IntersectRayAABB2(raySrc, rayDir.GetReciprocal(), pNode->GetBoundBox(), start, end) == ISECT_RAY_AABB_NONE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (start > distanceNormalized)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -235,17 +258,13 @@ namespace AZ
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::Vector3 intersectionNormal;
|
||||
float hitDistanceNormalized;
|
||||
const float maxDist(FLT_MAX);
|
||||
float nearestDist = maxDist;
|
||||
|
||||
float nearestDistanceNormalized = distanceNormalized;
|
||||
for (AZ::u32 i = 0; i < nVBuffSize; ++i)
|
||||
{
|
||||
const auto& [first, second, third] = pNode->GetVertexIndex(i);
|
||||
const AZ::u32 nObjIndex = pNode->GetObjIndex(i);
|
||||
|
||||
AZStd::array_view<float> positionBuffer = m_meshes[nObjIndex].m_vertexData;
|
||||
const AZStd::array_view<float> positionBuffer = m_meshes[nObjIndex].m_vertexData;
|
||||
|
||||
if (positionBuffer.empty())
|
||||
{
|
||||
@@ -258,25 +277,23 @@ namespace AZ
|
||||
AZ::Vector3{positionBuffer[third * 3 + 0], positionBuffer[third * 3 + 1], positionBuffer[third * 3 + 2]},
|
||||
};
|
||||
|
||||
const AZ::Vector3 rayEnd = raySrc + rayDir * distance;
|
||||
|
||||
if (AZ::Intersect::IntersectSegmentTriangleCCW(raySrc, rayEnd, trianglePoints[0], trianglePoints[1], trianglePoints[2],
|
||||
intersectionNormal, hitDistanceNormalized) != Intersect::ISECT_RAY_AABB_NONE)
|
||||
float hitDistanceNormalized;
|
||||
AZ::Vector3 intersectionNormal;
|
||||
const AZ::Vector3 rayEnd = raySrc + rayDir;
|
||||
if (IntersectSegmentTriangleCCW(raySrc, rayEnd, trianglePoints[0], trianglePoints[1], trianglePoints[2],
|
||||
intersectionNormal, hitDistanceNormalized) != ISECT_RAY_AABB_NONE)
|
||||
{
|
||||
float hitDistance = hitDistanceNormalized * distance;
|
||||
|
||||
if (nearestDist > hitDistance)
|
||||
if (nearestDistanceNormalized > hitDistanceNormalized)
|
||||
{
|
||||
normal = intersectionNormal;
|
||||
nearestDistanceNormalized = hitDistanceNormalized;
|
||||
}
|
||||
|
||||
nearestDist = AZStd::GetMin(nearestDist, hitDistance);
|
||||
}
|
||||
}
|
||||
|
||||
if (nearestDist < maxDist)
|
||||
if (nearestDistanceNormalized < distanceNormalized)
|
||||
{
|
||||
distance = AZStd::GetMin(distance, nearestDist);
|
||||
distanceNormalized = nearestDistanceNormalized;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -284,8 +301,8 @@ namespace AZ
|
||||
}
|
||||
|
||||
// running both sides to find the closest intersection
|
||||
const bool bFoundChild0 = RayIntersectionRecursively(pNode->GetChild(0), raySrc, rayDir, distance, normal);
|
||||
const bool bFoundChild1 = RayIntersectionRecursively(pNode->GetChild(1), raySrc, rayDir, distance, normal);
|
||||
const bool bFoundChild0 = RayIntersectionRecursively(pNode->GetChild(0), raySrc, rayDir, distanceNormalized, normal);
|
||||
const bool bFoundChild1 = RayIntersectionRecursively(pNode->GetChild(1), raySrc, rayDir, distanceNormalized, normal);
|
||||
|
||||
return bFoundChild0 || bFoundChild1;
|
||||
}
|
||||
@@ -311,5 +328,5 @@ namespace AZ
|
||||
GetPenetratedBoxesRecursively(pNode->GetChild(0), raySrc, rayDir, outBoxes);
|
||||
GetPenetratedBoxesRecursively(pNode->GetChild(1), raySrc, rayDir, outBoxes);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace RPI
|
||||
} // namespace AZ
|
||||
|
||||
Reference in New Issue
Block a user