# PBR Shader Name Property

**URL:** <https://forum.babylonjs.com/t/pbr-shader-name-property/1731>\
**Category:** Questions\
**Created:** [March 6, 2019, 3:57am UTC](https://forum.babylonjs.com/t/pbr-shader-name-property/1731 "2019-03-06T03:57:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [March 6, 2019, 3:57am UTC](https://forum.babylonjs.com/t/pbr-shader-name-property/1731/1 "2019-03-06T03:57:13Z")

</div>

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

```auto
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:

```auto
        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

```auto
 protected shaderName:string = "pbr";

```

and just use that for the createEffect call:

```auto
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… 🙂

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [March 6, 2019, 4:36am UTC](https://forum.babylonjs.com/t/pbr-shader-name-property/1731/2 "2019-03-06T04:36:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [March 6, 2019, 9:55am UTC](https://forum.babylonjs.com/t/pbr-shader-name-property/1731/3 "2019-03-06T09:55:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [March 6, 2019, 1:15pm UTC](https://forum.babylonjs.com/t/pbr-shader-name-property/1731/4 "2019-03-06T13:15:21Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![MackeyK24](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mackeyk24/32/3741_2.png) [@MackeyK24](https://forum.babylonjs.com/u/MackeyK24)\
**Post date:** [March 8, 2019, 7:17am UTC](https://forum.babylonjs.com/t/pbr-shader-name-property/1731/5 "2019-03-08T07:17:32Z")

</div>

Added PR for customShaderNameResolve for PBRMaterialBase

> <https://github.com/BabylonJS/Babylon.js/pull/6035>

That should do it 🙂

---

<div class="post-metadata">

**Author:** ![Num\_T](https://avatars.discourse-cdn.com/v4/letter/n/49beb7/32.png) [@Num\_T](https://forum.babylonjs.com/u/Num_T)\
**Post date:** [April 6, 2019, 8:51pm UTC](https://forum.babylonjs.com/t/pbr-shader-name-property/1731/6 "2019-04-06T20:51:21Z")

</div>

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 ☹

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).

---

<div class="post-metadata">

**Author:** ![Num\_T](https://avatars.discourse-cdn.com/v4/letter/n/49beb7/32.png) [@Num\_T](https://forum.babylonjs.com/u/Num_T)\
**Post date:** [April 6, 2019, 10:15pm UTC](https://forum.babylonjs.com/t/pbr-shader-name-property/1731/7 "2019-04-06T22:15:22Z")

</div>

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!
