Okay, after two hours of trying everything, finally managed to write a Metal shader program that runs with SCNTechnique (DRAW_QUAD)
This actually works.
// Example of Metal Post Process Program
// Suitable for SCNTechnique
#include <metal_stdlib>
using namespace metal;
#include <SceneKit/scn_metal>
struct custom_vertex_t
{
float4 position [[attribute(SCNVertexSemanticPosition)]];
};
constexpr sampler s = sampler(coord::normalized,
address::repeat,
filter::linear);
struct out_vertex_t
{
float4 position [[position]];
float2 uv;
};
vertex out_vertex_t passThruVertexShader(custom_vertex_t in [[stage_in]])
{
out_vertex_t out;
out.position = in.position;
out.uv = float2((in.position.x + 1.0) * 0.5 , (in.position.y + 1.0) * -0.5);
return out;
};
fragment half4 passThruFragmentShader(out_vertex_t vert [[stage_in]],
texture2d<float, access::sample> image [[texture(0)]]
)
{
float4 col = image.sample( s , vert.uv );
return half4(col);
};
Line 25 flops the texture vertically. Otherwise the image is upside down.
What's puzzling me is line 30. This texture attribute binds "image" to the input image coming from ShaderKit.
texture(0) is a guess. Also odd is the symbol "image" has to be the same as the one in the plist. If we use a different symbol in the shader, then there is a binding error at runtime.
Perhaps someone who actually knows what they are doing could explain this.