Factorized Push Data
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -11,6 +11,11 @@ cbuffer RootConstants : register(b0, space0)
|
||||
uint _Padding; // Padding for alignment
|
||||
float2 Scale; // 2D scale factor
|
||||
float2 Translate; // 2D translation
|
||||
|
||||
float3 LightDirection; // Normalized, world-space
|
||||
float LightPad;
|
||||
float3 LightColor;
|
||||
float AmbientIntensity;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
float4 main(float4 Color : TEXCOORD0) : SV_Target0
|
||||
#include "RootConstants.hlsl"
|
||||
|
||||
float4 main(float4 Color : TEXCOORD0, float3 WorldNormal : TEXCOORD1) : SV_Target0
|
||||
{
|
||||
return Color;
|
||||
float3 N = normalize(WorldNormal);
|
||||
float NdotL = saturate(dot(N, -LightDirection));
|
||||
float3 diffuse = Color.rgb * LightColor * NdotL;
|
||||
float3 ambient = Color.rgb * AmbientIntensity;
|
||||
return float4(diffuse + ambient, Color.a);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
struct Output
|
||||
{
|
||||
float4 Color : TEXCOORD0;
|
||||
float3 Normal : TEXCOORD1;
|
||||
float3 WorldNormal : TEXCOORD1;
|
||||
float4 Position : SV_Position;
|
||||
};
|
||||
|
||||
@@ -20,9 +20,10 @@ Output main(uint vertexIndex : SV_VertexID)
|
||||
float3 normal = asfloat(buffer.Load3(offset + 12));
|
||||
float4 col = asfloat(buffer.Load4(offset + 24));
|
||||
|
||||
//output.Position = float4(pos, 1.0f);
|
||||
output.Position = mul(ViewProjection, mul(Model, float4(pos, 1.0f)));
|
||||
output.Color = col;
|
||||
output.Normal = normal;
|
||||
|
||||
float3 worldNormal = mul((float3x3)Model, normal);
|
||||
output.WorldNormal = worldNormal;
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <Core/Container/Vector.h>
|
||||
#include <Core/Math/Matrix.h>
|
||||
#include <Graphics/VertexData.h>
|
||||
#include <Graphics/PushConstants.h>
|
||||
#include <Juliet.h>
|
||||
|
||||
namespace Juliet
|
||||
@@ -40,13 +41,6 @@ namespace Juliet
|
||||
GraphicsPipeline* Pipeline;
|
||||
};
|
||||
|
||||
struct PushData
|
||||
{
|
||||
Matrix ViewProjection;
|
||||
Matrix Model;
|
||||
uint32 BufferIndex;
|
||||
};
|
||||
|
||||
[[nodiscard]] JULIET_API bool InitializeMeshRenderer(NonNullPtr<Arena> arena, NonNullPtr<GraphicsDevice> device,
|
||||
NonNullPtr<Window> window);
|
||||
JULIET_API void ShutdownMeshRenderer();
|
||||
|
||||
25
Juliet/include/Graphics/PushConstants.h
Normal file
25
Juliet/include/Graphics/PushConstants.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <Core/Math/Matrix.h>
|
||||
#include <Core/Math/Vector.h>
|
||||
#include <Juliet.h>
|
||||
|
||||
namespace Juliet
|
||||
{
|
||||
struct PushData
|
||||
{
|
||||
Matrix ViewProjection;
|
||||
Matrix Model;
|
||||
uint32 BufferIndex;
|
||||
uint32 TextureIndex;
|
||||
uint32 VertexOffset;
|
||||
uint32 Padding;
|
||||
float Scale[2];
|
||||
float Translate[2];
|
||||
|
||||
Vector3 LightDirection;
|
||||
float LightPad;
|
||||
Vector3 LightColor;
|
||||
float AmbientIntensity;
|
||||
};
|
||||
} // namespace Juliet
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <Core/HAL/Filesystem/Filesystem.h>
|
||||
#include <Core/Memory/Allocator.h>
|
||||
#include <Graphics/GraphicsPipeline.h>
|
||||
#include <Graphics/PushConstants.h>
|
||||
|
||||
namespace Juliet
|
||||
{
|
||||
@@ -302,18 +303,22 @@ namespace Juliet
|
||||
BindGraphicsPipeline(renderPass, g_DebugState.DepthTestedPipeline);
|
||||
|
||||
// Pack VP matrix + Model (identity for debug) + buffer index into push constants
|
||||
struct
|
||||
{
|
||||
Matrix vp;
|
||||
Matrix model;
|
||||
uint32 bufferIndex;
|
||||
uint32 vertexOffset; // Offset in vertices (not bytes)
|
||||
uint32 padding[2];
|
||||
} pushData;
|
||||
pushData.vp = Camera_GetViewProjectionMatrix(camera);
|
||||
pushData.model = MatrixIdentity();
|
||||
pushData.bufferIndex = bufferIndex;
|
||||
pushData.vertexOffset = 0; // Depth-tested vertices start at 0
|
||||
PushData pushData = {};
|
||||
pushData.ViewProjection = Camera_GetViewProjectionMatrix(camera);
|
||||
pushData.Model = MatrixIdentity();
|
||||
pushData.BufferIndex = bufferIndex;
|
||||
pushData.TextureIndex = 0;
|
||||
pushData.VertexOffset = 0; // Depth-tested vertices start at 0
|
||||
pushData.Padding = 0;
|
||||
pushData.Scale[0] = 1.0f; pushData.Scale[1] = 1.0f;
|
||||
pushData.Translate[0] = 0.0f; pushData.Translate[1] = 0.0f;
|
||||
|
||||
// Dummy light data as we don't light debug primitives
|
||||
pushData.LightDirection = {0,0,-1};
|
||||
pushData.LightPad = 0;
|
||||
pushData.LightColor = {1,1,1};
|
||||
pushData.AmbientIntensity = 1.0f;
|
||||
|
||||
SetPushConstants(cmdList, ShaderStage::Vertex, 0, sizeof(pushData) / sizeof(uint32), &pushData);
|
||||
|
||||
DrawPrimitives(renderPass, g_DebugState.DepthTestedVertexCount, 1, 0, 0);
|
||||
@@ -325,18 +330,22 @@ namespace Juliet
|
||||
BindGraphicsPipeline(renderPass, g_DebugState.OverlayPipeline);
|
||||
|
||||
// Pack VP matrix + Model (identity for debug) + buffer index into push constants
|
||||
struct
|
||||
{
|
||||
Matrix vp;
|
||||
Matrix model;
|
||||
uint32 bufferIndex;
|
||||
uint32 vertexOffset; // Offset in vertices (not bytes)
|
||||
uint32 padding[2];
|
||||
} pushData;
|
||||
pushData.vp = Camera_GetViewProjectionMatrix(camera);
|
||||
pushData.model = MatrixIdentity();
|
||||
pushData.bufferIndex = bufferIndex;
|
||||
pushData.vertexOffset = kMaxDebugVertices / 2; // Overlay vertices start at half
|
||||
PushData pushData = {};
|
||||
pushData.ViewProjection = Camera_GetViewProjectionMatrix(camera);
|
||||
pushData.Model = MatrixIdentity();
|
||||
pushData.BufferIndex = bufferIndex;
|
||||
pushData.TextureIndex = 0;
|
||||
pushData.VertexOffset = kMaxDebugVertices / 2; // Overlay vertices start at half
|
||||
pushData.Padding = 0;
|
||||
pushData.Scale[0] = 1.0f; pushData.Scale[1] = 1.0f;
|
||||
pushData.Translate[0] = 0.0f; pushData.Translate[1] = 0.0f;
|
||||
|
||||
// Dummy light data as we don't light debug primitives
|
||||
pushData.LightDirection = {0,0,-1};
|
||||
pushData.LightPad = 0;
|
||||
pushData.LightColor = {1,1,1};
|
||||
pushData.AmbientIntensity = 1.0f;
|
||||
|
||||
SetPushConstants(cmdList, ShaderStage::Vertex, 0, sizeof(pushData) / sizeof(uint32), &pushData);
|
||||
|
||||
DrawPrimitives(renderPass, g_DebugState.OverlayVertexCount, 1, 0, 0);
|
||||
|
||||
@@ -178,6 +178,11 @@ namespace Juliet
|
||||
for (Mesh& mesh : g_MeshRenderer.Meshes)
|
||||
{
|
||||
pushData.Model = mesh.Transform;
|
||||
pushData.TextureIndex = 0;
|
||||
pushData.VertexOffset = static_cast<uint32>(mesh.VertexOffset);
|
||||
pushData.Padding = 0;
|
||||
pushData.Scale[0] = 1.0f; pushData.Scale[1] = 1.0f;
|
||||
pushData.Translate[0] = 0.0f; pushData.Translate[1] = 0.0f;
|
||||
SetPushConstants(cmdList, ShaderStage::Vertex, 0, sizeof(pushData) / 4, &pushData);
|
||||
DrawIndexedPrimitives(pass, static_cast<uint32>(mesh.IndexCount), 1, static_cast<uint32>(mesh.IndexOffset),
|
||||
static_cast<uint32>(mesh.VertexOffset), 0);
|
||||
|
||||
@@ -320,6 +320,10 @@ void JulietApplication::OnRender(RenderPass* pass, CommandList* cmd)
|
||||
PushData pushData = {};
|
||||
pushData.ViewProjection = Camera_GetViewProjectionMatrix(GetDebugCamera());
|
||||
|
||||
pushData.LightDirection = Normalize({ 0.5f, -1.0f, -0.5f });
|
||||
pushData.LightColor = { 1.0f, 0.95f, 0.8f };
|
||||
pushData.AmbientIntensity = 0.2f;
|
||||
|
||||
RenderMeshes(pass, cmd, pushData);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user