# How to add a bump map in scene kit?

I'm trying to draw an Earth, as I've found the textures in this site: http://planetpixelemporium.com/earth.html

I loaded the diffuse, specular and bump maps:

let earthGeometry = SCNSphere(radius: radius)

let earthMap = UIImage(named: "Earth_map")
let earthBump = UIImage(named: "Earth_bump")
let earthSpec = UIImage(named: "Earth_specular")

earthGeometry.firstMaterial!.diffuse.contents = earthMap
earthGeometry.firstMaterial!.specular.contents = earthSpec

let earth = SCNNode(geometry: earthGeometry)


But there is no property for the bump map. The only way that comes to my mind is to use a MDLMaterial but I see no way to convert the material back to a SCNMaterial. The method:

+ (instancetype)materialWithMDLMaterial:(MDLMaterial *)mdlMaterial


Runs just in Objective-C and not in Swift. Does anyone know how to convert it to a SCNMaterial, or alternatively to use another way to apply a bump map in a SCNMaterial?

There isn’t a built-in way to apply a grayscale bump map like the one you have; what SceneKit expects is a normal map. It’s pretty straightforward to convert one into the other, though; there’s even an online tool available to do so here.

earthGeometry.firstMaterial!.normal.contents = earthBump


EDIT: the updated code will be: