Added debug renderer + imgui renderer
All code made by gemini with some help
This commit is contained in:
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