react-xr icon indicating copy to clipboard operation
react-xr copied to clipboard

@react-three/xr does not play well with @react-three/postprocessing

Open Bossieh opened this issue 3 years ago • 5 comments
trafficstars

First of all thanks a lot for this awesome library! The future is now! :D

But it seems that when I use <EffectComposer> from @react-three/postprocessing in my scene the hit testing goes wrong. There are still hit results but the position/rotation is completely wrong.

If I remove the <EffectComposer> everything works completely fine.

Versions i'm using:

  • @react-three/xr: 5.0.4
  • @react-three/postprocessing: 2.4.6
  • @react-three/fiber: 8.0.19
<XRButton
    mode="AR"
    sessionInit={{
        requiredFeatures: ['hit-test'],
        optionalFeatures: ['dom-overlay', 'dom-overlay-for-handheld-ar'],
        domOverlay: { root: document.body }
    }}
>
<Canvas
    gl={{
        preserveDrawingBuffer: true
    }}
    shadows
    frameloop="demand"
    onCreated={(rootState) => {
        rootState.camera.position.x = 12
        rootState.camera.position.y = 5
        rootState.camera.position.z = 13
    }}
>
    <XR referenceSpace="local">
        // my 3D scene
    </XR>
    <EffectComposer autoClear={false}> // this guy messes up hit testing
        <Outline
            blur
            edgeStrength={4}
            pulseSpeed={0.5}
            visibleEdgeColor={0xffffff}
            hiddenEdgeColor={0xffffff}
        />
        <SMAA />
    </EffectComposer>
</Canvas>

Bossieh avatar Oct 27 '22 07:10 Bossieh

I'm assuming you're testing on a mobile device? https://github.com/pmndrs/postprocessing doesn't formally support WebXR rendering, not yet -- I'll be implementing this once they support viewport regions.

I don't believe EffectComposer is using camera transforms from WebXR pose, which would be the only way the hit test would not be aligned. You may want to add a lambda pass and call gl.xr.updateCamera(state.camera) to keep the scene camera in sync with WebXR.

You may also be interested in taking rendering into your own hands in the meantime, see https://twitter.com/Cody_J_Bennett/status/1482585611781480448, https://codesandbox.io/s/7x7p3q.

CodyJasonBennett avatar Oct 29 '22 12:10 CodyJasonBennett

Thank you for your quick reply, yes I am testing this on a mobile device.

So if I understand correctly @react-three/postprocessing has to support XR first? If so I will open an issue about this at @react-three/postprocessing

Bossieh avatar Oct 31 '22 09:10 Bossieh

Indeed, it will need work from both @react-three/postprocessing and postprocessing.

CodyJasonBennett avatar Nov 01 '22 12:11 CodyJasonBennett

I have opened an issue at @react-three/postprocessing: https://github.com/pmndrs/postprocessing/issues/452

Bossieh avatar Nov 02 '22 10:11 Bossieh

You may also be interested in taking rendering into your own hands in the meantime, see https://twitter.com/Cody_J_Bennett/status/1482585611781480448, https://codesandbox.io/s/7x7p3q.

@CodyJasonBennett Codesandbox demo don't working now, only showing black screen.

And, useDepthBuffer of @react-three/drei get the same problem? Try get it work, but don't look correct.

#1427

hecodeit avatar May 05 '23 22:05 hecodeit

Postprocessing with threejs unfortunately does not work in WebXR. This is not related to this repository though, just a limitation of threejs.

bbohlender avatar Jul 17 '24 09:07 bbohlender