Some clean up in the mesh renderer

This commit is contained in:
Patedam committed 2026-08-09 17:59:37 -04:00
1 parent 73aa4a846b
commit fb020d16e5
15 files changed
+60 -34

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+12 -10
View File
@@ -22,18 +22,20 @@ cbuffer RootConstants : register(b0, space0)
uint BufferIndex; uint BufferIndex;
uint TextureIndex; uint TextureIndex;
uint VertexOffset; // Base vertex for indexed drawing with bindless buffers uint VertexOffset; // Base vertex for indexed drawing with bindless buffers
uint _Padding; // Padding for alignment
float2 Scale; // 2D scale factor
float2 Translate; // 2D translation
float2 _Padding2; // Explicit padding to align LightDirection to 16 bytes
float3 GlobalLightDirection; // Normalized, world-space
float GlobalLightPad;
float3 GlobalLightColor;
float GlobalAmbientIntensity;
uint LightBufferIndex; uint LightBufferIndex;
uint ActiveLightCount; uint ActiveLightCount;
float GlobalAmbientIntensity;
float3 GlobalLightDirection; // Normalized, world-space
uint _Pad1;
float3 GlobalLightColor;
uint _Pad2;
float2 Scale; // 2D scale factor
float2 Translate; // 2D translation
float4 MeshAlbedo;
}; };
+1 -1
View File
@@ -27,7 +27,7 @@ Output main(uint vertexIndex : SV_VertexID)
float4 worldPos = mul(Model, float4(pos, 1.0f)); float4 worldPos = mul(Model, float4(pos, 1.0f));
output.Position = mul(ViewProjection, worldPos); output.Position = mul(ViewProjection, worldPos);
output.Color = col; output.Color = col * MeshAlbedo;
output.WorldPosition = worldPos.xyz; output.WorldPosition = worldPos.xyz;
float3 worldNormal = mul((float3x3)Model, normal); float3 worldNormal = mul((float3x3)Model, normal);
+6
View File
@@ -99,6 +99,12 @@ extern "C" JULIET_API void __cdecl GameUpdate(Juliet::GameData* params, [[maybe_
printf("Door is %s\n", door->IsOpened ? "Opened" : "Closed"); printf("Door is %s\n", door->IsOpened ? "Opened" : "Closed");
printf("Rock has %d health points\n", rock->Health); printf("Rock has %d health points\n", rock->Health);
// Summer at 2pm lighting
Vector3 sunDirection = { -0.2f, -0.9f, -0.3f };
Vector3 sunColor = { 1.0f, 0.95f, 0.85f };
float ambientIntensity = 0.4f;
SetGlobalLight(sunDirection, sunColor, ambientIntensity);
} }
GameMode previousFrameMode = gGameState->Mode; GameMode previousFrameMode = gGameState->Mode;
+1
View File
@@ -41,6 +41,7 @@ namespace Juliet
JULIET_API void SetPointLightRadius(LightID id, float radius); JULIET_API void SetPointLightRadius(LightID id, float radius);
JULIET_API void SetPointLightIntensity(LightID id, float intensity); JULIET_API void SetPointLightIntensity(LightID id, float intensity);
JULIET_API void ClearPointLights(); JULIET_API void ClearPointLights();
JULIET_API void SetGlobalLight(const Vector3& direction, const Vector3& color, float ambientIntensity);
// Assets & Instances // Assets & Instances
[[nodiscard]] JULIET_API MeshAssetID GetOrCreateMeshAsset(String name); [[nodiscard]] JULIET_API MeshAssetID GetOrCreateMeshAsset(String name);
+12 -10
View File
@@ -14,17 +14,19 @@ namespace Juliet
uint32 BufferIndex; uint32 BufferIndex;
uint32 TextureIndex; uint32 TextureIndex;
uint32 VertexOffset; uint32 VertexOffset;
uint32 Padding;
float Scale[2];
float Translate[2];
float Padding2[2];
Vector3 GlobalLightDirection;
float GlobalLightPad;
Vector3 GlobalLightColor;
float GlobalAmbientIntensity;
uint32 LightBufferIndex; uint32 LightBufferIndex;
uint32 ActiveLightCount; uint32 ActiveLightCount;
float GlobalAmbientIntensity;
Vector3 GlobalLightDirection;
uint32 Pad1;
Vector3 GlobalLightColor;
uint32 Pad2;
float Scale[2];
float Translate[2];
Vector4 MeshAlbedo;
}; };
} // namespace Juliet } // namespace Juliet
@@ -310,13 +310,11 @@ namespace Juliet
pushData.BufferIndex = bufferIndex; pushData.BufferIndex = bufferIndex;
pushData.TextureIndex = 0; pushData.TextureIndex = 0;
pushData.VertexOffset = 0; // Depth-tested vertices start at 0 pushData.VertexOffset = 0; // Depth-tested vertices start at 0
pushData.Padding = 0;
pushData.Scale[0] = 1.0f; pushData.Scale[1] = 1.0f; pushData.Scale[0] = 1.0f; pushData.Scale[1] = 1.0f;
pushData.Translate[0] = 0.0f; pushData.Translate[1] = 0.0f; pushData.Translate[0] = 0.0f; pushData.Translate[1] = 0.0f;
// Dummy light data as we don't light debug primitives // Dummy light data as we don't light debug primitives
pushData.GlobalLightDirection = {0,0,-1}; pushData.GlobalLightDirection = {0,0,-1};
pushData.GlobalLightPad = 0;
pushData.GlobalLightColor = {1,1,1}; pushData.GlobalLightColor = {1,1,1};
pushData.GlobalAmbientIntensity = 1.0f; pushData.GlobalAmbientIntensity = 1.0f;
@@ -338,13 +336,11 @@ namespace Juliet
pushData.BufferIndex = bufferIndex; pushData.BufferIndex = bufferIndex;
pushData.TextureIndex = 0; pushData.TextureIndex = 0;
pushData.VertexOffset = kMaxDebugVertices / 2; // Overlay vertices start at half pushData.VertexOffset = kMaxDebugVertices / 2; // Overlay vertices start at half
pushData.Padding = 0;
pushData.Scale[0] = 1.0f; pushData.Scale[1] = 1.0f; pushData.Scale[0] = 1.0f; pushData.Scale[1] = 1.0f;
pushData.Translate[0] = 0.0f; pushData.Translate[1] = 0.0f; pushData.Translate[0] = 0.0f; pushData.Translate[1] = 0.0f;
// Dummy light data as we don't light debug primitives // Dummy light data as we don't light debug primitives
pushData.GlobalLightDirection = {0,0,-1}; pushData.GlobalLightDirection = {0,0,-1};
pushData.GlobalLightPad = 0;
pushData.GlobalLightColor = {1,1,1}; pushData.GlobalLightColor = {1,1,1};
pushData.GlobalAmbientIntensity = 1.0f; pushData.GlobalAmbientIntensity = 1.0f;
+20 -7
View File
@@ -33,6 +33,10 @@ namespace Juliet
PointLight* MappedLights = nullptr; PointLight* MappedLights = nullptr;
Matrix* MappedTransforms = nullptr; Matrix* MappedTransforms = nullptr;
Vector3 GlobalLightDirection = { 0.0f, -1.0f, 0.0f };
Vector3 GlobalLightColor = { 0.0f, 0.0f, 0.0f };
float GlobalAmbientIntensity = 0.0f;
}; };
MeshRendererState g_MeshRenderer; MeshRendererState g_MeshRenderer;
@@ -59,6 +63,10 @@ namespace Juliet
CubePrimitiveMeshAssetID = CreateCubePrimitive(); CubePrimitiveMeshAssetID = CreateCubePrimitive();
QuadPrimitiveMeshAssetID = CreateQuadPrimitive(); QuadPrimitiveMeshAssetID = CreateQuadPrimitive();
// SpherePrimitiveMeshAssetID = CreateSpherePrimitive(); // Will implement later // SpherePrimitiveMeshAssetID = CreateSpherePrimitive(); // Will implement later
// Create default material asset (ID = 0)
MaterialAsset defaultMaterial = {};
g_MeshRenderer.MaterialAssets.PushBack(defaultMaterial);
} }
bool InitializeMeshRendererGraphics(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window) bool InitializeMeshRendererGraphics(NonNullPtr<GraphicsDevice> device, NonNullPtr<Window> window)
@@ -282,9 +290,9 @@ namespace Juliet
pushData.LightBufferIndex = lightDescriptorIndex; pushData.LightBufferIndex = lightDescriptorIndex;
pushData.TransformsBufferIndex = transformsDescriptorIndex; pushData.TransformsBufferIndex = transformsDescriptorIndex;
pushData.ActiveLightCount = static_cast<uint32>(g_MeshRenderer.PointLights.Count); pushData.ActiveLightCount = static_cast<uint32>(g_MeshRenderer.PointLights.Count);
pushData.GlobalLightDirection = { 0.0f, -1.0f, 0.0f }; pushData.GlobalLightDirection = g_MeshRenderer.GlobalLightDirection;
pushData.GlobalLightColor = { 0.0f, 0.0f, 0.0f }; pushData.GlobalLightColor = g_MeshRenderer.GlobalLightColor;
pushData.GlobalAmbientIntensity = 0.0f; pushData.GlobalAmbientIntensity = g_MeshRenderer.GlobalAmbientIntensity;
SetIndexBuffer(cmdList, g_MeshRenderer.IndexBuffer, IndexFormat::UInt16, g_MeshRenderer.Indices.Count, 0); SetIndexBuffer(cmdList, g_MeshRenderer.IndexBuffer, IndexFormat::UInt16, g_MeshRenderer.Indices.Count, 0);
@@ -297,18 +305,16 @@ namespace Juliet
} }
MeshAsset& meshAsset = g_MeshRenderer.MeshAssets.Data[instance.MeshAsset]; MeshAsset& meshAsset = g_MeshRenderer.MeshAssets.Data[instance.MeshAsset];
// If we used MaterialAsset, we would pass properties here. MaterialAsset& materialAsset = g_MeshRenderer.MaterialAssets.Data[instance.MaterialAsset];
// For now, the shader doesn't read material color, or maybe we can pass it if PushData supports it.
// pushData has GlobalLightColor, but no individual mesh color yet. We can just keep it simple.
pushData.MeshIndex = meshIndex; pushData.MeshIndex = meshIndex;
pushData.TextureIndex = 0; // Would be instance.MaterialAsset.BaseColorTexture later pushData.TextureIndex = 0; // Would be instance.MaterialAsset.BaseColorTexture later
pushData.VertexOffset = static_cast<uint32>(meshAsset.VertexOffset); pushData.VertexOffset = static_cast<uint32>(meshAsset.VertexOffset);
pushData.Padding = 0;
pushData.Scale[0] = 1.0f; pushData.Scale[0] = 1.0f;
pushData.Scale[1] = 1.0f; pushData.Scale[1] = 1.0f;
pushData.Translate[0] = 0.0f; pushData.Translate[0] = 0.0f;
pushData.Translate[1] = 0.0f; pushData.Translate[1] = 0.0f;
pushData.MeshAlbedo = materialAsset.AlbedoColor;
SetPushConstants(cmdList, ShaderStage::Vertex, 0, sizeof(pushData) / 4, &pushData); SetPushConstants(cmdList, ShaderStage::Vertex, 0, sizeof(pushData) / 4, &pushData);
DrawIndexedPrimitives(pass, static_cast<uint32>(meshAsset.IndexCount), 1, DrawIndexedPrimitives(pass, static_cast<uint32>(meshAsset.IndexCount), 1,
static_cast<uint32>(meshAsset.IndexOffset), static_cast<uint32>(meshAsset.VertexOffset), 0); static_cast<uint32>(meshAsset.IndexOffset), static_cast<uint32>(meshAsset.VertexOffset), 0);
@@ -373,6 +379,13 @@ namespace Juliet
g_MeshRenderer.PointLights.Clear(); g_MeshRenderer.PointLights.Clear();
} }
void SetGlobalLight(const Vector3& direction, const Vector3& color, float ambientIntensity)
{
g_MeshRenderer.GlobalLightDirection = direction;
g_MeshRenderer.GlobalLightColor = color;
g_MeshRenderer.GlobalAmbientIntensity = ambientIntensity;
}
MeshAssetID GetCubePrimitiveMeshAssetID() MeshAssetID GetCubePrimitiveMeshAssetID()
{ {
Assert(CubePrimitiveMeshAssetID != static_cast<MeshAssetID>(-1)); Assert(CubePrimitiveMeshAssetID != static_cast<MeshAssetID>(-1));
+1 -1
View File
@@ -175,7 +175,7 @@ if /i "!CFG!"=="Debug" (
set IMGUI_UNITY_SRCS= set IMGUI_UNITY_SRCS=
) )
set COMMON_LIBS=kernel32.lib user32.lib gdi32.lib dxguid.lib Ws2_32.lib dxgi.lib imm32.lib dwmapi.lib d3dcompiler.lib shell32.lib winhttp.lib delayimp.lib set COMMON_LIBS=kernel32.lib user32.lib gdi32.lib dxguid.lib Ws2_32.lib dxgi.lib imm32.lib dwmapi.lib d3dcompiler.lib dxcompiler.lib shell32.lib winhttp.lib delayimp.lib
if defined IMGUI_UNITY_SRCS ( if defined IMGUI_UNITY_SRCS (
echo STEP Compiling ImGui Shared Objs [!CFG!]>>"!PLAN_FILE!" echo STEP Compiling ImGui Shared Objs [!CFG!]>>"!PLAN_FILE!"
+7 -1
View File
@@ -1,7 +1,13 @@
@echo off @echo off
setlocal enabledelayedexpansion setlocal enabledelayedexpansion
set TARGET=x64-Release set TARGET=x64-Debug
if not exist "bin\%TARGET%\JulietShaderCompiler.exe" (
set TARGET=x64-Release
)
if not exist "bin\%TARGET%\JulietShaderCompiler.exe" (
set TARGET=x64-Profile
)
REM Chemin relatif vers JulietShaderCompiler.exe REM Chemin relatif vers JulietShaderCompiler.exe
set COMPILER_PATH=bin\%TARGET%\JulietShaderCompiler.exe set COMPILER_PATH=bin\%TARGET%\JulietShaderCompiler.exe