Home > Software design >  SceneKit shadow chainsaw like rough edge
SceneKit shadow chainsaw like rough edge

Time:09-21

My SceneKit shadow has chainsaw like rough/pixelated edges. I simply use the default value with simple setup:

  func addLightNode() -> SCNNode {
    let light = SCNLight()
    light.type = .directional
    light.castsShadow = true
    light.shadowColor = UIColor.black.copy(alpha: 0.5)
    let node = SCNNode()
    node.light = light
    node.eulerAngles = light_euler_angles
    
    rootNode.addChildNode(node)
    return node
  }

This is the result:

enter image description here

I have tried to increase the shadowBias but the same result. What other attribute should I set in order to prevent this?

CodePudding user response:

Try to increase shadowSampleCount:

    light.shadowSampleCount = 8

The default value for iOS is 1, increase it to something like 8 or 16 should be good enough

  • Related