123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- //
- // Shaders.metal
- // LenzCameraNativeModuleForRN
- //
- // Created by 王昭威 on 2023/1/26.
- //
- #include "LenzCommon.h"
- #include <metal_stdlib>
- 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<float> 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));
- }
|