Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SceneKit: Programmatically use "Procedural Sky" option from Scene Inspector?

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?

like image 257
Crashalot Avatar asked Oct 28 '22 15:10

Crashalot


1 Answers

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:

  • https://github.com/FlexMonkey/SkyCubeTextureDemo
  • http://flexmonkey.blogspot.com/2015/07/a-first-look-at-model-ios-sky-cube.html

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.

like image 133
Wukerplank Avatar answered Nov 15 '22 10:11

Wukerplank