Triangle in render texture

This commit is contained in:
antopilo
2024-12-07 21:48:59 -05:00
parent cd2e603733
commit 29130dde7f
15 changed files with 554 additions and 21 deletions

View File

@@ -0,0 +1,28 @@
struct VSInput
{
[[vk::location(0)]] float3 Position : POSITION0;
[[vk::location(1)]] float3 Color : COLOR0;
};
struct UBO
{
float4x4 projectionMatrix;
float4x4 modelMatrix;
float4x4 viewMatrix;
};
cbuffer ubo : register(b0, space0) { UBO ubo; }
struct VSOutput
{
float4 Pos : SV_POSITION;
[[vk::location(0)]] float3 Color : COLOR0;
};
VSOutput main(VSInput input, uint VertexIndex : SV_VertexID)
{
VSOutput output = (VSOutput)0;
output.Color = input.Color * float(VertexIndex);
output.Pos = mul(ubo.projectionMatrix, mul(ubo.viewMatrix, mul(ubo.modelMatrix, float4(input.Position.xyz, 1.0))));
return output;
}

View File

@@ -0,0 +1,9 @@
struct PSInput {
float3 Color : TEXCOORD0;
};
float4 main(PSInput input) : SV_Target
{
// Return color with alpha = 1.0f
return float4(input.Color, 1.0f);
}

View File

@@ -0,0 +1,30 @@
// HLSL version for Shader Model 6.1
struct VSOutput {
float4 Position : SV_Position;
float3 Color : TEXCOORD0;
};
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)
};
// 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];
return output;
}

View File

@@ -0,0 +1,39 @@
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;
};
// Main vertex shader
VSOutput main(uint vertexIndex : SV_VertexID) {
VSOutput output;
// Load vertex data from the buffer
Vertex v = vertexBuffer[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;
}