0

I'm building an iOS App using SceneKit and ARKit. I'm using SCNTechnique to modify the rendering of SceneKit and draw a part of the scene in a stylized way. Currently, I'm using a simple metal fragment shader to draw the scene in black and white:

fragment half4 fragment_shader(VertexOut vert [[stage_in]],
                                                texture2d<half, access::sample> scene [[texture(0)]])                                              )
    {
        constexpr sampler samp = sampler(coord::normalized, address::repeat, filter::nearest);
        half4 color = scene.sample(samp, vert.texcoord);
        
        constexpr half3 weights = half3(0.2126, 0.7152, 0.0722);
        color.rgb = half3(dot(color.rgb, weights)) * 0.1;
        return color;
}

I now want to encapsulate the sylization and use a CIFilter instead of writing all the metal code myself. Is it possible to call CIFilters in Metal and for instance passing them a texture2d? If so, how?

lzsl
  • 41
  • 1
  • 3

1 Answers1

0

It seems you can assign CIFilters to SCNNodes directly via the filters property. From the docs:

When this array is nonempty, SceneKit renders the node (and its child node hierarchy) into an image buffer and then applies the filters before compositing the filters’ output into the rendered scene.

Frank Rupprecht
  • 9,191
  • 31
  • 56