// // Shaders.metal // LenzCameraNativeModuleForRN // // Created by 王昭威 on 2023/1/26. // #include "LenzCommon.h" #include using namespace metal; typedef struct{ // float3 position [[attribute]]; }VertextIn; typedef struct{ float4 position [[position]]; float2 uv; }VertextOut; vertex VertextOut vert_main(uint vertId [[vertex_id]]){ float4x4 vertices = float4x4( float4( -1.0, -1.0, 0.0, 1.0 ), float4( 1.0, -1.0, 0.0, 1.0 ), float4( -1.0, 1.0, 0.0, 1.0 ), float4( 1.0, 1.0, 0.0, 1.0 ) ); float4x2 uvs = float4x2( float2( 0.0, 1.0 ), float2( 1.0, 1.0 ), float2( 0.0, 0.0 ), float2( 1.0, 0.0 ) ); return VertextOut{ .position = vertices[vertId], .uv = uvs[vertId], }; } fragment half4 frag_main(VertextOut in [[stage_in]], texture2d texture [[texture(CameraCapturedTexture)]]){ sampler s = sampler(address::clamp_to_edge, filter::linear); if(is_null_texture(texture)){ return half4(0, 0, 0, 1); } return half4(texture.sample(s, in.uv)); }