summaryrefslogtreecommitdiffstats
path: root/third_party/rust/metal/examples/mesh-shader/shaders.metal
blob: 1a82530742813d436a7339519c48186544568f12 (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
#include <metal_stdlib>

using namespace metal;

struct VertexOut {
    float4 position [[position]];
};

using mesh_t = mesh<VertexOut, void, 3, 1, topology::triangle>;

[[mesh]] void mesh_function(mesh_t m) {
    VertexOut v;
    v.position = float4(-1.0, -1.0, 0.0, 1.0);

    m.set_primitive_count(1);

    m.set_vertex(0, v);
    v.position = float4(0.0, 1.0, 0.0, 1.0);
    m.set_vertex(1, v);
    v.position = float4(1.0, -1.0, 0.0, 1.0);
    m.set_vertex(2, v);

    m.set_index(0, 0);
    m.set_index(1, 1);
    m.set_index(2, 2);
}

fragment half4 fragment_function() {
    return half4(0.1, 1.0, 0.1, 1.0);
}