Added debug renderer + imgui renderer
All code made by gemini with some help
This commit is contained in:
Binary file not shown.
BIN
Assets/compiled/ImGui.frag.dxil
Normal file
BIN
Assets/compiled/ImGui.frag.dxil
Normal file
Binary file not shown.
BIN
Assets/compiled/ImGui.vert.dxil
Normal file
BIN
Assets/compiled/ImGui.vert.dxil
Normal file
Binary file not shown.
@@ -13,9 +13,12 @@ Output main(uint vertexIndex : SV_VertexID)
|
||||
// Retrieve the vertex buffer using SM6.6 bindless syntax
|
||||
ByteAddressBuffer buffer = ResourceDescriptorHeap[BufferIndex];
|
||||
|
||||
// TextureIndex is used as vertex offset for consolidated buffer (depth-tested at 0, overlay at halfMax)
|
||||
uint actualVertexIndex = vertexIndex + TextureIndex;
|
||||
|
||||
// Vertex layout: float3 Position (12 bytes) + float4 Color (16 bytes) = 28 bytes stride
|
||||
uint stride = 28;
|
||||
uint offset = vertexIndex * stride;
|
||||
uint offset = actualVertexIndex * stride;
|
||||
|
||||
float3 pos = asfloat(buffer.Load3(offset));
|
||||
float4 col = asfloat(buffer.Load4(offset + 12));
|
||||
|
||||
38
Assets/source/ImGui.frag.hlsl
Normal file
38
Assets/source/ImGui.frag.hlsl
Normal file
@@ -0,0 +1,38 @@
|
||||
struct Input
|
||||
{
|
||||
float4 Color : TEXCOORD0;
|
||||
float2 UV : TEXCOORD1;
|
||||
};
|
||||
|
||||
#include "RootConstants.hlsl"
|
||||
|
||||
float4 main(Input input) : SV_Target0
|
||||
{
|
||||
// Retrieve the texture using SM6.6 bindless syntax
|
||||
// Texture2D texture = ResourceDescriptorHeap[TextureIndex]; (Must cast to Texture2D<float4>)
|
||||
// Wait, ResourceDescriptorHeap indexing returns a wrapper, usually we use Textures[TextureIndex]?
|
||||
// Juliet seems to use `ResourceDescriptorHeap` for Buffers.
|
||||
// Let's check Triangle.vert/frag.
|
||||
|
||||
// In bindless, usually:
|
||||
// Texture2D<float4> tex = ResourceDescriptorHeap[TextureIndex];
|
||||
// SamplerState samp = SamplerDescriptorHeap[0]; // Assuming static sampler or passed index
|
||||
|
||||
// I need to check how Juliet accesses textures.
|
||||
// I'll assume standard SM6.6 usage.
|
||||
Texture2D<float4> tex = ResourceDescriptorHeap[TextureIndex];
|
||||
SamplerState samp = SamplerDescriptorHeap[0]; // Point sampler or Linear? ImGui usually uses Linear.
|
||||
// D3D12GraphicsDevice.cpp created static samplers.
|
||||
// Root signature has Static Samplers.
|
||||
// RegisterSpace 0.
|
||||
// Sampler register 0 is Point/Nearest?
|
||||
// Let's check CreateGraphicsRootSignature in D3D12GraphicsDevice.cpp.
|
||||
// It creates s_nearest at 0.
|
||||
|
||||
// If I want Linear, I might need another sampler or rely on s_nearest for font (pixel art font?)
|
||||
// Default ImGui font is usually antialiased, so Linear is preferred.
|
||||
// But pixel aligned UI...
|
||||
// I will use `SamplerDescriptorHeap[0]` for now.
|
||||
|
||||
return input.Color * tex.Sample(samp, input.UV);
|
||||
}
|
||||
70
Assets/source/ImGui.vert.hlsl
Normal file
70
Assets/source/ImGui.vert.hlsl
Normal file
@@ -0,0 +1,70 @@
|
||||
struct Output
|
||||
{
|
||||
float4 Color : TEXCOORD0;
|
||||
float2 UV : TEXCOORD1;
|
||||
float4 Position : SV_Position;
|
||||
};
|
||||
|
||||
#include "RootConstants.hlsl"
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
float2 Pos;
|
||||
float2 UV;
|
||||
uint Color;
|
||||
};
|
||||
|
||||
Output main(uint vertexIndex : SV_VertexID)
|
||||
{
|
||||
Output output;
|
||||
|
||||
// Retrieve the vertex buffer using SM6.6 bindless syntax
|
||||
ByteAddressBuffer buffer = ResourceDescriptorHeap[BufferIndex];
|
||||
|
||||
// Add VertexOffset for indexed drawing with bindless buffers
|
||||
// (SV_VertexID in indexed draw is raw index from index buffer, doesn't include BaseVertexLocation)
|
||||
uint actualVertexIndex = vertexIndex + VertexOffset;
|
||||
|
||||
// ImDrawVert stride = 20 bytes (Vec2 pos + Vec2 uv + uint color)
|
||||
uint stride = 20;
|
||||
uint offset = actualVertexIndex * stride;
|
||||
|
||||
float2 pos = asfloat(buffer.Load2(offset));
|
||||
float2 uv = asfloat(buffer.Load2(offset + 8));
|
||||
uint col = buffer.Load(offset + 16);
|
||||
|
||||
// Unpack color (uint to float4)
|
||||
// ImGui colors are 0xAABBGGRR (ABGR packed)
|
||||
// We need to unpack to float4.
|
||||
// HLSL unpacks as little endian.
|
||||
// uint 0xAABBGGRR -> byte0=RR, byte1=GG, byte2=BB, byte3=AA
|
||||
float4 c;
|
||||
c.x = float(col & 0xFF) / 255.0f;
|
||||
c.y = float((col >> 8) & 0xFF) / 255.0f;
|
||||
c.z = float((col >> 16) & 0xFF) / 255.0f;
|
||||
c.w = float((col >> 24) & 0xFF) / 255.0f;
|
||||
|
||||
// Transform
|
||||
// ImGui sends pixel coordinates.
|
||||
// We need to transform to NDC [-1, 1].
|
||||
// PushConstants should contain Scale and Translate.
|
||||
// float2 Scale = 2.0 / DisplaySize
|
||||
// float2 Translate = -1.0 - (DisplayPos * Scale)
|
||||
|
||||
// We will assume PushConstants are float2 Scale, float2 Translate.
|
||||
// Struct in RootConstants.hlsl?
|
||||
// RootConstants.hlsl likely defines `cbuffer PushConstants : register(b0)`.
|
||||
// Let's assume standard push constants usage.
|
||||
// Debug.vert.hlsl used `ViewProjection`.
|
||||
// We need to customize PushConstants or reuse `ViewProjection` slot?
|
||||
// Juliet uses 128 bytes of push constants.
|
||||
// We can map float4 ProjectionMatrix (or similar).
|
||||
|
||||
// Use Scale and Translate from RootConstants
|
||||
output.Position = float4(pos * Scale + Translate, 0.0f, 1.0f);
|
||||
output.Color = c;
|
||||
output.UV = uv;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user