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
#include <metal_stdlib>
using namespace metal;
constant int NUM_LIGHTS [[function_constant(0)]];
constant float BRIGHTNESS [[function_constant(1)]];
constant bool USE_GAMMA [[function_constant(2)]];
struct Uniforms {
float3 base_color;
float ambient;
};
struct _vs_main_Input {
float3 position [[attribute(0)]];
};
struct VertexOutput {
float4 position [[position]];
};
struct _fs_main_Input {
float4 frag_coord [[user(locn0)]];
};
struct _fs_main_Output {
float4 color [[user(locn0)]];
};
vertex VertexOutput vs_main(_vs_main_Input input [[stage_in]]) {
VertexOutput __luma_output;
__luma_output.position = float4(input.position, 1.0);
return __luma_output;
}
fragment _fs_main_Output fs_main(_fs_main_Input input [[stage_in]],
constant Uniforms& uniforms [[buffer(0)]]) {
_fs_main_Output __luma_output;
float3 color = (uniforms.base_color * uniforms.ambient);
int i = 0;
while ((i < NUM_LIGHTS)) {
color = (color + float3(0.1, 0.1, 0.1));
i = (i + 1);
}
color = (color * BRIGHTNESS);
__luma_output.color = float4(color, 1.0);
return __luma_output;
}