Sceneekit–加载HDR或EXR照明环境无效

发布于 2025-01-21 04:35:31 字数 590 浏览 1 评论 0 原文

我尝试加载 .hdr 文件将其用作Skybox并使用其照明信息。这是我使用的代码:

backgroundColor = UIColor.gray 
// check if a default skybox is added

let environment = UIImage(named: "studio_small_09_2k.hdr")
scene?.lightingEnvironment.contents = environment
scene?.lightingEnvironment.intensity = 1.0
scene?.background.contents = environment

不幸的是,我收到一个灰色屏幕,也没有错误。有没有在Scenekit中使用HDR文件的经验?

XCode版本:13.2.1 iOS版本:15.3.1 hdr文件: https://polyhaven.com/a/studio_small_09

I tried loading an .hdr file to use it as a skybox and use its lighting informations. This is the code I used:

backgroundColor = UIColor.gray 
// check if a default skybox is added

let environment = UIImage(named: "studio_small_09_2k.hdr")
scene?.lightingEnvironment.contents = environment
scene?.lightingEnvironment.intensity = 1.0
scene?.background.contents = environment

Unfortunately I recieve a grey screen and also no errors. Has anyone experience in using hdr files in SceneKit?

XCode Version: 13.2.1
iOS version: 15.3.1
hdr file: https://polyhaven.com/a/studio_small_09

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙与沫 2025-01-28 04:35:31

我通常使用,其中6张图像中的每一个为Square (height == width)

另外,支持以下立方体映射表示:

  • 垂直条作为单个图像(高度== 6 *宽度)
  • 水平条作为单个图像(6 * height == width)
  • 球形投影作为单个图像(2 * height ==宽度)

这是SwiftUI代码:

func makeUIView(context: Context) -> SCNView {

    let sceneView = SCNView(frame: .zero)
    sceneView.scene = SCNScene()
    // if EXR or HDR is 2:1 spherical map, it really meets the requirements
    sceneView.scene?.lightingEnvironment.contents = UIImage(named: "std.exr")
    sceneView.backgroundColor = .black
    sceneView.autoenablesDefaultLighting = true
    sceneView.allowsCameraControl = true
    
    let node = SCNNode()
    node.geometry = SCNSphere(radius: 0.1)
    node.geometry?.firstMaterial?.lightingModel = .physicallyBased
    node.geometry?.firstMaterial?.metalness.contents = 1.0
    sceneView.scene?.rootNode.addChildNode(node)
    return sceneView
}

特别注意 - 您需要。基于照明模型以获得HDR或EXR反射。

让我们为BG设置它:

sceneView.scene?.background.contents = UIImage(named: "std.exr")

”在此处输入图像描述”

为什么您的 .exr 不起作用?

解决方案很简单:从项目中删除您的 .exr ,然后清空垃圾,然后拖放 .exr file,in 选择用于添加这些文件的选项窗口选择添加到目标

”在此处输入图像描述

现在您的 .exr 必须工作。

I usually use a Cube Texture Set, where each of 6 images is square (height == width).

Also, the following cube map representations are supported:

  • Vertical strip as single image (height == 6 * width)
  • Horizontal strip as single image (6 * height == width)
  • Spherical projection as single image (2 * height == width)

Here's a SwiftUI code:

func makeUIView(context: Context) -> SCNView {

    let sceneView = SCNView(frame: .zero)
    sceneView.scene = SCNScene()
    // if EXR or HDR is 2:1 spherical map, it really meets the requirements
    sceneView.scene?.lightingEnvironment.contents = UIImage(named: "std.exr")
    sceneView.backgroundColor = .black
    sceneView.autoenablesDefaultLighting = true
    sceneView.allowsCameraControl = true
    
    let node = SCNNode()
    node.geometry = SCNSphere(radius: 0.1)
    node.geometry?.firstMaterial?.lightingModel = .physicallyBased
    node.geometry?.firstMaterial?.metalness.contents = 1.0
    sceneView.scene?.rootNode.addChildNode(node)
    return sceneView
}

Pay particular attention – you need .physicallyBased lighting model to get HDR or EXR reflections.

enter image description here

And let's set it for BG:

sceneView.scene?.background.contents = UIImage(named: "std.exr")

enter image description here

Why your .exr doesn't work?

The solutions is simple: delete your .exr from project, empty the Trash and after that drag-and-drop .exr file, in Choose options for adding these files window choose Add to targets:

enter image description here

Now your .exr must work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文