-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
instancedMesh + postprocessing + Suspense Heisenbug #215
Comments
It looks like the issue is related to the Normal Pass. Here's a version of the Codesandbox that works with the normal pass commented out. Is it possible it has something to do with the fact that the NormalPass uses a material that always sets I'm a little over my head, but reading around the area in three.js where the TypeError is thrown (renders/webgl/WebGLBindingStates.js:L295) it looks like cc @drcmda |
Yes, that's probably it - I haven't seen Enabling the override material workaround fixes the issue: https://codesandbox.io/s/r3f-bug-fix-standardeffects-btfxe?file=/src/StandardEffects.js |
I found that moving the |
suspense is just for fetching the smaa textures. they load async, so the suspense block may conclude after the other scene stuff. moving box out means that "box" exists immediately while effects needs some time until the fetch request is through. |
Thanks for the fast response! This will definitely help patch things in the short term. Part of the weirdness is definitely related to Suspense, but I don't think it's an issue with it being experimental... I would guess it's more to do with the way that the react-three-fiber reconciler adds new objects to the scene (when the Suspense resolves) after rendering has already started (or replaces existing objects if the fallback is not null). @vanruesc is there anything about the way the Normal Pass is set up that relies on objects / materials already existing at the time the constructor is called? (@drcmda is this line of reasoning way off base?) |
Thanks for the additional information. Three compiles override materials based on which mesh gets rendered first. I should've been more precise when I said that moving the Box out of the Suspense "fixes" it. My guess is that this causes the Box to be rendered before the Particles which means that the override material is compiled against the simple mesh. The error disappears because The only real solution for scenes that use a mix of instanced, skinned and common meshes is to enable the override material workaround which assigns individual override materials to different types of meshes. |
Aha! That makes perfect sense. Thanks for explaining. I'm not sure there is a bug then, per se, aside from documenting the issue. unless you think that three should be able to handle the case in which the override material is compiled against the instanced mesh, without throwing an error? |
@vanruesc should i enable the workaround by default in the abstractions? does it have any downsides? there's standardeffects in a lib we publish called "drei" but there's also react-postprocessing which is in the works, a react specific wrapper for all of pp's effects. |
I think the override material system should be replaced with MRT support and more flexible, extendable built-in materials.
Well, it depends on the use case. If you have a scene that only contains static meshes, then the override material mechanism is the most efficient solution. In reality, however, scenes often contain static meshes as well as instanced or skinned meshes and in this case the global override material solution completely fails. I recommend enabling the workaround. |
I am running into a bizarre bug that has something to do with the interaction of 3 components in react-three-fiber. (Per @drcmda's suggestion in pmndrs/react-three-fiber#570 (comment), I'm opening a issue here since it seems like postprocessing is a key component of the bug.)
→ Codesandbox (important section reproduced below)
Running the code throws the following error:
Here's the weird part: removing any one of
<Particles/>
(which is an instanced mesh),<Box/>
(just a regular mesh, but crucially one inside a<Suspense/>
wrapper) or<StandardEffects/>
(a drei wrapper around postprocessing) seems to fix the issue.I'm not even sure where to start debugging this one... the
TypeError
comes from three.js trying to readobject.instanceMatrix
which doesn't exist. This seems to point to an issue with InstancedMesh and postprocessing, although as I mentioned above, removing the regular mesh from inside the react-three-fiber Suspense wrapper also gets rid of the error... 🤷♂️The text was updated successfully, but these errors were encountered: