sky*_*guy 5 xcode lighting augmented-reality swift arkit
好吧,当添加到 Swift/Xcode 中的 ARScene 时,我拼命地在我的对象上实现这种温暖的灯光 - 温暖的灯光和周围的小发光灯:
需要明确的是,我不希望添加到场景中的对象看起来像是属于周围的房间。我希望它们脱颖而出/看起来温暖而发光。ARKit 上的所有教程都会教你如何模仿实际房间的灯光。
Xcode 有几个照明选项,从相机收集的周围环境中提取,因为:
if let lightEstimate = session.currentFrame?.lightEstimate
Run Code Online (Sandbox Code Playgroud)
我可以打印出温暖度、强度等。并且我当前还设置了这些属性来匹配房间的光线:
sceneView.automaticallyUpdatesLighting = true
extension ARSCNView {
func setup() { //SCENE SETUP
antialiasingMode = .multisampling4X
autoenablesDefaultLighting = true
preferredFramesPerSecond = 60
contentScaleFactor = 1.3
if let camera = pointOfView?.camera {
camera.wantsHDR = true
camera.wantsExposureAdaptation = true
camera.exposureOffset = -1
camera.minimumExposure = -1
camera.maximumExposure = 3
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过提高对象纹理的发射率,但没有任何效果。添加灯光只会使物体变黑/无颜色。
这里有什么问题吗?
要在 ARKit 中创建这种类型的红色霓虹灯效果。您可以执行以下操作。
您需要创建一个reactor.scnp(scenekit粒子系统文件)并进行以下更改以创建发光的红色光环。这应该与文件 Spark.png 一起放置在 Playground 的 Resources 目录中
这些是要从默认反应器类型更改的设置。保留所有其他设置。
将图像动画颜色更改为红色/橙色/红色/黑色
速度系数 = 0.1
启用照明已选中
发射器形状 = 球体
图像尺寸 = 0.5
图像强度 = 0.1
模拟速度系数 = 0.1
注意:下面的代码是我用于测试目的的游乐场应用程序。您只需点击任意位置即可将霓虹灯添加到场景中。您可以根据需要放置任意数量的霓虹灯。
import ARKit
import SceneKit
import PlaygroundSupport
import SceneKit.ModelIO
class ViewController: NSObject {
var sceneView: ARSCNView
init(sceneView: ARSCNView) {
self.sceneView = sceneView
super.init()
self.setupWorldTracking()
self.sceneView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ViewController.handleTap(_:))))
}
private func setupWorldTracking() {
if ARWorldTrackingConfiguration.isSupported {
let configuration = ARWorldTrackingConfiguration()
configuration.planeDetection = .horizontal
configuration.isLightEstimationEnabled = true
self.sceneView.session.run(configuration, options: [])
}
}
@objc func handleTap(_ gesture: UITapGestureRecognizer) {
let results = self.sceneView.hitTest(gesture.location(in: gesture.view), types: ARHitTestResult.ResultType.featurePoint)
guard let result: ARHitTestResult = results.first else {
return
}
let cylinder = SCNCylinder(radius: 0.05, height: 1)
cylinder.firstMaterial?.emission.contents = UIColor.red
cylinder.firstMaterial?.emission.intensity = 1
let spotLight = SCNNode()
spotLight.light = SCNLight()
spotLight.scale = SCNVector3(1,1,1)
spotLight.light?.intensity = 1000
spotLight.castsShadow = true
spotLight.position = SCNVector3Zero
spotLight.light?.type = SCNLight.LightType.directional
spotLight.light?.color = UIColor.white
let particleSystem = SCNParticleSystem(named: "reactor", inDirectory: nil)
let systemNode = SCNNode()
systemNode.addParticleSystem(particleSystem!)
let node = SCNNode(geometry: cylinder)
let position = SCNVector3Make(result.worldTransform.columns.3.x, result.worldTransform.columns.3.y, result.worldTransform.columns.3.z)
systemNode.position = position
node.position = position
self.sceneView.scene.rootNode.addChildNode(spotLight)
self.sceneView.scene.rootNode.addChildNode(node)
self.sceneView.scene.rootNode.addChildNode(systemNode)
}
}
let sceneView = ARSCNView()
let viewController = ViewController(sceneView: sceneView)
sceneView.autoenablesDefaultLighting = false
PlaygroundPage.current.needsIndefiniteExecution = true
PlaygroundPage.current.liveView = viewController.sceneView
Run Code Online (Sandbox Code Playgroud)
如果您在场景中寻找霓虹灯/发光效果...之前对有关发光/霓虹灯照明的类似问题的回答应该会给您一些指导。
正如您从提供的答案中看到的,sceneKit 没有对体积照明的内置支持,所有方法都更多是为了实现与发光光类似的效果。
要向场景添加“红色”定向光效果...这是使用 sceneView.autoenablesDefaultLighting = true 的替代方法
let myLight = SCNNode()
myLight.light = SCNLight()
myLight.scale = SCNVector3(1,1,1)
myLight.intensity = 1000
myLight.position = SCNVector3Zero
myLight.light?.type = SCNLight.LightType.directional
myLight.light?.color = UIColor.red
// add the light to the scene
sceneView.scene.rootNode.addChildNode(myLight)
Run Code Online (Sandbox Code Playgroud)
注意:此效果使场景中的所有对象更加偏红。
| 归档时间: |
|
| 查看次数: |
4553 次 |
| 最近记录: |