title: iOS10 + SceneKit: render a video with custom shader
body: <p>How can I render a video as a diffuse texture on a node in SceneKit while using custom shader? This sounds like a simple thing to do but:</p>
  
  <ul>
  <li>SceneKit elements don't support <code>AVPlayerLayer</code> as input texture (<a href="https://stackoverflow.com/a/32890987/2054629">SO</a>)</li>
  <li>alternatives are:
  
  <ul>
  <li>using a SpriteKit scene with a SKVideoNode but:
  
  <ul>
  <li>Since iOS 10, rendering with openGL fails as soon as a SpriteKit scene is involved (<a href="https://stackoverflow.com/questions/39521210/ios10-cant-render-sprite-kit-scene-within-scenekit-with-opengl">SO</a>) I've filled a radar</li>
  <li>I could not figure out how to pass uniforms to a shader modifier when using Metal (<a href="https://stackoverflow.com/questions/39522370/scn-shader-modifier-in-metal-pass-uniform-to-shader">SO</a>) Things were working perfectly with openGL (on iOS 9, when SpriteKit was working) There's surprisingly very little documentation out there on that.</li>
  <li>SCNProgram seems to fails as soon as a video is involved in the SceneKit scene (<a href="https://stackoverflow.com/questions/39526026/metal-scnprogram-cant-render-a-spritekit-scene-that-has-video-content">SO</a>) Things work fine with the same setup without video</li>
  </ul></li>
  <li>transforming the video output to a CGImage, passing it to a CALayer, and passing this layer to the SceneKit video node (no SpriteKit involved) This is detailed <a href="https://stackoverflow.com/a/38399833/2054629">here</a>, but not a viable solution as soon as the video is a bit large, because all the output is getting copied to image and this is costly..</li>
  </ul></li>
  </ul>
  
  <p>I'm still quite reluctant to get out of SceneKit, since it's handling a lot of the annoying low level things with opengl/metal, but I can't get things to work right now...</p>
  
  <p>As an additional bad news, it looks like SpriteKit has memory leak when used with Metal, and that it keeps alive the SceneView, and therefore all the parent views and everything attached to them...</p>
  
  <p>You can find a reproduction of this issue <a href="https://github.com/gsabran/SceneKit-SpriteKit-memoryLeak" rel="nofollow noreferrer">here</a>, and a simpler one <a href="https://gist.github.com/gsabran/30714b7c82ad24d43fe7179d638bbe47" rel="nofollow noreferrer">here</a>: </p>