Add "View Size" node for GUI materials

This commit is contained in:
2022-05-21 22:51:44 +03:00
parent 4967b27ff7
commit b89e3bb0ff
6 changed files with 50 additions and 4 deletions

View File

@@ -114,6 +114,8 @@ struct Render2DDrawCall
struct
{
MaterialBase* Mat;
float Width;
float Height;
} AsMaterial;
struct
@@ -984,7 +986,10 @@ void DrawBatch(int32 startIndex, int32 count)
// Apply and bind material
auto material = d.AsChar.Mat;
MaterialBase::BindParameters bindParams(Context, *(RenderContext*)nullptr);
bindParams.CustomData = &ViewProjection;
Render2D::CustomData customData;
customData.ViewProjection = ViewProjection;
customData.ViewSize = Float2(d.AsMaterial.Width, d.AsMaterial.Height);
bindParams.CustomData = &customData;
material->Bind(bindParams);
// Bind font atlas as a material parameter
@@ -1017,7 +1022,10 @@ void DrawBatch(int32 startIndex, int32 count)
// Bind material
auto material = (MaterialBase*)d.AsMaterial.Mat;
MaterialBase::BindParameters bindParams(Context, *(RenderContext*)nullptr);
bindParams.CustomData = &ViewProjection;
Render2D::CustomData customData;
customData.ViewProjection = ViewProjection;
customData.ViewSize = Float2(d.AsMaterial.Width, d.AsMaterial.Height);
bindParams.CustomData = &customData;
material->Bind(bindParams);
// Bind index and vertex buffers
@@ -1892,6 +1900,8 @@ void Render2D::DrawMaterial(MaterialBase* material, const Rectangle& rect, const
drawCall.StartIB = IBIndex;
drawCall.CountIB = 6;
drawCall.AsMaterial.Mat = material;
drawCall.AsMaterial.Width = rect.GetWidth();
drawCall.AsMaterial.Height = rect.GetHeight();
WriteRect(rect, color);
}

View File

@@ -5,6 +5,8 @@
#include "Engine/Core/Math/Color.h"
#include "Engine/Scripting/ScriptingType.h"
#include "Engine/Core/Types/Span.h"
#include "Engine/Core/Math/Vector2.h"
#include "Engine/Core/Math/Matrix.h"
struct SpriteHandle;
struct TextLayoutOptions;
@@ -44,6 +46,13 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Render2D);
VertexSnapping = 1,
};
public:
struct CustomData
{
Matrix ViewProjection;
Float2 ViewSize;
};
public:
/// <summary>