0

I come from Unity world. In Unity we can easily rotate the background skybox for image based lighting. I see that in Swift we can apply skybox by typing:

// Create a new scene
let scene = SCNScene()
var IBLImage = UIImage()
scene.lightingEnvironment.contents = IBLImage

But I want it to be able to rotate so that it can match with real environment. So far no luck with code in terms of rotating lighting Environment contents.

Any help will be highly appreciated.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220

2 Answers2

0

You should use a contentsTransform instance property – a transformation that can be applied to the material property’s visual contents:

var contentsTransform: SCNMatrix4 { get set }

or

scene.lightingEnvironment.contentsTransform

SceneKit applies this transformation to the texture coordinates provided by the geometry object the material is attached to, then uses the resulting coordinates to map the material property’s contents across the surface of the material.

About a representation of a 4x4 Matrix read here.

Also, read my answer about a combination of shear and scale (rotation) here.

enter image description here

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
0

Thanks for the answer, based on your explainition I created a function as follows

func makeRotationAroundY(angle: Float) -> simd_float4x4 {
 let rows = [
        simd_float4( cos(angle), Float(0.0), -sin(angle), Float(0.0)),
        simd_float4( Float(0.0), Float(1.0), Float(0.0), Float(0.0)),
        simd_float4( sin(angle), Float(0.0), cos(angle), Float(0.0)),
        simd_float4( Float(0.0), Float(0.0), Float(0.0), Float(1.0))
    ]
 return float4x4(rows: rows)
 }

and called

scene.lightingEnvironment.contentsTransform = SCNMatrix4(makeRotationAroundY(angle: GLKMathDegreesToRadians(180)))

However, there seems to be no change when I see content on sphere node for example. I put any angle in there seems to reflect no change.