Calculating uv transforms for terrain detail materials (#7375)
Calculating uv transforms for terrain detail materials This adds support for uv transforms in terrain detail materials. To support this work, the code for generating a matrix from material properties was pulled out of the material functor and put into a new MaterialUtils file in Atom Utils.monroegm-disable-blank-issue-2
parent
d77403f9df
commit
ff4412db7c
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AzCore/std/containers/span.h>
|
||||||
|
#include <AzCore/Math/Vector2.h>
|
||||||
|
#include <AzCore/Math/Matrix3x3.h>
|
||||||
|
#include <AzCore/RTTI/TypeInfo.h>
|
||||||
|
|
||||||
|
//! This file holds useful material related utility functions.
|
||||||
|
|
||||||
|
namespace AZ
|
||||||
|
{
|
||||||
|
namespace Render
|
||||||
|
{
|
||||||
|
enum class TransformType
|
||||||
|
{
|
||||||
|
Invalid,
|
||||||
|
Scale,
|
||||||
|
Rotate,
|
||||||
|
Translate
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UvTransformDescriptor
|
||||||
|
{
|
||||||
|
Vector2 m_center{ Vector2::CreateZero() };
|
||||||
|
float m_scale{ 1.0f };
|
||||||
|
float m_scaleX{ 1.0f };
|
||||||
|
float m_scaleY{ 1.0f };
|
||||||
|
float m_translateX{ 0.0f };
|
||||||
|
float m_translateY{ 0.0f };
|
||||||
|
float m_rotateDegrees{ 0.0f };
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a 3x3 uv transform matrix from a set of input properties.
|
||||||
|
Matrix3x3 CreateUvTransformMatrix(const UvTransformDescriptor& desc, const AZStd::span<const TransformType> transformOrder);
|
||||||
|
}
|
||||||
|
|
||||||
|
AZ_TYPE_INFO_SPECIALIZE(Render::TransformType, "{D8C15D33-CE3D-4297-A646-030B0625BF84}");
|
||||||
|
}
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||||
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Atom/Utils/MaterialUtils.h>
|
||||||
|
|
||||||
|
namespace AZ::Render
|
||||||
|
{
|
||||||
|
|
||||||
|
Matrix3x3 CreateUvTransformMatrix(const UvTransformDescriptor& desc, AZStd::span<const TransformType> transformOrder)
|
||||||
|
{
|
||||||
|
float translateX = desc.m_translateX;
|
||||||
|
float translateY = desc.m_translateY;
|
||||||
|
|
||||||
|
if (desc.m_scaleX != 0.0f)
|
||||||
|
{
|
||||||
|
translateX *= (1.0f / desc.m_scaleX);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (desc.m_scaleY != 0.0f)
|
||||||
|
{
|
||||||
|
translateY *= (1.0f / desc.m_scaleY);
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix3x3 translateCenter2D = Matrix3x3::CreateIdentity();
|
||||||
|
translateCenter2D.SetBasisZ(-desc.m_center.GetX(), -desc.m_center.GetY(), 1.0f);
|
||||||
|
|
||||||
|
Matrix3x3 translateCenterInv2D = Matrix3x3::CreateIdentity();
|
||||||
|
translateCenterInv2D.SetBasisZ(desc.m_center.GetX(), desc.m_center.GetY(), 1.0f);
|
||||||
|
|
||||||
|
Matrix3x3 scale2D = Matrix3x3::CreateDiagonal(AZ::Vector3(desc.m_scaleX * desc.m_scale, desc.m_scaleY * desc.m_scale, 1.0f));
|
||||||
|
|
||||||
|
Matrix3x3 translate2D = Matrix3x3::CreateIdentity();
|
||||||
|
translate2D.SetBasisZ(translateX, translateY, 1.0f);
|
||||||
|
|
||||||
|
Matrix3x3 rotate2D = Matrix3x3::CreateRotationZ(AZ::DegToRad(desc.m_rotateDegrees));
|
||||||
|
|
||||||
|
Matrix3x3 transform = translateCenter2D;
|
||||||
|
for (auto transformType : transformOrder)
|
||||||
|
{
|
||||||
|
switch (transformType)
|
||||||
|
{
|
||||||
|
case TransformType::Scale:
|
||||||
|
transform = scale2D * transform;
|
||||||
|
break;
|
||||||
|
case TransformType::Rotate:
|
||||||
|
transform = rotate2D * transform;
|
||||||
|
break;
|
||||||
|
case TransformType::Translate:
|
||||||
|
transform = translate2D * transform;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
transform = translateCenterInv2D * transform;
|
||||||
|
return transform;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue