Matheus Rocha Matheus Rocha - 1 month ago 15
Swift Question

Is there a way to draw a SCNNode always in front of others?

I've been trying to make a scene with scene kit in which an specified object is always in front of others, despite the fact that it's actually behind the other objects. A similar effect to this used in blender.

Apparently, blender uses GUI and a lot of math to transform otherwise 2D objects, but I need this effect in a SCNNode with a SCNGeometry, in other words, a 3D object currently locate in the scene.

I considered using category masks, but after reading Apple's documentation I've realized that doesn't work for the effect I'm looking for.

Does anyone know a way of doin this in SceneKit? Or better yet, is it even possible to do this?

Thank you all so much in advance, for now and all other help I've got from StackExchange!

Answer

So, turns out I found the answer to my question (with the help of mnuages). I just wanted to post a complete answer.

Final result
Like suggested by mnuages, I tried setting both readsFromDepthBuffer and writesToDepthBuffer to false and setting the node's renderingOrder to a high number. It worked the wrong way. Instead of being always in front, it was always behind every object. The way to get the result shown in the picture is to set only readsFromDepthBuffer to false, and set the cube's renderingOrder to -1, or else it will be impossible to draw over it.

Since the cube and the other nodes' materials have readsFromDepthBuffer and writesToDepthBuffer set to the default value of true, it will still be in front of the objects behind it, and behind the objects in front of it, in other words, it will be normal, only the arrows will behave the way we want.

As can be seen in the image, the portion of the lines in front of the cube are visible. The same can't be said for portion behind it.