I'm trying to convert my game from SceneKit to RealityKit. I noticed that even when the scene is static (nothing moves), RealityKit keeps using CPU. In SceneKit, CPU goes down to 0% with a static scene.
With this simplest of games, RealityKit keeps using about 65% CPU:
class ViewController: NSViewController {
override func loadView() {
view = ARView(frame: NSScreen.main!.frame)
}
}
Is this expected or a bug?
I created FB22125047.
RealityKit
RSS for tagSimulate and render 3D content for use in your augmented reality apps using RealityKit.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
I'm in the process of converting my SceneKit game to RealityKit. In SceneKit I used to be able to mark nodes as selected by setting SCNMaterial.emission with a custom color. I can do the same with PhysicallyBasedMaterial.emissiveColor, but I'd like to keep my entitities unaffected by the scene lights by using UnlitMaterial. In SceneKit I can set a category mask to indicate what light should affect what node, but there doesn't seem to be such a thing in RealityKit. So at the moment it seems like I have to choose between being able to mark an entity as selected, or having entities unaffected by lighting, but not both.
Is there some effect or component I can use to mark entities as selected by applying some coloring regardless of the material used?
I'm converting my game from SceneKit to RealityKit. It has a SpriteKit overlay that according to Explore advanced rendering with RealityKit 2 I can add with the code below.
The code runs fine if the SKScene only contains a SKSpriteNode (see the commented out line), but when I add a SKShapeNode with a fillColor instead, the app crashes with this error:
-[MTLDebugRenderCommandEncoder validateCommonDrawErrors:]:5970: failed assertion `Draw Errors Validation
MTLDepthStencilDescriptor uses frontFaceStencil but MTLRenderPassDescriptor has a nil stencilAttachment texture
MTLDepthStencilDescriptor uses backFaceStencil but MTLRenderPassDescriptor has a nil stencilAttachment texture
'
I don't know enough about low-level graphics and stencils yet to figure out a quick solution, so I would appreciate if anyone could share an easy fix or explanation of what's wrong. Thanks!
class ViewController: NSViewController {
var device: MTLDevice!
var renderer: SKRenderer!
override func loadView() {
let arView = ARView(frame: NSScreen.main!.frame)
view = arView
arView.renderCallbacks.prepareWithDevice = { [weak self] device in
guard let self = self else { return }
self.device = device
renderer = SKRenderer(device: MTLCreateSystemDefaultDevice()!)
let scene = SKScene()
let shape = SKShapeNode(rectOf: CGSize(width: 10, height: 10))
shape.fillColor = .red
scene.addChild(shape)
// scene.addChild(SKSpriteNode(color: .red, size: CGSize(width: 10, height: 10)))
renderer.scene = scene
}
arView.renderCallbacks.postProcess = { [weak self] context in
guard let self = self else { return }
let encoder = context.commandBuffer.makeBlitCommandEncoder()
encoder?.copy(from: context.sourceColorTexture, to: context.targetColorTexture)
encoder?.endEncoding()
renderer.update(atTime: context.time)
let descriptor = MTLRenderPassDescriptor()
descriptor.colorAttachments[0].loadAction = .load
descriptor.colorAttachments[0].storeAction = .store
descriptor.colorAttachments[0].texture = context.targetColorTexture
renderer.render(withViewport: CGRect(x: 0, y: 0, width: context.targetColorTexture.width, height: context.targetColorTexture.height), commandBuffer: context.commandBuffer, renderPassDescriptor: descriptor)
}
}
}