# Error on defining uniform for PBRCustomMaterial

**URL:** <https://forum.babylonjs.com/t/error-on-defining-uniform-for-pbrcustommaterial/11435>\
**Category:** Bugs\
**Created:** [June 4, 2020, 8:35pm UTC](https://forum.babylonjs.com/t/error-on-defining-uniform-for-pbrcustommaterial/11435 "2020-06-04T20:35:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alvov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/alvov/32/2061_2.png) [@alvov](https://forum.babylonjs.com/u/alvov)\
**Post date:** [June 4, 2020, 8:35pm UTC](https://forum.babylonjs.com/t/error-on-defining-uniform-for-pbrcustommaterial/11435/1 "2020-06-04T20:35:49Z")

</div>

Hello!  
It seems that after the refactoring of PBR fragment shader code the order of `#define CUSTOM_FRAGMENT_...` blocks inside of it got broken.  
For example, now this block:

```auto
#define CUSTOM_FRAGMENT_UPDATE_ALBEDO

```

comes before that block:

```auto
#define CUSTOM_FRAGMENT_DEFINITIONS

```

So since custom uniforms have to be defined in the latter block, while being used in the first block, shader fails to compile with `FRAGMENT SHADER ERROR: undeclared identifier` error.

Please check [Babylon.js Playground](https://www.babylonjs-playground.com/#W465G3) for the reference. There’s an error with the latest version of BJS, while with v.4.1.0 everything works fine.

---

<div class="post-metadata">

**Author:** ![alvov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/alvov/32/2061_2.png) [@alvov](https://forum.babylonjs.com/u/alvov)\
**Post date:** [June 4, 2020, 8:37pm UTC](https://forum.babylonjs.com/t/error-on-defining-uniform-for-pbrcustommaterial/11435/2 "2020-06-04T20:37:20Z")

</div>

At first glance possible fix could be to move the

```auto
#define CUSTOM_FRAGMENT_DEFINITIONS

```

block to the next line after

```auto
precision highp float;

```

but I might be missing something.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [June 4, 2020, 9:13pm UTC](https://forum.babylonjs.com/t/error-on-defining-uniform-for-pbrcustommaterial/11435/3 "2020-06-04T21:13:20Z")

</div>

pinging @Evgeni_Popov

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 4, 2020, 9:41pm UTC](https://forum.babylonjs.com/t/error-on-defining-uniform-for-pbrcustommaterial/11435/4 "2020-06-04T21:41:59Z")

</div>

Thanks for the report, fixed by:

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

---

<div class="post-metadata">

**Author:** ![alvov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/alvov/32/2061_2.png) [@alvov](https://forum.babylonjs.com/u/alvov)\
**Post date:** [June 10, 2020, 8:05am UTC](https://forum.babylonjs.com/t/error-on-defining-uniform-for-pbrcustommaterial/11435/5 "2020-06-10T08:05:10Z")

</div>

i can confirm that it was fixed in 4.2.0-alpha.19, thanks a lot!
