Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check autoClear for RTT to fix utility layer on native OpenXR #12774

Merged
merged 1 commit into from
Jul 21, 2022

Conversation

rgerd
Copy link
Member

@rgerd rgerd commented Jul 20, 2022

Illustration showing left and right eyes in a HoloLens 2 running BabylonNative:
stereo-clear-artifacts

fixes BabylonJS/BabylonNative#1087

There were two issues going on here. The first is that we needed to render the utility layer after rendering to both eyes in the target scene. By rendering the utility layer scene in between eye renders, we were getting weird clearing behavior that is hard to describe. The second is that we were double-clearing our output render target textures in cases where RenderTargetTexture.skipInitialClear = false.

By changing the observable used in utilityLayerRenderer from onAfterCameraRenderObservable to onAfterRenderCameraObservable, we're making sure to render the layer only once after finishing both eyes (instead of after the left and before the right and then again after both eyes). This doesn't meaningfully change any behavior in rendering scenarios with cameras without sub-cameras.

By checking Scene.autoClear when clearing the camera's output render target, we avoid clearing our render targets when rendering multiple scenes that are supposed to layer onto those render targets. This means that clearing behavior when rendering a scene to a render target matches the clearing behavior when rendering that same scene to the default frame buffer. This is a breaking change for experiences that expected the scene not to honor autoClear = false when rendering to a RTT, but this is not documented/expected behavior as far as I know.

We weren't seeing this bug in any other scenario (i.e. Oculus on Web, native iOS, native Android, etc) because on all other platforms RenderTargetTexture.skipInitialClear = true, and so we never saw any weird clearing behavior because the RTT's were never getting cleared in the first place, which on those platforms is totally acceptable because they get automatically cleared by either the WebXR runtime or the BabylonNative XR implementation at the top of the frame.

@rgerd rgerd requested a review from RaananW July 20, 2022 20:02
@azure-pipelines
Copy link

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@azure-pipelines
Copy link

@sebavan
Copy link
Member

sebavan commented Jul 20, 2022

LGTM but will wait on @RaananW to validate :-)

@rgerd rgerd added the bug label Jul 20, 2022
Copy link
Member

@RaananW RaananW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great changes!

@RaananW RaananW merged commit 160d054 into BabylonJS:master Jul 21, 2022
@rgerd rgerd deleted the utility-layer-xr-clear-fix branch August 1, 2022 22:57
RaananW pushed a commit that referenced this pull request Dec 9, 2022
Former-commit-id: 3faa363da681e0de8a7567594d9bd5f906053298
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken clearing in right eye on HL2 when rendering utility layer
3 participants