Not all properties cloned when cloning ShaderMaterial

None of the base properties of Material are cloned when cloning a ShaderMaterial: is it intended?

I had a bug because I cloned a ShaderMaterial with alphaMode=12 but got alphaMode=2 in the cloned material (2=default value).

By the way, clone() is not implemented in Material (it returns null) contrary to what the doc is saying.

Yes shaderMaterial cloning is not good at all :slight_smile:

Please provide a pg that highlights the issue and I will fix the clone function

Here it is:

https://www.babylonjs-playground.com/#1OH09K#132

alphaMode / backFaceCulling values are not cloned, so the front-most cube is not rendered like the other one. You have to uncomment the last two lines to achieve the same rendering.

ok will be fixed by next nightly :slight_smile:

1 Like

I saw you did the changes, thanks!

However, I think you should also deep-copy _options and _shaderPath, else if we modify a property in these objects in one shader, all cloned instances will get the same change.

Fancy doing a PR? I can do it else

Never done it before, I will try!

1 Like

PR created:

1 Like

Just in case, as I saw a comment of you, tried to reply but could not validate: maybe you removed your comment in-between?

I had answered:

This create a shallow copy of _options object (TypeScript 2.1 ยท TypeScript).

Then, in the next block of code, I clone the properties that are arrays (the other types of property - string and boolean - are already handled by the shallow copy).

lol yeah I found the answer by myself (it as a stupid question so I removed it)