ARKit - 适应光线条件

时间:2017-11-23 23:50:59

标签: swift unity3d augmented-reality arkit

我目前正在学习在Unity和Swift中做一些ARKit的事情。

有人怎么能让我的物体的光线适应环境光?

谢谢!

1 个答案:

答案 0 :(得分:0)

要为您的应用启用ARKit的Status = gBS->OpenProtocol( HandleBuffer[Index], &gEfiUsbIoProtocolGuid, (VOID **)&UsbIo, gImageHandle, NULL, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL ); ,您需要执行以下步骤:

  • 为ARS场景启用光估计(在Xcode中):

    Light Estimation
  • 利用configuration.lightEstimationEnabled = true 更新照明:

    lightEstimate.ambientIntensity
  • 创建PBR材料:

    func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
    
        guard let lightEstimate = sceneView.session.currentFrame?.lightEstimate else { 
            return 
        } 
        spotLight.intensity = lightEstimate.ambientIntensity / 1000.0
    }
    
  • 分配环境图:

    let material = SCNMaterial()
    material.lightingModel = .physicallyBased
    material.diffuse.contents = UIImage(named: "diffuse.png")
    material.metalness.contents = UIImage(named: "metalness.png")
    material.roughness.contents = UIImage(named: "roughness.png")
    myModel.materials = [material]
    
  • 设置照明环境的强度:

    let environment = UIImage(named: "envMap.png")
    
    sceneView.scene.lightingEnvironment.contents = environment
    

希望这会有所帮助。