Plasma Engine  2.0
Loading...
Searching...
No Matches
MeshRendererUtils.h
1#pragma once
2
3#include <RendererCore/Meshes/MeshComponentBase.h>
4
5#include <RendererCore/../../../Data/Base/Shaders/Common/ObjectConstants.h>
6
7namespace plInternal
8{
9 PL_FORCE_INLINE void FillPerInstanceData(plPerInstanceData& ref_perInstanceData, const plMeshRenderData* pRenderData)
10 {
11 plMat4 objectToWorld = pRenderData->m_GlobalTransform.GetAsMat4();
12
13 ref_perInstanceData.ObjectToWorld = objectToWorld;
14
15#if PL_ENABLED(PL_GAMEOBJECT_VELOCITY)
16 plMat4 lastObjectToWorld = pRenderData->m_LastGlobalTransform.GetAsMat4();
17 ref_perInstanceData.LastObjectToWorld = lastObjectToWorld;
18#endif
19
20 if (pRenderData->m_uiUniformScale)
21 {
22 ref_perInstanceData.ObjectToWorldNormal = objectToWorld;
23#if PL_ENABLED(PL_GAMEOBJECT_VELOCITY)
24 ref_perInstanceData.LastObjectToWorldNormal = lastObjectToWorld;
25#endif
26 }
27 else
28 {
29 plMat3 mInverse = objectToWorld.GetRotationalPart();
30 mInverse.Invert(0.0f).IgnoreResult();
31 // we explicitly ignore the return value here (success / failure)
32 // because when we have a scale of 0 (which happens temporarily during editing) that would be annoying
33
34 plShaderTransform shaderT;
35 shaderT = mInverse.GetTranspose();
36 ref_perInstanceData.ObjectToWorldNormal = shaderT;
37
38#if PL_ENABLED(PL_GAMEOBJECT_VELOCITY)
39 mInverse = lastObjectToWorld.GetRotationalPart();
40 mInverse.Invert(0.0f).IgnoreResult();
41 // we explicitly ignore the return value here (success / failure)
42 // because when we have a scale of 0 (which happens temporarily during editing) that would be annoying
43
44 shaderT = mInverse.GetTranspose();
45 ref_perInstanceData.LastObjectToWorldNormal = shaderT;
46#endif
47 }
48
49 ref_perInstanceData.BoundingSphereRadius = pRenderData->m_GlobalBounds.m_fSphereRadius;
50 ref_perInstanceData.GameObjectID = pRenderData->m_uiUniqueID;
51 ref_perInstanceData.VertexColorAccessData = 0;
52 ref_perInstanceData.Color = pRenderData->m_Color;
53 }
54} // namespace plInternal
plResult Invert(Type fEpsilon=plMath::SmallEpsilon< Type >())
Inverts this matrix. Return value indicates whether the matrix could be Inverted.
Definition AllClasses_inl.h:230
const plMat3Template< Type > GetTranspose() const
Returns the transpose of this matrix.
Definition Mat3_inl.h:164
const plMat3Template< Type > GetRotationalPart() const
Returns the 3x3 rotational and scaling part of the matrix.
Definition Mat4_inl.h:458
Definition MeshComponentBase.h:13
A wrapper class that converts a plTransform into the correct data layout for shaders.
Definition Types.h:35
const plMat4Template< Type > GetAsMat4() const
Returns the transformation as a matrix.
Definition Transform_inl.h:111
PL_ALWAYS_INLINE void IgnoreResult()
Used to silence compiler warnings, when success or failure doesn't matter.
Definition Types.h:69