Skip to content

Instantly share code, notes, and snippets.

@kunofellasleep
Last active October 6, 2018 03:56
Show Gist options
  • Save kunofellasleep/2b4cefa7bf024d03df62a32e920a0b0c to your computer and use it in GitHub Desktop.
Save kunofellasleep/2b4cefa7bf024d03df62a32e920a0b0c to your computer and use it in GitHub Desktop.
duotone-style shader
#include <metal_stdlib>
using namespace metal;
kernel void duotone(
texture2d<float, access::write> outTex [[texture(0)]],
texture2d<float, access::read> inTex [[texture(1)]],
uint2 gid [[thread_position_in_grid]])
{
float3 c = inTex.read(gid).rgb;
float mn = (c.r + c.g + c.b) / 3.0;
float4 out = float4(0.5, 0.5 + mn, 1.0, 1.0);
outTex.write(out.rgba, gid);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment