pmndrs / drei

🥉 useful helpers for react-three-fiber
https://docs.pmnd.rs/drei
MIT License
8.38k stars 699 forks source link

MeshReflectorMaterial increases the number of geometries and textures dramatically #1777

Closed XavierYribarren closed 3 days ago

XavierYribarren commented 10 months ago

Problem description:

I've added a plane with a MeshReflectorMaterial to my scene, and when I scroll down, the number of textures and geometries increases dramatically. I know the problem comes from the material because it only happened when I added it, and 'solved' it when I removed to reflector mat.

Relevant code:

 <mesh position={[0,0,15]}>
  <planeGeometry args={[20,20,20,20]}/>
  <MeshReflectorMaterial
            blur={[400, 100]}
            resolution={1024}
            mixBlur={1}
            mixStrength={15}
            depthScale={1}
            minDepthThreshold={0.85}
            color="#151515"
            metalness={0.6}
            roughness={1}
            debug={4}
          />
 </mesh>

See the r3f-perf report below :

Capture d’écran de 2024-01-11 17-41-35

Suggested solution:

zhavoronskaya commented 4 months ago

try moving your relevant code into separate memoized component:

const ReflectorMemoized = React.memo(function ReflectorMemoized() {
  return (
    <mesh position={[0, 0, 15]}>
      <planeGeometry args={[20, 20, 20, 20]} />
      <MeshReflectorMaterial
        //...
      />
    </mesh>
  );
}, () => true);

did the trick for me

github-actions[bot] commented 1 week ago

Thank you for contributing! We’re marking this issue as stale as a gentle reminder to revisit it and give it the attention it needs to move forward.

Any activity, like adding an update or comment, will automatically remove the stale label so it stays on our radar.

Feel free to reach out on Discord if you need support or feedback from the community. This issue will close automatically soon if there’s no further activity. Thank you for understanding and for being part of the project!

github-actions[bot] commented 3 days ago

We’re closing this issue to keep our project manageable and make room for other active work, but we truly appreciate your effort and contribution.

If you’d like to continue working on this, please feel free to re-open it or reach out on Discord — our community is always ready to support you. Thanks again for helping us stay organized and for understanding our approach!