PBR Shader Name Property

Yo @Deltakosh … Can we please give the PBRMaterialBase as shader name property so we can subclass a PBR Shader and just have a custom pbr.fragment.fx and vertex.fx that we loaded in into the shaderstore.

I have to make a Terrain Splatmap shader for PBR Metallic and Specular as well as Standard materials… I will use the same texture properties but i just to apply my tweeks to the glsl shaders…

If we add a Shader name property then we can easily go

class MyCustomPBR extends BABYLON.PBRMaterial {
  public constructor(...) {
    this.shaderName = "my_pbr";
 }

and have the easiest Custom PBR Shaders Ever… The Same thing with StandardMaterial.

And all we really have to do is change one call from using a hard coded “pbr” in the create effect at the end of the PBRMaterialBase _prepareEffect function:

        return engine.createEffect("pbr", <EffectCreationOptions>{
            attributes: attribs,
            uniformsNames: uniforms,
            uniformBuffersNames: uniformBuffers,
            samplers: samplers,
            defines: join,
            fallbacks: fallbacks,
            onCompiled: onCompiled,
            onError: onError,
            indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS }
        }, engine);

we add a protected shaderName to the PBRMaterialClass that our SUBCLASSES can set on construction

 protected shaderName:string = "pbr";

and just use that for the createEffect call:

return engine.createEffect(this.shaderName, <EffectCreationOptions>{
            attributes: attribs,
            uniformsNames: uniforms,
            uniformBuffersNames: uniformBuffers,
            samplers: samplers,
            defines: join,
            fallbacks: fallbacks,
            onCompiled: onCompiled,
            onError: onError,
            indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS }
        }, engine);

That should not negatively impact the codebase but give us the ability to write custom shaders WITHOUT having to COPY the whole PBR set of classes and changing the name EVERYWHERE just to supply a custom fragment and vertex program name to use for MY MATERIAL subclass…

What do think… PLEASE SAY YES… :slight_smile:

I think i get what you are saying but how would you manage the glsl side of it? Are you planning to inject custom sections like the CustomMaterial does or are you talking about writing whole custom PBR shaders that you pass to this?

Hey @Pryme8 … Im talking a whole custom pbr.vertex.fx and pbr.fragment.fx

I do the same thing for StandardMaterial… But it was a bit easier after i found
customShaderNameResolve on the StandardMaterial… That worked great
before in the last toolkit. but i need a way to specify the shader program for PBR as well

@MackeyK24 feel free to make a PR for this. Can I ask what you are customizing in the shader ? I am thinking about material customization at the moment and would be interested to know more about your use case.

Added PR for customShaderNameResolve for PBRMaterialBase

That should do it :slight_smile:

I really want to try an use this myself but I’m getting an error in the console telling me that BABYLON.MyCustomPBR is not a constructor. I imagine I may be doing something obvious wrong but it’s beyond me unfortunately :frowning:

Edit: ah it was obvious - MyCustomPBR isn’t in the BABYLON namespace (module? I’m from a C# background). Anyway, on to the next error for me - TextureTools is not defined, I’m hoping because I haven’t setup my glsl files yet).

Arrrgg. I’m almost there - I just can’t work out how to associate my new material type with my fx files. Where is the path resolved - I’ve tried popping my copies in the same place as my index.html but unsurprisingly that hasn’t worked!