Check autoClear for RTT to fix utility layer on native OpenXR #12774
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Illustration showing left and right eyes in a HoloLens 2 running BabylonNative:
![stereo-clear-artifacts](https://user-images.githubusercontent.com/4724014/180064594-238f7fc0-6b3f-4aeb-bd45-9c7e5244362b.png)
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
fromonAfterCameraRenderObservable
toonAfterRenderCameraObservable
, 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 honorautoClear = 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.