diff --git a/Assets/compiled/Debug.vert.dxil b/Assets/compiled/Debug.vert.dxil index add627d..3e160f5 100644 Binary files a/Assets/compiled/Debug.vert.dxil and b/Assets/compiled/Debug.vert.dxil differ diff --git a/Assets/compiled/ImGui.frag.dxil b/Assets/compiled/ImGui.frag.dxil index d602062..5b0eb5f 100644 Binary files a/Assets/compiled/ImGui.frag.dxil and b/Assets/compiled/ImGui.frag.dxil differ diff --git a/Assets/compiled/ImGui.vert.dxil b/Assets/compiled/ImGui.vert.dxil index d980a68..b87161a 100644 Binary files a/Assets/compiled/ImGui.vert.dxil and b/Assets/compiled/ImGui.vert.dxil differ diff --git a/Assets/compiled/SolidColor.frag.dxil b/Assets/compiled/SolidColor.frag.dxil index 8920976..3ac12c8 100644 Binary files a/Assets/compiled/SolidColor.frag.dxil and b/Assets/compiled/SolidColor.frag.dxil differ diff --git a/Assets/compiled/Triangle.vert.dxil b/Assets/compiled/Triangle.vert.dxil index 49c09b1..7b20223 100644 Binary files a/Assets/compiled/Triangle.vert.dxil and b/Assets/compiled/Triangle.vert.dxil differ diff --git a/Assets/source/RootConstants.hlsl b/Assets/source/RootConstants.hlsl index e0fcf7e..9945f39 100644 --- a/Assets/source/RootConstants.hlsl +++ b/Assets/source/RootConstants.hlsl @@ -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; }; diff --git a/Assets/source/SolidColor.frag.hlsl b/Assets/source/SolidColor.frag.hlsl index a8e6d9f..cb18e2d 100644 --- a/Assets/source/SolidColor.frag.hlsl +++ b/Assets/source/SolidColor.frag.hlsl @@ -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); } diff --git a/Assets/source/Triangle.vert.hlsl b/Assets/source/Triangle.vert.hlsl index 5569b7d..664651e 100644 --- a/Assets/source/Triangle.vert.hlsl +++ b/Assets/source/Triangle.vert.hlsl @@ -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; } diff --git a/Juliet/include/Graphics/MeshRenderer.h b/Juliet/include/Graphics/MeshRenderer.h index 9ead3d3..a8df0b6 100644 --- a/Juliet/include/Graphics/MeshRenderer.h +++ b/Juliet/include/Graphics/MeshRenderer.h @@ -3,6 +3,7 @@ #include #include #include +#include #include 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, NonNullPtr device, NonNullPtr window); JULIET_API void ShutdownMeshRenderer(); diff --git a/Juliet/include/Graphics/PushConstants.h b/Juliet/include/Graphics/PushConstants.h new file mode 100644 index 0000000..37a53bd --- /dev/null +++ b/Juliet/include/Graphics/PushConstants.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include + +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 diff --git a/Juliet/src/Graphics/DebugDisplayRenderer.cpp b/Juliet/src/Graphics/DebugDisplayRenderer.cpp index ee4a5db..6484971 100644 --- a/Juliet/src/Graphics/DebugDisplayRenderer.cpp +++ b/Juliet/src/Graphics/DebugDisplayRenderer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include 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); diff --git a/Juliet/src/Graphics/MeshRenderer.cpp b/Juliet/src/Graphics/MeshRenderer.cpp index 6de922d..383c90e 100644 --- a/Juliet/src/Graphics/MeshRenderer.cpp +++ b/Juliet/src/Graphics/MeshRenderer.cpp @@ -178,6 +178,11 @@ namespace Juliet for (Mesh& mesh : g_MeshRenderer.Meshes) { pushData.Model = mesh.Transform; + pushData.TextureIndex = 0; + pushData.VertexOffset = static_cast(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(mesh.IndexCount), 1, static_cast(mesh.IndexOffset), static_cast(mesh.VertexOffset), 0); diff --git a/JulietApp/main.cpp b/JulietApp/main.cpp index 6706ca6..325ea2c 100644 --- a/JulietApp/main.cpp +++ b/JulietApp/main.cpp @@ -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); }