Skip to content

Latest commit

 

History

History
49 lines (40 loc) · 1.35 KB

SDL_shaders_metal.metal

File metadata and controls

49 lines (40 loc) · 1.35 KB
 
1
2
3
4
#include <metal_texture>
using namespace metal;
Dec 9, 2017
Dec 9, 2017
5
struct SolidVertex
Dec 9, 2017
Dec 9, 2017
7
8
9
10
11
12
13
14
15
16
float4 position [[position]];
float pointSize [[point_size]];
};
vertex SolidVertex SDL_Solid_vertex(constant float2 *position [[buffer(0)]], uint vid [[vertex_id]])
{
SolidVertex v;
v.position = float4(position[vid].x, position[vid].y, 0.0f, 1.0f);
v.pointSize = 0.5f;
return v;
Dec 9, 2017
Dec 9, 2017
19
fragment float4 SDL_Solid_fragment(constant float4 &col [[buffer(0)]])
20
21
22
23
24
25
26
27
28
29
30
31
{
return col;
}
struct CopyVertex
{
float4 position [[position]];
float2 texcoord;
};
vertex CopyVertex SDL_Copy_vertex(constant float2 *position [[buffer(0)]], constant float2 *texcoords [[buffer(1)]], uint vid [[vertex_id]])
{
Dec 9, 2017
Dec 9, 2017
32
33
34
35
CopyVertex v;
v.position = float4(position[vid].x, position[vid].y, 0.0f, 1.0f);
v.texcoord = texcoords[vid];
return v;
Dec 9, 2017
Dec 9, 2017
38
fragment float4 SDL_Copy_fragment_nearest(CopyVertex vert [[stage_in]], constant float4 &col [[buffer(0)]], texture2d<float> tex [[texture(0)]])
Dec 10, 2017
Dec 10, 2017
40
constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::nearest);
Dec 9, 2017
Dec 9, 2017
41
42
43
44
45
return tex.sample(s, vert.texcoord) * col;
}
fragment float4 SDL_Copy_fragment_linear(CopyVertex vert [[stage_in]], constant float4 &col [[buffer(0)]], texture2d<float> tex [[texture(0)]])
{
Dec 10, 2017
Dec 10, 2017
46
constexpr sampler s(coord::normalized, address::clamp_to_edge, filter::linear);
Dec 9, 2017
Dec 9, 2017
47
return tex.sample(s, vert.texcoord) * col;