summaryrefslogtreecommitdiff
path: root/assets/shaders/triangle.metal
blob: 60557054fe80e8302541bf7de8f0aa7add6d4038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <metal_stdlib>

using namespace metal;

struct VertexIn {
  float2 position;
  float3 color;
};

struct VertexOut {
  float4 computedPosition [[position]];
  float3 fragColor;
};

// Vertex shader
vertex VertexOut basic_vertex(
  const device VertexIn* vertex_array [[ buffer(0) ]],
  unsigned int vid [[ vertex_id ]]
  ) {
  VertexIn v = vertex_array[vid];

  VertexOut outVertex = VertexOut();
  outVertex.computedPosition = float4(v.position.xy, 0.0, 1.0);
  outVertex.fragColor = v.color;
  return outVertex;
}

// Fragment shader
fragment float4 basic_fragment(
  VertexOut interpolated [[stage_in]]
) { 
  return float4(interpolated.fragColor, 1.0);
}