/
SDL_shaders_metal.metal
52 lines (45 loc) · 1.67 KB
1
#include <metal_texture>
2
#include <metal_matrix>
3
4
5
using namespace metal;
6
struct SolidVertexOutput
7
{
8
9
float4 position [[position]];
float pointSize [[point_size]];
10
11
};
12
13
vertex SolidVertexOutput SDL_Solid_vertex(const device float2 *position [[buffer(0)]],
constant float4x4 &projection [[buffer(2)]],
14
constant float4x4 &transform [[buffer(3)]],
15
uint vid [[vertex_id]])
16
{
17
SolidVertexOutput v;
18
v.position = (projection * transform) * float4(position[vid], 0.0f, 1.0f);
19
20
v.pointSize = 0.5f;
return v;
21
}
22
23
fragment float4 SDL_Solid_fragment(constant float4 &col [[buffer(0)]])
24
25
26
27
{
return col;
}
28
struct CopyVertexOutput
29
30
31
32
33
{
float4 position [[position]];
float2 texcoord;
};
34
35
36
vertex CopyVertexOutput SDL_Copy_vertex(const device float2 *position [[buffer(0)]],
const device float2 *texcoords [[buffer(1)]],
constant float4x4 &projection [[buffer(2)]],
37
constant float4x4 &transform [[buffer(3)]],
38
uint vid [[vertex_id]])
39
{
40
CopyVertexOutput v;
41
v.position = (projection * transform) * float4(position[vid], 0.0f, 1.0f);
42
43
v.texcoord = texcoords[vid];
return v;
44
45
}
46
47
48
49
fragment float4 SDL_Copy_fragment(CopyVertexOutput vert [[stage_in]],
constant float4 &col [[buffer(0)]],
texture2d<float> tex [[texture(0)]],
sampler s [[sampler(0)]])
50
{
51
52
return tex.sample(s, vert.texcoord) * col;
}