Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Normal mapping in Scenekit

I am trying to add normal map for a 3D model in swift using SCNMaterial properties. The diffuse property is working but no other property including normal property is visible on the screen. When I debug to check if the node's material consists of the normal property, it shows the property exists with the image that I added. I have also checked if the normal image that I am using is correct or not in the SceneKit Editor where it works fine. I have added the code that I am using.

let node = SCNNode()
node.geometry = SCNSphere(radius: 0.1)
node.geometry!.firstMaterial!.diffuse.contents = UIColor.lightGray
node.geometry!.firstMaterial!.normal.contents = UIImage(named: "normal")
node.position = SCNVector3(0,0,0)
sceneView.scene.rootNode.addChildNode(node)

This is the output I am getting

Screen Shot

I am expecting something like this Screenshot

like image 216
Anchal Avatar asked May 18 '26 15:05

Anchal


2 Answers

I got the solution. Since I did not enable DefaultLighting, there was no lighting in the scene. Added this to the code.

sceneView.autoenablesDefaultLighting = true
like image 156
Anchal Avatar answered May 21 '26 05:05

Anchal


Given the screenshot, it seems like there is no lighting in the scene, or the material does not respond to lighting, since the sphere is not shaded. For a normal map to work, lighting has to be taken into account, because it responds to lighting direction. Have you tried creating an entirely new SCNMaterial and played with its properties? (I.E. https://developer.apple.com/documentation/scenekit/scnmaterial/lightingmodel seems interesting)

I would try setting

node.geometry!.firstMaterial!.lightingModel = .physicallyBased
like image 24
Kevin van den Hoek Avatar answered May 21 '26 03:05

Kevin van den Hoek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!