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

Drei MeshPortalMaterial with GlobalCanvas not displaying correctly #32

Open
CadotV opened this issue Nov 28, 2023 · 3 comments
Open

Drei MeshPortalMaterial with GlobalCanvas not displaying correctly #32

CadotV opened this issue Nov 28, 2023 · 3 comments

Comments

@CadotV
Copy link

CadotV commented Nov 28, 2023

When using components directly inside the GlobalCanvas (without useCanvas hook or scrollScene), the meshPortalMaterial only display after saving the file by adding / removing another mesh.

I tried enabling all layers for the main camera, and some few things with gl but without success.

Might be the default render loop from the GlobalRenderer, but i'm a noob with Three.

Here is a repo to see it in action by comment/uncomment the sphere mesh.

codesandbox

@ffdead
Copy link
Member

ffdead commented Nov 29, 2023

Thanks for reporting!

Haven't tried this material but will look into it and report back ⏳

@ffdead
Copy link
Member

ffdead commented Nov 30, 2023

Hi @CadotV - check this out:

https://codesandbox.io/p/devbox/r3f-scroll-rig-with-meshportalmaterial-bug-forked-mrzdll

It seems the createPortal() call inside RenderTexture runs first with the original default camera, before GlobalCanvas has updated the r3f state with the new camera from the scroll-rig.

The r3f state gets updated with the correct camera after the first render - but at that point the state enclave for createPortal does not update to reflect it.

The sandbox above uses a dirty workaround by forcing a re-mount with the updated camera to make the children visible:

<MeshPortalMaterial
            key={camera.fov} // force re-mount with proper camera
            blend={0.1}
            blur={0.1}
            transparent
            renderPriority={1001} // render after globalcanvas to enable blend
>

@ffdead
Copy link
Member

ffdead commented Nov 30, 2023

@CodyJasonBennett or @drcmda do you know a better way to override the default camera before any createPortal runs?

Currently we call set in a useLayoutEffect:
https://github.com/14islands/r3f-scroll-rig/blob/master/src/components/PerspectiveCamera.tsx#L60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants