SKTexture used for SceneKit object is rendered too bright

I would like to preload and use some images for both SpriteKit and SceneKit models (my game uses SceneKit with a SpriteKit overlay), and as far as I can see the only efficient way would be to create and preload SKTexture objects which can be supplied to SKSpriteNode(texture:) and SCNMaterial.diffuse.contents.

The problem is that SKTexture are rendered too bright in SceneKit, for some unknown reason. Here a comparison between rendering an image (from URL) and a SKTexture:

And the code that produces it:

let url = Bundle.main.url(forResource: "art.scnassets/texture.png", withExtension: nil)!
let plane1 = SCNPlane(width: 10, height: 10)
plane1.firstMaterial!.diffuse.contents = url.path
let node1 = SCNNode(geometry: plane1)
node1.position.x = -5
scene.rootNode.addChildNode(node1)

let plane2 = SCNPlane(width: 10, height: 10)
plane2.firstMaterial!.diffuse.contents = SKTexture(image: NSImage(byReferencing: url))
let node2 = SCNNode(geometry: plane2)
node2.position.x = 5
scene.rootNode.addChildNode(node2)

This issue was already mentioned in this other post, but since I wasn't notified of the reply from Quinn asking about the feedback number I created at the time, it didn't make any progress.

Answered by DTS Engineer in 812221022

Hello @Nickkk,

Ok, sounds like you are using this approach as a performance optimization. Until there is some resolution on your bug report, it appears that you won't be able to re-use the SKTexture.

Best regards,

Greg

Hello @Nickkk,

I see that you filed a bug report for this issue. Please continue to follow-up with your bug report in each new release, updating it if the issue persists.

In the meantime, can you share the reason that you are using an SKTexture as your material property contents here? There might be an alternative path (that does not use SKTexture) that can unblock you.

Best regards,

Greg

Right now for SceneKit I'm preloading SCNMaterial by running

material.diffuse.contents = url

and for SpriteKit I run

SKTexture(image: NSImage(contentsOf: url)!)

in the background. If I need the same image for both SceneKit and SpriteKit, this means that it's read twice from disk.

As mentioned, I'd like to use SKTexture because that's what I think could be preloaded once and then used in both SpriteKit and SceneKit.

Hello @Nickkk,

Ok, sounds like you are using this approach as a performance optimization. Until there is some resolution on your bug report, it appears that you won't be able to re-use the SKTexture.

Best regards,

Greg

On the plane, try using .firstMaterial?.lightingModel = .constant

I didn't have this exact scenario but I remember solving a display issue with SKTextures in a 3D scene by doing this.

On the plane, try using .firstMaterial?.lightingModel = .constant

Thank you for your input! Unfortunately the result is still the same. I tried all the different lighting models and none yielded the desired result.

SKTexture used for SceneKit object is rendered too bright
 
 
Q