Now using vertex pulling with mesh buffers

This commit is contained in:
antopilo
2024-12-08 00:30:33 -05:00
parent 29130dde7f
commit dfc5b6fa69
7 changed files with 174 additions and 64 deletions

View File

@@ -1,30 +1,39 @@
// HLSL version for Shader Model 6.1
struct Vertex
{
float3 position;
float uv_x;
float3 normal;
float uv_y;
float4 color;
};
// Define the structured buffer for vertices
StructuredBuffer<Vertex> vertexBuffer : register(t0); // Binding of vertex buffer (example: t0)
// Define push constants block
cbuffer PushConstants : register(b0) { // Push constants binding (example: b0)
float4x4 render_matrix; // Matrix for rendering
uint64_t vertexBufferAddress; // Buffer reference address (Vulkan-specific handling required)
};
// Outputs
struct VSOutput {
float4 Position : SV_Position;
float3 Color : TEXCOORD0;
float2 UV : TEXCOORD1;
};
VSOutput main(uint vertexIndex : SV_VertexID)
{
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID) {
VSOutput output;
// Constant array of positions for the triangle
float3 positions[3] = {
float3(1.0f, 1.0f, 0.0f),
float3(-1.0f, 1.0f, 0.0f),
float3(0.0f, -1.0f, 0.0f)
};
// Load vertex data from the buffer
Vertex v = vertexBuffer[vertexIndex];
// Constant array of colors for the triangle
float3 colors[3] = {
float3(1.0f, 0.0f, 0.0f), // red
float3(0.0f, 1.0f, 0.0f), // green
float3(0.0f, 0.0f, 1.0f) // blue
};
// Output the position of each vertex
output.Position = float4(positions[vertexIndex], 1.0f);
output.Color = colors[vertexIndex];
// Transform and output vertex data
output.Position = mul(render_matrix, float4(v.position, 1.0f));
output.Color = v.color.xyz;
output.UV = float2(v.uv_x, v.uv_y);
return output;
}