Reality Composer Pro | UnlitSurface and opacity maps error

Hello all -

I'm experiencing a shading error when I have two UnlitSurface shaders using images for color and opacity. When the shaders are applied to two mesh planes, one placed in front of the other, the shader in front will render and the plane mesh will mask out and not render what is behind.

Basically - it looks like the opacity map on the shader in front is creating a 'mask'.

I've attached some images here to help explain.

Has anyone experienced this error? And how can I go about fixing this - thx!

Post not yet marked as solved Up vote post of KevinTho Down vote post of KevinTho
805 views
  • Curious to see if the depth group answer solved this issue for you?

Add a Comment

Replies

Hello,

I'm not 100% confident in this diagnosis at this point, but this sounds like a rendering order issue to me, that is, the rendered result depends on which plane is drawn by the system first. If it is a rendering order issue, then you may be able to resolve this explicitly by using ModelSortGroupComponent. If that doesn't help and you don't think it is a rendering order issue, then I'd need to see the RCP project to help further.

  • I'm looking for some example of how to use ModelSortGroup. Any code snippets to share? web search come up empty.

  • Just FYI – this doesn't resolve with modelsortgroupcomponents. Like, if you're building a tree in the standard way of using cards with transparency to define leaves, etc, you'll end up with sort issues like the OP's, all over the place. And there's no way to define which order these leaves should be in – it would be completely impractical.

    Note that if you turn on 'opacity threshold' this problem disappears. But this isn't really a solution, as opacity threshold results in horrible aliasing.

Add a Comment

Do you have an example of adding a component to a ModelSortGroup and then setting the order?

something like: let myGroup = ModelSortGroup(depthPass: ModelSortGroup.DepthPass.postPass) let mySort = ModelSortGroupComponent(group: myGroup, order: 2)

How do I setup the group to let the sort order know what components to reference when I set the order?

@KevinTho any luck here? What did you learn or discover?

Thanks in advance for sharing.

Here is an example that uses ModelSortGroup:

import SwiftUI
import RealityKit

struct ContentView: View {
    
    let group = ModelSortGroup(depthPass: .postPass)

    var body: some View {
        VStack {
            RealityView { content in
                
                let innerBox = ModelEntity(mesh: .generateBox(size: 0.05), materials: [SimpleMaterial(color: .red, isMetallic: false)])
                
                let outterBox = ModelEntity(mesh: .generateBox(size: 0.1), materials: [SimpleMaterial(color: .blue, isMetallic: false)])
                
                innerBox.components.set(ModelSortGroupComponent(group: group, order: 1))
                outterBox.components.set(ModelSortGroupComponent(group: group, order: 0))
                
                innerBox.components.set(OpacityComponent(opacity: 0.5))
                outterBox.components.set(OpacityComponent(opacity: 0.5))
                
                let entity = Entity()
                entity.addChild(innerBox)
                entity.addChild(outterBox)
                            
                content.add(entity)
            }
        }
    }
}