Jedi Council, I am once against asking for your support~
I have a few CustomMaterial’s in my project. Babylon will properly create the effect with the correctly generated ShaderProgram. There are some triggers occuring in my program that cause the CustomMaterial to create a new Effect without any of my CustomMaterial customizations.I can repro it locally but have had a hard time reproducing it inside of babylon playground.
- Add Plane with CustomMaterial A
- CustomMaterial A compiles
- Add Box with a plain old StandardMaterial
- Add Box to ShadowGenerator (this is causing CustomMaterial to regenerate for some reason)
- CustomMaterial A recompiles a brand new Effect with a new uniqueId, no custom uniforms, no custom code, it’s just StandardMaterial at this point
I’m not looking for answers exactly, just looking for clues maybe as to where to look next. I’m certain this is a CustomMaterial bug, or a huge misunderstanding. I have been trying to reproduce it here, Babylon.js Playground
As a side note, if I freeze the CustomMaterial it won’t bug out, but that’s a workaround to this bug as far as I can tell.
Here is a gif of the issue, Imgur Notice how when the model is loaded, the grid disappears on the image. I load the model with a StandardMaterial, but once I add the model to the shadow generator with shadowGenerator.addShadowCaster(model), it regenerates the CustomMaterial on the image. I think this is a coincidence, potentially one of many cases that can trigger it.
I know Profile - nasimiasl - Babylon.js wrote CustomMaterial but I didn’t want to ping him directly.
There are two mistakes in your PG:
- you create material B as
new BABYLON.StandardMaterial(...)
and not new MaterialB(...)
- you pass
this.scene
instead of scene
to new BABYLON.DirectionalLight
I think we will really need a repro PG to be able to find the problem.
1 Like
Alright, I’m still working on it.I figured that was the case… dang.
I got a repro on the recompilation, but in playground it doesn’t blow away all the CustomMaterial data like it does locally. I’m looking into that still. https://playground.babylonjs.com/#3LI39D#1
This recompile looks like a smell… honestly and it’s some how should lead me to the problem of blowing away my effect and making an empty one.
Ok let me know when you wanna fix anything in CustomMaterial also i think a clone bug still exist in custom material
The recompilation is expected.
It’s because when you add the box in the shadow caster list, now the material applied to the ground should handle shadow rendering: to do that, some #define
of the material are updated, leading to a recompilation.
1 Like
OK! Here we go!
CustomMaterial will always break when it’s shader gets recompiled… in 4.1.0. The issue was fixed 4 months ago here, uniforms / samplers / attributes not set in some cases · BabylonJS/Babylon.js@62f2459 · GitHub
It never made it into 4.1.0 materials library release in NPM as a patch here, babylonjs-materials - npm
I looked in my NPM package and the code is completely different, and clear why it would break…
CustomMaterial.prototype.Builder = function (shaderName, uniforms, uniformBuffers, samplers, defines) {
var _this = this;
if (this._isCreatedShader) {
return this._createdShaderName;
}
this._isCreatedShader = false;
CustomMaterial.ShaderIndexer++;
var name = "custom_" + CustomMaterial.ShaderIndexer;
this.ReviewUniform("uniform", uniforms);
this.ReviewUniform("sampler", samplers);
This is why it does not reproduce in the playground. It seems like when it would recompile none of the uniforms will be included. This makes CustomMaterial absolutely useless without the 4.2.0 release, unless I fork and fix it locally before 4.2.0 comes out of preview.
Why not just taking 4.2 drops? There are REALLY stable
1 Like
I get what you’re saying but… how is an end user supposed to know how stable a “preview” build is? If I’m launching a new product I’m going to use the LTS. I wonder if it seems reasonable to host playgrounds for both LTS and Nightly, because if it did I would have just tried it in LTS and reproduced it, and not in Nightly, and realized it had already been fixed.
It is already the case, you can change the version here:
1 Like
Sharepoint or even PowerPoint are using our preview builds if that helps:)
1 Like