RetroArch/gfx/common/metal/Shaders.metal
Stuart Carnie 411bcf8bdd feat(apple): Metal support for macOS
* includes rgui
* shader support

This is a work-in-progress and there are some bugs and visual artifacts
still to be fixed.
2018-06-20 21:33:45 -07:00

56 lines
1.8 KiB
Metal

//
// Shaders.metal
// MetalRenderer
//
// Created by Stuart Carnie on 5/31/18.
// Copyright © 2018 Stuart Carnie. All rights reserved.
//
// File for Metal kernel and shader functions
#include <metal_stdlib>
#include <simd/simd.h>
// Including header shared between this Metal shader code and Swift/C code executing Metal API commands
#import "ShaderTypes.h"
using namespace metal;
#pragma mark - functions using projected coordinates
vertex ColorInOut basic_vertex_proj_tex(const Vertex in [[ stage_in ]],
const device Uniforms &uniforms [[ buffer(BufferIndexUniforms) ]])
{
ColorInOut out;
out.position = uniforms.projectionMatrix * float4(in.position, 1.0);
out.texCoord = in.texCoord;
return out;
}
fragment float4 basic_fragment_proj_tex(ColorInOut in [[stage_in]],
constant Uniforms & uniforms [[ buffer(BufferIndexUniforms) ]],
texture2d<half> tex [[ texture(TextureIndexColor) ]],
sampler samp [[ sampler(SamplerIndexDraw) ]])
{
half4 colorSample = tex.sample(samp, in.texCoord.xy);
return float4(colorSample);
}
#pragma mark - functions using normalized device coordinates
vertex ColorInOut basic_vertex_ndc_tex(const Vertex in [[ stage_in ]])
{
ColorInOut out;
out.position = float4(in.position, 1.0);
out.texCoord = in.texCoord;
return out;
}
fragment float4 basic_fragment_ndc_tex(ColorInOut in [[stage_in]],
texture2d<half> tex [[ texture(TextureIndexColor) ]],
sampler samp [[ sampler(SamplerIndexDraw) ]])
{
half4 colorSample = tex.sample(samp, in.texCoord.xy);
return float4(colorSample);
}