4
\$\begingroup\$

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?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

The property you want to apply your texture to is called "normal", for normal mapping. You can find the documentation for this property here.

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
earthGeometry.firstMaterial!.normal.contents = earthBump

let earth = SCNNode(geometry: earthGeometry)

As you can see in this image from the documentation, this works with a tangent space normal map:

Normal map diagram

Here the pale blueish-lavender colour represents a surface normal pointing straight out from the sphere, while the other colours represent normals tilted east/west/north/south by hills and valleys. If your bump map is in a different formal (like a greyscale heightmap), then you can use various tools to convert it to this coloured normal map format.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .