project-aster/samples/02_box/shader/triangle.slang

46 lines
794 B
Plaintext

struct Vertex {
float3 point;
float3 color;
};
struct VSIn {
uint VertexIndex : SV_VertexID;
};
struct VSOut
{
float4 Pos : SV_POSITION;
float3 Color : COLOR0;
};
static const float3 points[] = {
float3(-0.5f, -0.5f, 0.5f),
float3(0.5f, -0.5f, 0.5f),
float3(0.0f, 0.5f, 0.5f),
};
static const float3 colors[] = {
float3(1.0f, 0.0f, 0.0f),
float3(0.0f, 1.0f, 0.0f),
float3(0.0f, 0.0f, 1.0f),
};
[shader("vertex")]
VSOut vsmain(VSIn input) {
VSOut output;
output.Pos = float4(points[input.VertexIndex], 1.0f);
output.Color = colors[input.VertexIndex];
return output;
}
struct FSOut {
float4 Color;
};
[shader("fragment")]
FSOut fsmain(VSOut input) {
FSOut outp;
outp.Color = float4(input.Color, 1.0);
return outp;
}