Add PackNormal/UnpackNormal and GetInt/SetInt to MeshAccessor

This commit is contained in:
Wojtek Figat
2025-01-12 21:22:35 +01:00
parent 344d342610
commit d751c6a6c6
5 changed files with 90 additions and 15 deletions

View File

@@ -37,6 +37,11 @@ public:
bool IsValid() const;
bool IsLinear(PixelFormat expectedFormat) const;
FORCE_INLINE int32 GetInt(int32 index) const
{
return (int32)_sampler.Read(_data.Get() + index * _stride).X;
}
FORCE_INLINE float GetFloat(int32 index) const
{
return _sampler.Read(_data.Get() + index * _stride).X;
@@ -57,7 +62,12 @@ public:
return _sampler.Read(_data.Get() + index * _stride);
}
FORCE_INLINE void SetFloat(int32 index, const float& value)
FORCE_INLINE void SetInt(int32 index, const int32 value)
{
_sampler.Write(_data.Get() + index * _stride, Float4((float)value));
}
FORCE_INLINE void SetFloat(int32 index, const float value)
{
_sampler.Write(_data.Get() + index * _stride, Float4(value));
}
@@ -182,4 +192,17 @@ public:
{
return Attribute((VertexElement::Types)((byte)VertexElement::Types::TexCoord0 + channel));
}
public:
// Unpacks normal/tangent vector from normalized range to full range.
FORCE_INLINE static void UnpackNormal(Float3& normal)
{
normal = normal * 2.0f - 1.0f;
}
// Packs normal/tangent vector to normalized range from full range.
FORCE_INLINE static void PackNormal(Float3& normal)
{
normal = normal * 0.5f + 0.5f;
}
};