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

MeshRefractionMaterial buggy when used on multiple meshes #1058

Open
philly-d opened this issue Sep 22, 2022 · 0 comments
Open

MeshRefractionMaterial buggy when used on multiple meshes #1058

philly-d opened this issue Sep 22, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@philly-d
Copy link

The new MeshRefractionMaterial is awesome - thanks for open-sourcing it!

Problem description:

The new material is working great, except something weird happens when it's used in a scene multiple times with different models. It's hard to explain without a demo, so here's a sandbox link. You can see that the second diamond model appears inside the first.
image

Relevant code:

It looks like the issue is that the bvh uniform on the shader is reused across instances of the material (I don't think it gets cloned during instantiation like other Three.js uniform types)

Suggested solution:

Creating an instance of the bvh uniform inside the MeshRefractionMaterial component with useMemo and passing it to the shader material as a prop resolves the issue for me. You can see this by setting fix = true on line 17 of the sandbox

  • three version: 0.144.0
  • @react-three/fiber version: 8.8.1
  • @react-three/drei version: 9.32.0
  • node version: 16.14.0
  • yarn version: 1.22.17
@philly-d philly-d added the bug Something isn't working label Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant