swiftscenekithdropenexr

SceneKit Swift - using HDR environment light map from file


I'm trying to use a spherical HDR image as the environment light in a Swift project using SceneKit and am having trouble using standard 32bpc HDR imaging formats to do it. I can use PNG maps easily, but have trouble loading images from an OpenEXR .exr or Radiance .hdr file.

In this documentation page it seems to describe the feature I'm after.

I can't find any apple documentation describing it, so my current best guess is to write my own function to load the files and then create a CGImage instance using a custom CGDataProvider, as it seems that this container supports floating point and high dynamic range values. Then set that CGImage as the content of the environment light.

Is anyone able to confirm if this is the right idea or if this is actually already implemented somewhere. I've not done any apple development before (come from a graphics background) and am not sure if I'm on a bit of a wild goose chase at the moment.


Solution

  • What "troubles" do you have exactly? scene.lightingEnvironment.contents = "envmap.exr" should work.