I’ve an issue with shadows in RealityKit
and DirectionalLights
.
After performing some analysis from my preliminary query about this, I downloaded an Xcode challenge that describes the fundamentals of lights in RealityKit
. It is easy sufficient.
One of many examples utilized in that pattern challenge concerned a DirectionalLight
, which might be very useful for lighting just like the solar.
I took a have a look at the DirectionalLight
choice within the app, and added an additional sphere the scene:
This is the lighting for that:
personal func addDirectionalLight() {
let directionalLight = DirectionalLight()
directionalLight.gentle.depth = 100000
directionalLight.shadow?.maximumDistance = 5
directionalLight.shadow?.depthBias = 1
directionalLight.look(at: [0, 0, 0], from: [-50, 20, 0], relativeTo: nil)
addLight(directionalLight)
}
I made the depth of it fairly excessive so you possibly can simply see the sunshine (white half) vs the shadows (non-white half).
I then went to my very own challenge.
I wish to create a directional lighting setup to realize an impact akin to the solar. I believed that might be simple… I’d simply have to have a look at how the pattern challenge did it and make changes.
Properly… I attempted creating my very own lighting setup as follows:
let directionalLight = DirectionalLight()
directionalLight.gentle.depth = 100000
directionalLight.shadow?.maximumDistance = 3
directionalLight.look(at: [0, 0, 0], from: [0, 100, 1200], relativeTo: nil)
// directionalLight.orientation = simd_quatf(angle: .pi/2, axis: [0, 1, 0])
lightAnchor.addChild(directionalLight)
the place lightAnchor
is an AnchorEntity
at [0, 0, 0] for the world.
This is the end result when utilized to things:
Do you discover something? I circled it. It is just like the lighting is being utilized to every particular person object with none form of regard for the truth that one other object is there.
In actual life, a shadow could be casted from the sphere on high of the dice along with the shadow that’s at present current. Have a look at the primary picture and fake it’s the high of the dice from the second photograph. Sure, there is a shadow on the again of the sphere the place the sunshine would not hit, however ALSO on the aircraft it is on.
I’m extraordinarily confused.
The one factor I considered is that the primary picture has a scale the place the sphere within the middle of the photograph is about 3 meters broad… whereas my second picture is at a a lot, a lot bigger scale. That field is 150 meters broad.
However, that ought to not affect the lighting, proper? I do not imagine it ought to. Is my DirectionalLight
in a foul place? I do not perceive how it will be, contemplating that it hit field and sphere.
I merely need shadows like within the first picture, however for some purpose I can not obtain that.
I actually need some assistance on this. It will be wonderful if somebody may!
Additionally, completely satisfied Imaginative and prescient Professional day! 🙂