I have an MTKView in which I want to first render a SceneKit scene onto a Render Texture and then pass this render texture into my own post-processing stage.
It works fine, I see my Scene rendered correctly with all the objects, but there are no shadows being renderered and I've worked out that it's the SCNRenderer call that's not drawing them (the scene in a SCNView, ARSCNView etc. will show shadows fine). i.e., the nodes are casting correctly, and the light is set to cast shadows, so it's not a scene issue.
Presumably I've not set up the descriptor with extra details that it needs for shadow rendering, but I'm not certain what the SCNRenderer is actually needing here? Sadly the documentation isn't revealing a great to deal to me on this subject.
Any pointers would be much appreciated, no matter how general. I can't even find examples of the SCNRenderer being used in similar situations.
It works fine, I see my Scene rendered correctly with all the objects, but there are no shadows being renderered and I've worked out that it's the SCNRenderer call that's not drawing them (the scene in a SCNView, ARSCNView etc. will show shadows fine). i.e., the nodes are casting correctly, and the light is set to cast shadows, so it's not a scene issue.
Presumably I've not set up the descriptor with extra details that it needs for shadow rendering, but I'm not certain what the SCNRenderer is actually needing here? Sadly the documentation isn't revealing a great to deal to me on this subject.
Any pointers would be much appreciated, no matter how general. I can't even find examples of the SCNRenderer being used in similar situations.
Code Block let descriptor = MTLRenderPassDescriptor() descriptor.colorAttachments[0].loadAction = .clear descriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0) descriptor.colorAttachments[0].texture = metalRenderTexture descriptor.colorAttachments[0].storeAction = .store if let commandBuffer = commandQueue.makeCommandBuffer() { commandBuffer.label = "3DSceneBuffer" if isDrawingPreVizScene { sceneKitRenderer.render(withViewport: CGRect(x: 0, y: 0, width: metalRenderTexture!.width, height: metalRenderTexture!.height), commandBuffer: commandBuffer, passDescriptor: descriptor) } commandBuffer.commit() }
UPDATE: This turned out to be a case of user error.
The camera in the SceneKit scene was having the projection matrix overwritten by the projection matrix of the ARKit frame camera in order to keep in sync (we can't use ARSCNView for our needs).
However, overwriting the projection matrix changed the near/far which meant the shadows weren't renderered correctly. Using the alternative method:
The camera in the SceneKit scene was having the projection matrix overwritten by the projection matrix of the ARKit frame camera in order to keep in sync (we can't use ARSCNView for our needs).
However, overwriting the projection matrix changed the near/far which meant the shadows weren't renderered correctly. Using the alternative method:
Code Block node.camera.projectionTransform = SCNMatrix4(frame.camera.projectionMatrix(for: .landscapeRight, viewportSize: CGSize(width: width, height: height), zNear: 0.1, zFar: 1000))