Skip to content

Latest commit

 

History

History
52 lines (45 loc) · 1.67 KB

SDL_shaders_metal.metal

File metadata and controls

52 lines (45 loc) · 1.67 KB
 
1
#include <metal_texture>
Dec 31, 2017
Dec 31, 2017
2
#include <metal_matrix>
3
4
5
using namespace metal;
Dec 31, 2017
Dec 31, 2017
6
struct SolidVertexOutput
Jan 1, 2018
Jan 1, 2018
8
9
float4 position [[position]];
float pointSize [[point_size]];
Dec 9, 2017
Dec 9, 2017
10
11
};
Dec 31, 2017
Dec 31, 2017
12
13
vertex SolidVertexOutput SDL_Solid_vertex(const device float2 *position [[buffer(0)]],
constant float4x4 &projection [[buffer(2)]],
Jan 3, 2018
Jan 3, 2018
14
constant float4x4 &transform [[buffer(3)]],
Dec 31, 2017
Dec 31, 2017
15
uint vid [[vertex_id]])
Dec 9, 2017
Dec 9, 2017
16
{
Dec 31, 2017
Dec 31, 2017
17
SolidVertexOutput v;
Jan 3, 2018
Jan 3, 2018
18
v.position = (projection * transform) * float4(position[vid], 0.0f, 1.0f);
Jan 1, 2018
Jan 1, 2018
19
20
v.pointSize = 0.5f;
return v;
Jan 1, 2018
Jan 1, 2018
22
Dec 9, 2017
Dec 9, 2017
23
fragment float4 SDL_Solid_fragment(constant float4 &col [[buffer(0)]])
24
25
26
27
{
return col;
}
Dec 31, 2017
Dec 31, 2017
28
struct CopyVertexOutput
29
30
31
32
33
{
float4 position [[position]];
float2 texcoord;
};
Dec 31, 2017
Dec 31, 2017
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)]],
Jan 1, 2018
Jan 1, 2018
37
constant float4x4 &transform [[buffer(3)]],
Dec 31, 2017
Dec 31, 2017
38
uint vid [[vertex_id]])
Dec 31, 2017
Dec 31, 2017
40
CopyVertexOutput v;
Jan 1, 2018
Jan 1, 2018
41
v.position = (projection * transform) * float4(position[vid], 0.0f, 1.0f);
Dec 9, 2017
Dec 9, 2017
42
43
v.texcoord = texcoords[vid];
return v;
Jan 1, 2018
Jan 1, 2018
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)]])
Dec 9, 2017
Dec 9, 2017
51
52
return tex.sample(s, vert.texcoord) * col;
}