在 SceneKit 中渲染具有半透明纹理的 3D 模型(头发)? [英] Render a 3D model (hair) with semi-transparent texture in SceneKit?

查看:23
本文介绍了在 SceneKit 中渲染具有半透明纹理的 3D 模型(头发)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 SceneKit 中渲染 3D 模型,但它看起来不正确.例如这个

如果我关闭写入深度"选项,它将如下所示:但也有一些问题,因为我只看到了最底层"的发型.

我认为这应该是可能的.怎么做才对?

解决方案

在你的 3D 模型中,当从不同角度观看时,一些头发会弹出的原因对于 SceneKit 来说是很常见的:你的模型具有 SceneKit 的半透明材料由于某些内部

let scene = SCNScene(named: "art.scnassets/Hair.scn")!let hair = scene.rootNode.childNode(withName: "MDL_OBJ", recursively: true)!hair.geometry?.firstMaterial?.transparencyMode = SCNTransparencyMode.dualLayer

解决方案 2:

头发束不能是单一几何体,而必须是复合几何体(由多个几何体层组成,统一为一组).

hair.geometry?.firstMaterial?.colorBufferWriteMask = SCNColorMask.allhair.geometry?.firstMaterial?.readsFromDepthBuffer = falsehair.geometry?.firstMaterial?.writesToDepthBuffer = falsehair.geometry?.firstMaterial?.blendMode = SCNBlendMode.alpha

I'm trying to render a 3D model in SceneKit but it looks incorrect. For example this model (it's an SCN file with texture and you can reproduce it in your Xcode):

In Xcode Scene Editor it is rendered like this:

Transparency -> Mode -> Dual Layer
Double Sided = true

If I turn off the "Write depth" option, it will look like this: But there are also some issues because it I see only "the lowest layer" of haircut.

I think this should be possible. How to do it right?

解决方案

The reason that in your 3D model some strands of hair popped out when viewed from different angles is quite usual for SceneKit: your model has semi-transparent material that SceneKit can't render properly due to some inner engine rendering techniques (time 49:35) applied to depth buffer.

In order to deal with this problem there are two solutions:

Solution 1:

Your 3D model must have a completely opaque texture (without semi-transparent parts at all). In that case use .dualLayer property.

let scene = SCNScene(named: "art.scnassets/Hair.scn")!
let hair = scene.rootNode.childNode(withName: "MDL_OBJ", recursively: true)!

hair.geometry?.firstMaterial?.transparencyMode = SCNTransparencyMode.dualLayer

Solution 2:

Strands of hair mustn't be a mono-geometry but must be a compound geometry (consisted of several geometry layers unified in one group).

hair.geometry?.firstMaterial?.colorBufferWriteMask = SCNColorMask.all
hair.geometry?.firstMaterial?.readsFromDepthBuffer = false
hair.geometry?.firstMaterial?.writesToDepthBuffer = false
hair.geometry?.firstMaterial?.blendMode = SCNBlendMode.alpha

这篇关于在 SceneKit 中渲染具有半透明纹理的 3D 模型(头发)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆