How to use SCNNode filters with ARKit?

Viewed 501

I am trying to implement a custom CIFilter to use with an SCNNode in my ARSCNView. Unfortunately it just creates a gray rectangle where the node should be on the screen. I have also tried built-in CIFilters to double check my code to no avail.

On some other SO post I have read that CIFilter only works when OpenGL is selected as the renderingAPI for the SCNView because CoreImage doesn't play well with Metal and as far as I can tell it is impossible to get ARSCNView to run with OpenGL. The said post is from 2016 so I am wondering if anything has changed.

What I am trying to implement is to outline/highlight the object on the screen to feedback the user about object selection. I have achieved something usable by adding a shader modifier but it gives limited control over shading. I really don't want to overtake all shading on myself.

Below is my CIKernel for outlining which works very good on Quartz Composer.

Any help and information is highly appreciated.

kernel vec4 outline(sampler src) {
  vec2 texturePos = destCoord();
  float alpha = 4.0f * sample(src, texturePos).a;
  float thickness = 5.0f;

  alpha -= sample(src, texturePos + vec2(thickness, 0.0f)).a;
  alpha -= sample(src, texturePos + vec2(-thickness, 0.0f)).a;
  alpha -= sample(src, texturePos + vec2(0.0f, thickness)).a;
  alpha -= sample(src, texturePos + vec2(0.0f, -thickness)).a;

  if (alpha > 0.9f) {
      vec4 resultCol = vec4(1.0f, 1.0f, 1.0f, alpha);
      return resultCol;
  }else{
      vec4 resultCol = sample(src, texturePos);
      return resultCol;
  }
}
1 Answers

I also faced a similar problem. The cause is because we made the following settings. CIFilter could be implemented by removing this setting. I have not analyzed the details but if it comes to help!

sceneView.antialiasingMode = .multisampling4X
sceneView.contentScaleFactor = 1.3
Related