In Xcode SceneKit editor, its possible to visualise surface normals of a SCNGeoemtry
It seems that the editor uses SCNGeometrySource.Semantic to render the image: https://developer.apple.com/documentation/scenekit/scngeometrysource/semantic
How can I render the surface normals of a geometry to an image?
Let's give it a try. You can achieve a normal or normal like shading of your geometry by using a
SCNProgram()
for rendering. This replaces the entire rendering which is provided by Apple (likeconstant
,phong
,blinn
, orphysicallyBased
)Start using for example with the default SceneKit Template that comes along with Xcode, the one that contains the rotating spaceship.
First, create a Metal-File, and call it
shaders.metal
.Variation 1 (first Image below): Copy the following code into this file. (this code here will generate a World Space Normal Map)
Variation 2 (second image below): Copy the following code into this file. (this code here will generate a Tangent Space Normal Map)
In the the GameViewController insert the following function, that will attach this shader to a given Node (you can also define the SCNProgram globally and re-use it).
the last step is filing a Node to that shader. I'll use the default Spaceship here. (Make sure to file the exact node containing the geometry you want to shade with that custom shader program.)
Modify Code like this: (here: in
viewDidLoad
)Hope this will help in some way.