How to use SCNNode filters with ARKit?

时间:2017-08-13 13:44:34

标签: ios swift opengl-es metal arkit

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 个答案:

答案 0 :(得分:3)

我也遇到过类似的问题。原因是我们进行了以下设置。可以通过删除此设置来实现CIFilter。 我没有分析细节,但是如果有帮助的话!

sceneView.antialiasingMode = .multisampling4X
sceneView.contentScaleFactor = 1.3