metal-examples-tutorials/ch09/chapter09.playground/Resources/Shaders.metal

26 lines
601 B
Metal
Executable File

#include <metal_stdlib>
using namespace metal;
struct Vertex {
float4 position [[position]];
float4 color;
};
struct Uniforms {
float4x4 modelViewProjectionMatrix;
};
vertex Vertex vertex_func(constant Vertex *vertices [[buffer(0)]], constant Uniforms &uniforms [[buffer(1)]], uint vid [[vertex_id]]) {
float4x4 matrix = uniforms.modelViewProjectionMatrix;
Vertex in = vertices[vid];
Vertex out;
out.position = matrix * float4(in.position);
out.color = in.color;
return out;
}
fragment float4 fragment_func(Vertex vert [[stage_in]]) {
return vert.color;
}