Render a 3D model (hair) with semi-transparent texture in SceneKit?

后端 未结 1 1468
孤独总比滥情好
孤独总比滥情好 2021-01-15 19:38

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):

相关标签:
1条回答
  • 2021-01-15 20:08

    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
    
    0 讨论(0)
提交回复
热议问题