Skip to content

Instantly share code, notes, and snippets.

@pfulop
Created March 23, 2019 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfulop/c9041715980a7f01211566e849d13b2b to your computer and use it in GitHub Desktop.
Save pfulop/c9041715980a7f01211566e849d13b2b to your computer and use it in GitHub Desktop.
#include <metal_stdlib>
using namespace metal;
#include <SceneKit/scn_metal>
#define GREEN_SCREEN_R 71.0/255.0
#define GREEN_SCREEN_G 255.0/255.0
#define GREEN_SCREEN_B 21.0/255.0
struct VertexInput {
float3 position [[attribute(SCNVertexSemanticPosition)]];
float2 texCoords [[attribute(SCNVertexSemanticTexcoord0)]];
};
struct NodeBuffer {
float4x4 modelViewProjectionTransform;
};
typedef struct {
float4 renderedCoordinate [[position]];
float2 textureCoordinate;
} TextureMappingVertex;
vertex TextureMappingVertex mapTexture(VertexInput in [[ stage_in ]],
constant NodeBuffer& scn_node [[ buffer(0) ]]) {
TextureMappingVertex out;
out.renderedCoordinate = scn_node.modelViewProjectionTransform * float4(in.position, 1.0);
out.textureCoordinate = in.texCoords;
return out;
}
//float4 over( in vec4 a, in vec4 b )
//{
// return a + b*(1.0-a.w);
//}
fragment half4 displayTexture(TextureMappingVertex mappingVertex [[ stage_in ]],
texture2d<float, access::sample> texture [[ texture(0) ]]) {
constexpr sampler s(address::clamp_to_edge, filter::linear);
// return half4(1.0);
float4 videoTexture = texture.sample(s, mappingVertex.textureCoordinate);
videoTexture.a = videoTexture.g;
// greenColor.sample(s, mappingVertex.textureCoordinate)
// float4 diff = videoTexture - greenColor;
return half4(videoTexture);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment