5

In the Xcode SceneKit Scene Inspector, there is a Procedural Sky option under the Environment section.

According to some tutorials, enabling this option will impart more realism to 3D models.

1) If you're creating a scene from code and not from the Scene Inspector, how do you enable the Procedural Sky option? There is no Environment property.

2) Does the Procedural Sky option only work if you using PBR materials?

Crashalot
  • 33,605
  • 61
  • 269
  • 439

2 Answers2

4

Yes, you can: The class you are looking for is MDLSkyCubeTexture

The most basic way to use it to put it into your scene's background contents:

class MyGameScene: SCNScene {
    override init() {
        super.init()
        self.background.contents = MDLSkyCubeTexture(name: "sky",
                                          channelEncoding: .float16,
                                        textureDimensions: vector_int2(128, 128),
                                                turbidity: 0,
                                             sunElevation: 1.5,
                                upperAtmosphereScattering: 0.5,
                                             groundAlbedo: 0.5)
        // To let the sky influence the lighting:
        self.lightingEnvironment.contents = self.background.contents
    }
}

You'll have to read up on the parameters yourself since I just stumbled over this.

I found these links of interest:

These sources are 5 years old, so I'm sure some stuff has changed meanwhile.

Regarding the second part of your question: You can pipe this into your materials, but I'm not too knowledgeable yet.

Wukerplank
  • 4,156
  • 2
  • 28
  • 45
  • Works very well on Xcode 11, iOS 13! Using values above create colors different from the default procedural sky colors, but links provided & Xcode documentation shows how to create dusk, noon, etc. – BumMo Koo Jun 10 '20 at 06:19
-1

For iOS 12 use:

configuration.environmentTexturing = .automatic
shim
  • 9,289
  • 12
  • 69
  • 108
masaldana2
  • 635
  • 9
  • 20