Clip plane affects two subsequent meshes which share material

Please check the PG

How to reproduce:

  1. Create some mesh
  2. Apply a clip plane to it (via onBeforeRenderObservable/onAfterRenderObservable)
  3. Create a clone of this mesh (by default it would share the material with the source mesh)
  4. Apply another clip plane to it

For some reason, the source mesh clip plane also affects the cloned mesh, while the clip plane of the cloned mesh doesn’t seem to take effect at all.

Clip planes begin to work correctly when some other mesh is created before cloning the source mesh. In the PG this can be viewed by zooming camera in and out: when third sphere comes into view, both clip planes work as expected.

I guess this bug only appears when two meshes which share the same material are being rendered subsequently (thus the clip plane gets “cached” somewhere), but that’s just a guess.

P.S. Can also be reproduced with BJS 4.2.1.

cc @sebavan

In your case, I would advise to also clone the material

Currently we consider the clip planes as part of the material cache for perf reasons and as this is not used often in this way I would prefer that you clone it vs rebinding them most of the time in case the values are updated in observables.

Would that work for you ?

Ok, got it.

Yeah, in that case cloning the material would be the easiest option (I have <10 meshes like these).

Thank you!

1 Like