This question will leave you all puzzled: In my project, a spaceship is flying over a landscape. It casts a shadow (straight below) that is created by using a directional light, so its size doesn't change with the height of the ship. I was trying a lot of times to get it completely right, and sometimes it works and other times it doesn't. I have a moving camera, meaning the angle to the ship changes depending on the angle it flies.
Now I found out why the shadow isn't always working the way it is supposed to: below a certain view angle (the more it comes to the horizontal view), the shadow will become pixeled, then flicker until it's completely gone when the camera is entirely horizontal.
As the view is directed increasingly below, the shadow of the ship will become more and more resolved and at above approx. 30° it's just right.
I have checked in Stack Overflow, but it seems a changing angles camera is rather unusual. I guess a fixed camera above the player's node is more common.
Anyone know this behavior? This is my code.
self.dirLightNode = SCNNode()
self.dirLightNode.light = SCNLight()
self.dirLightNode.position = SCNVector3(x: -0 * dividerx,
y: 20 * dividery,
z: -00)
self.dirLightNode.light?.type = .directional
self.dirLightNode.light!.color = UIColor.black
self.dirLightNode.light?.castsShadow = true
self.dirLightNode.light?.shadowMode = .deferred
self.dirLightNode.light?.categoryBitMask = 1
self.dirLightNode.light?.shadowColor = UIColor.black.withAlphaComponent(0.8)
self.dirLightNode.rotation = SCNVector4Make(1,0,0, 1.5 * Float.pi)
self.dirLightNode.light?.orthographicScale = 10
self.dirLightNode.light?.shadowRadius = 10
self.dirLightNode.light?.shadowBias = 1
self.dirLightNode.light?.zFar = 100
self.dirLightNode.light?.zNear = 0
self.dirLightNode.light?.maximumShadowDistance = 10000
self.dirLightNode.light?.shadowSampleCount = 1
self.dirLightNode.light?.shadowMapSize = CGSize(width: 4096, height: 4096)
I tried to change the shadowradius, shadowBias,samplecount, automaticshadowprojection, etc. Nothing seems to fix the problem. Does anyone know a reference where all the parameters are explained thoroughly?