ios Scenekit阴影随着摄影机移动而逐渐消失

3mpgtkmj  于 2023-05-23  发布在  iOS
关注(0)|答案(1)|浏览(104)

我已经在Scenekit中设置了逼真的灯光,但是当相机远离灯光打开的对象时,灯光会逐渐消失,最终完全消失。

// LIGHTING
        let floorPlane = SCNFloor()
        let groundPlane = SCNNode()
        let groundMaterial = SCNMaterial()
        groundMaterial.lightingModel = .constant
        groundMaterial.writesToDepthBuffer = true
        groundMaterial.colorBufferWriteMask = []
        groundMaterial.isDoubleSided = true
        floorPlane.materials = [groundMaterial]
        groundPlane.geometry = floorPlane
        //
        charNode.addChildNode(groundPlane)
        // Create a ambient light
        ambientLight.light = SCNLight()
        ambientLight.light?.shadowMode = .deferred
        ambientLight.light?.color = UIColor.white
        ambientLight.light?.type = SCNLight.LightType.ambient
        ambientLight.position = SCNVector3(x: 0,y: 5,z: 0)
        // Create a directional light node with shadow
        directLight.light = SCNLight()
        directLight.light?.type = SCNLight.LightType.directional
        directLight.light?.color = UIColor.white
        directLight.light?.castsShadow = true
        directLight.light?.automaticallyAdjustsShadowProjection = true
        directLight.light?.shadowSampleCount = 64
        directLight.light?.shadowRadius = 16
        directLight.light?.shadowMode = .deferred
        directLight.light?.shadowMapSize = CGSize(width: 2048, height: 2048)
        directLight.light?.shadowColor = UIColor.black.withAlphaComponent(0.75)
        directLight.position = SCNVector3(x: 0,y: 5,z: 0)
        directLight.eulerAngles = SCNVector3(-Float.pi / 2, 0, 0)
        // Add the lights to the container
        charNode.addChildNode(ambientLight)
        charNode.addChildNode(directLight)
pokxtpni

pokxtpni1#

您可能需要增加SCNLight.maximumShadowDistance值:

/**
 @property maximumShadowDistance
 @abstract Specifies the maximum distance from the viewpoint from which
 the shadows for the receiver light won't be computed. Defaults to 100.0.
 */
@available(macOS 10.13, *)
open var maximumShadowDistance: CGFloat

相关问题