My project environment must be in mixed mode. When I use code to control OpacityComponent to fade Entity in and out, occasionally the gradient model outline area will appear with video penetration. What is the reason and how can it be resolved?
There is a video penetration issue in the gradient area。
Hi @MaoChao
I need a bit more detail to help you. Can you put together a minimal reproduction and share the code here? Ideally a single-file RealityView with one entity, one material, and the opacity animation that triggers the artifact, with nothing else in the scene.
Alternatively please file a feedback request using feedback assistant and include a video of the behavior and code to reproduce it.
Hello, this issue occurs occasionally, not 100%. There have been about two out of ten runs where the problem occurred. I cannot reproduce the problem 100% through short projects and code. But the good news is that I caught a screenshot of the problem, as shown in the picture. Could you please take a look.
The correct situation is that when the model fades out, the full screen gradually turns black. However, when the model disappears, the outline of the model incorrectly displays the real environment image that the video penetrates.
My model fading code looks like this:
public func FadeOutEntity(
entity:Entity,
duration: TimeInterval = 1.0,
completion: (() -> Void)? = nil
) {
if entity.components[OpacityComponent.self] == nil {
entity.components.set(OpacityComponent(opacity: 1))
}
else{
entity.components[OpacityComponent.self]?.opacity = 1
}
let action = FromToByAction<Float>(
from: 1,
to: 0,
timing: .easeInOut
)
do {
let anim = try AnimationResource.makeActionAnimation(
for: action,
duration: duration,
bindTarget: .opacity
)
entity.playAnimation(anim)
DispatchQueue.main.asyncAfter(deadline: .now() + duration) {
entity.stopAllAnimations()
self.EnableEntity(entity: entity,isEnabled: false)
completion?()
}
} catch {
entity.stopAllAnimations()
EnableEntity(entity: entity,isEnabled: false)
completion?()
}
}
Hi @MaoChao
Thanks, the screenshots are very helpful. This behavior is not expected.
One question first, so I understand the setup. Where is the black background coming from? You mentioned mixed immersion, but in mixed immersion the system should not hide passthrough at all (the system should not show a black background). Which of these best matches your setup?
- A Progressive immersive space with the Digital Crown turned all the way up
- A Full immersive space
- A black skybox entity you added to the scene yourself (for example, a large black sphere or box)
- Something else
Either way, this looks like a rendering bug worth reporting. Please file a report with Feedback Assistant and include a link to this forum post. Please reply here with the feedback number.
Hi @MaoChao
I'm unable to reproduce this using the latest visionOS 27. Here's the code I tried:
struct ImmersiveView: View {
var body: some View {
RealityView { content in
// Skybox (tap to toggle cube fade)
let skyboxRadius: Float = 50
var skyMaterial = UnlitMaterial(
color: UIColor(red: 0.15, green: 0.35, blue: 0.55, alpha: 1.0)
)
skyMaterial.faceCulling = .front
let skybox = ModelEntity(
mesh: .generateSphere(radius: skyboxRadius),
materials: [skyMaterial]
)
skybox.components.set(
CollisionComponent(shapes: [.generateSphere(radius: skyboxRadius)])
)
skybox.components.set(InputTargetComponent())
content.add(skybox)
let cube = ModelEntity(
mesh: .generateBox(size: 0.3),
materials: [SimpleMaterial(color: .orange, isMetallic: false)]
)
cube.name = "FadeCube"
cube.position = [0.9, 1.3, -1.2] // to the right of center
cube.components.set(OpacityComponent(opacity: 1.0))
content.add(cube)
// Wire the skybox tap to toggle the cube's fade.
skybox.components.set(
GestureComponent(
SpatialTapGesture()
.targetedToAnyEntity()
.onEnded { _ in
toggleFade(on: cube)
}
)
)
}
}
private func toggleFade(on entity: Entity) {
let current = entity.components[OpacityComponent.self]?.opacity ?? 1.0
let target: Float = current > 0.5 ? 0.0 : 1.0
Entity.animate(.easeInOut(duration: 1.5)) {
entity.components[OpacityComponent.self]?.opacity = target
}
}
}
Are you able to reproduce the issue using this snippet? I realize you mentioned it's intermittent. Would you mind filing a bug using Feedback Assistant (at https://feedbackassistant.apple.com/)?