Skip to content

Latest commit

 

History

History
59 lines (50 loc) · 1.9 KB

SDL_shaders_metal.metal

File metadata and controls

59 lines (50 loc) · 1.9 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
Dec 9, 2017
Dec 9, 2017
8
9
10
11
float4 position [[position]];
float pointSize [[point_size]];
};
Dec 31, 2017
Dec 31, 2017
12
13
14
vertex SolidVertexOutput SDL_Solid_vertex(const device float2 *position [[buffer(0)]],
constant float4x4 &projection [[buffer(2)]],
uint vid [[vertex_id]])
Dec 9, 2017
Dec 9, 2017
15
{
Dec 31, 2017
Dec 31, 2017
16
17
SolidVertexOutput v;
v.position = projection * float4(position[vid].x, position[vid].y, 0.0f, 1.0f);
Dec 9, 2017
Dec 9, 2017
18
19
v.pointSize = 0.5f;
return v;
Dec 9, 2017
Dec 9, 2017
22
fragment float4 SDL_Solid_fragment(constant float4 &col [[buffer(0)]])
23
24
25
26
{
return col;
}
Dec 31, 2017
Dec 31, 2017
27
struct CopyVertexOutput
28
29
30
31
32
{
float4 position [[position]];
float2 texcoord;
};
Dec 31, 2017
Dec 31, 2017
33
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)]],
uint vid [[vertex_id]])
Dec 31, 2017
Dec 31, 2017
38
39
CopyVertexOutput v;
v.position = projection * float4(position[vid].x, position[vid].y, 0.0f, 1.0f);
Dec 9, 2017
Dec 9, 2017
40
41
v.texcoord = texcoords[vid];
return v;
Dec 31, 2017
Dec 31, 2017
44
45
46
fragment float4 SDL_Copy_fragment_nearest(CopyVertexOutput vert [[stage_in]],
constant float4 &col [[buffer(0)]],
texture2d<float> tex [[texture(0)]])
Dec 10, 2017
Dec 10, 2017
48
constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::nearest);
Dec 9, 2017
Dec 9, 2017
49
50
51
return tex.sample(s, vert.texcoord) * col;
}
Dec 31, 2017
Dec 31, 2017
52
53
54
fragment float4 SDL_Copy_fragment_linear(CopyVertexOutput vert [[stage_in]],
constant float4 &col [[buffer(0)]],
texture2d<float> tex [[texture(0)]])
Dec 9, 2017
Dec 9, 2017
55
{
Dec 10, 2017
Dec 10, 2017
56
constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::linear);
Dec 9, 2017
Dec 9, 2017
57
return tex.sample(s, vert.texcoord) * col;