Files
sophia/sandbox/shaders/triangle.vert
T
2026-10-07 11:51:14 -07:00

46 lines
992 B
GLSL

#version 450
#extension GL_EXT_buffer_reference : require
struct TriangleVertex {
vec4 vertex;
vec4 color;
};
layout(buffer_reference, std430) readonly buffer TriangleVertexBuffer {
TriangleVertex vertices[];
};
layout( push_constant ) uniform constants {
TriangleVertexBuffer triangleBuffer;
vec2 padding;
vec4 data1;
vec4 data2;
vec4 data3;
} PushConstants;
layout (location = 0) out vec3 outColor;
void main()
{
//const array of positions for the triangle
const vec3 positions[3] = vec3[3](
vec3(-1.f,1.f, 0.0f),
vec3(1.f,1.f, 0.0f),
vec3(0.f,-1.f, 0.0f)
);
//const array of colors for the triangle
const vec3 colors[3] = vec3[3](
vec3(1.0f, 0.0f, 0.0f), //red
vec3(0.0f, 1.0f, 0.0f), //green
vec3(00.f, 0.0f, 1.0f) //blue
);
// Load vertex data from device address
TriangleVertex v = PushConstants.triangleBuffer.vertices[gl_VertexIndex];
// output the position of each vertex
gl_Position = vec4(v.vertex.xyz, 1.0);
outColor = vec3(v.color.xyz);
}