I seem to be running into an issue where the .glassBackgroundEffect modifier doesn't seem to render correctly. The issue is occurring when attached to a view shown in a RealityKit immersive view with a Skybox texture. The glass effect is applied but doesn't let any of the colour of the skybox behind it though.
I have created a sample project which is just the immersive space template with the addition of a skybox texture and an attachment with the glassBackgroundEffect modifier. The RealityView itself is
struct ImmersiveView: View {
var body: some View {
RealityView { content, attachments in
// Add the initial RealityKit content
if let immersiveContentEntity = try? await Entity(named: "Immersive", in: realityKitContentBundle) {
content.add(immersiveContentEntity)
let attachment = attachments.entity(for: "foo")!
let leftSphere = immersiveContentEntity.findEntity(named: "Sphere_Left")!
attachment.position = [0, 0.2, 0]
leftSphere.addChild(attachment)
// Add an ImageBasedLight for the immersive content
guard let resource = try? await EnvironmentResource(named: "ImageBasedLight") else { return }
let iblComponent = ImageBasedLightComponent(source: .single(resource), intensityExponent: 0.25)
immersiveContentEntity.components.set(iblComponent)
immersiveContentEntity.components.set(ImageBasedLightReceiverComponent(imageBasedLight: immersiveContentEntity))
// Put skybox here. See example in World project available at
var skyboxMaterial = UnlitMaterial()
let skyboxTexture = try! await TextureResource(named: "pano")
skyboxMaterial.color = .init(texture: .init(skyboxTexture))
let skyboxEntity = Entity()
skyboxEntity.components.set(ModelComponent(mesh: .generateSphere(radius: 1000), materials: [skyboxMaterial]))
skyboxEntity.scale *= .init(x: -1, y: 1, z: 1)
content.add(skyboxEntity)
}
} update: { _, _ in
} attachments: {
Attachment(id: "foo") {
Text("Hello")
.font(.extraLargeTitle)
.padding(48)
.glassBackgroundEffect()
}
}
}
}
The effect is shown bellow
I've tried this both in the simulator and in a physical device and get the same behaviour.
Not sure if this is an issue with RealityKit or if I'm just holding it wrong, would greatly appreciate any help. Thanks.