Custom material vs clones

repro: https://www.babylonjs-playground.com/#UXCB15#121

Hi, I need a little help here understanding what is happening. In the repro above, comment out cloned2 and cloned3 chunks. You will see a slow wave on clone1 and its instances. I used the render overlay to make it easier to see. Now, go ahead and uncomment cloned2 and cloned3 chunks. You will see that the wave frequency has increased, which is not what I expected. I’m trying to get cloned2 and cloned3 to display the same movement as the case when there was only cloned1 and its instances.

Can someone kindly highlight where I might have gone wrong ?

https://www.babylonjs-playground.com/#UXCB15#122
you use local position in shader for make wave
change it to world pos but in vertexshader you dont have directly world pos
you can use (mat4(world0,world1,world2,world3)*vec4(positionUpdated,1.0)).xyz

Hi @nasimiasl, I’m not sure if I understand what you are saying. If you look at this pg: https://www.babylonjs-playground.com/#UXCB15#123, the waves are much slower. This is what I want for the other clones as well. Your pg is still showing that cloned2 and cloned3 when present are much faster. In fact, if you keep adding clones + instances, the waves get even faster without doing any changes to the custom material itself. eg: https://www.babylonjs-playground.com/#UXCB15#124

1 Like

The material gets bound on each clone, and you increase the time on bind, so they will go faster

2 Likes

My bad. I have figured it out, material sharing is the culprit. Normally materials get shared across assets, there is no visible difference during rendering and I did not think twice about it. That is a mistake, it is actually a bad practice. Thanks everyone who helped ! :slight_smile:

1 Like