-
Notifications
You must be signed in to change notification settings - Fork 0
/
mesh_shader.metal
54 lines (41 loc) · 1.37 KB
/
mesh_shader.metal
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <metal_stdlib>
using namespace metal;
/***********************************************************************************************
* Vertex Shader
***********************************************************************************************/
struct VertexIn {
float4 position [[ attribute(0) ]];
float4 color [[ attribute(1) ]];
};
struct VertexOut {
float4 position [[ position ]];
float4 color;
};
vertex VertexOut vertex_main(VertexIn in [[ stage_in ]] ,
constant float4x4 &projectionMatrix [[ buffer(1) ]],
constant float4x4 &viewMatrix [[ buffer(2) ]]) {
VertexOut out;
out.position = in.position * projectionMatrix * viewMatrix;
out.color = in.color;
return out;
}
/*****************************************************************************************
* Fragment Shader
*****************************************************************************************/
struct FragmentIn {
float4 position [[ position ]];
float4 color;
};
struct FragmentOut {
float4 color [[color(0)]];
float depth [[depth(any)]];
};
fragment FragmentOut fragment_main(FragmentIn in [[ stage_in ]]) {
FragmentOut out;
float4 color = in.color;
float depth = in.position.z;
color.a = depth;
out.color = color;
out.depth = in.position.z;
return out;
}