# \`VERTEX SHADER ERROR: 0:222: 'world' : redefinition\` errors appeared in my own shader MToonMaterial

**URL:** <https://forum.babylonjs.com/t/vertex-shader-error-0-world-redefinition-errors-appeared-in-my-own-shader-mtoonmaterial/21665>\
**Category:** Bugs\
**Tags:** material, shader\
**Created:** [June 14, 2021, 1:29pm UTC](https://forum.babylonjs.com/t/vertex-shader-error-0-world-redefinition-errors-appeared-in-my-own-shader-mtoonmaterial/21665 "2021-06-14T13:29:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![il-m-yamagishi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/il-m-yamagishi/32/2378_2.png) [@il-m-yamagishi](https://forum.babylonjs.com/u/il-m-yamagishi)\
**Post date:** [June 14, 2021, 1:29pm UTC](https://forum.babylonjs.com/t/vertex-shader-error-0-world-redefinition-errors-appeared-in-my-own-shader-mtoonmaterial/21665/1 "2021-06-14T13:29:00Z")

</div>

[details are at GitHub issue virtual-cast/babylon-mtoon-material#66](https://github.com/virtual-cast/babylon-mtoon-material/issues/66).

This bugs may be caused by `meshUboDeclaration` or `instancesDeclaration` or something.

I’m waiting for any help.

---

<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 14, 2021, 2:01pm UTC](https://forum.babylonjs.com/t/vertex-shader-error-0-world-redefinition-errors-appeared-in-my-own-shader-mtoonmaterial/21665/2 "2021-06-14T14:01:48Z")

</div>

I think you want to rename the files:

- `ubo-declaration` =\> `mtoonUboDeclaration`
- `vertex-declaration` =\> `mtoonVertexDeclaration`
- `fragment-declaration` =\> `mtoonFragmentDeclaration`

When using `#include< __decl__ mtoonVertex>`, the system is removing ` __decl__ ` and is replacing `Vertex` by `UboDeclaration` if the engine supports `Ubo` or by `VertexDeclaration` if not. Same kind of transformations for `#include< __decl__ mtoonFragment>`.

---

<div class="post-metadata">

**Author:** ![il-m-yamagishi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/il-m-yamagishi/32/2378_2.png) [@il-m-yamagishi](https://forum.babylonjs.com/u/il-m-yamagishi)\
**Post date:** [June 14, 2021, 2:07pm UTC](https://forum.babylonjs.com/t/vertex-shader-error-0-world-redefinition-errors-appeared-in-my-own-shader-mtoonmaterial/21665/3 "2021-06-14T14:07:09Z")

</div>

The shaders are registered at constructor.

> <https://github.com/virtual-cast/babylon-mtoon-material/blob/adopt-5.0.0-dev/src/mtoon-material.ts#L641>

Isn’t that correct?

---

<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 14, 2021, 3:19pm UTC](https://forum.babylonjs.com/t/vertex-shader-error-0-world-redefinition-errors-appeared-in-my-own-shader-mtoonmaterial/21665/4 "2021-06-14T15:19:11Z")

</div>

Yes it should work.

Are you sure you are using the updated `instancesDeclaration.fx` file? Can you `console.log` `Effect.IncludesShadersStore["instancesDeclaration"]` and make sure it’s the right one (and especially that you can see occurrences of `WORLD_UBO`).

---

<div class="post-metadata">

**Author:** ![il-m-yamagishi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/il-m-yamagishi/32/2378_2.png) [@il-m-yamagishi](https://forum.babylonjs.com/u/il-m-yamagishi)\
**Post date:** [June 15, 2021, 1:50am UTC](https://forum.babylonjs.com/t/vertex-shader-error-0-world-redefinition-errors-appeared-in-my-own-shader-mtoonmaterial/21665/5 "2021-06-15T01:50:07Z")

</div>

result of `console.log(Effect.IncludesShadersStore["instancesDeclaration"]);`. babylon.js v5.0.0-alpha.25.

```auto
#ifdef INSTANCES
attribute vec4 world0;
attribute vec4 world1;
attribute vec4 world2;
attribute vec4 world3;
#if defined(THIN_INSTANCES) && !defined(WORLD_UBO)
uniform mat4 world;
#endif
#if defined(VELOCITY) || defined(PREPASS_VELOCITY)
attribute vec4 previousWorld0;
attribute vec4 previousWorld1;
attribute vec4 previousWorld2;
attribute vec4 previousWorld3;
#ifdef THIN_INSTANCES
uniform mat4 previousWorld;
#endif
#endif
#else
#if !defined(WORLD_UBO)
uniform mat4 world;
#endif
#if defined(VELOCITY) || defined(PREPASS_VELOCITY)
uniform mat4 previousWorld;
#endif
#endif

```

I wonder `#if` preprocessor should appear in compiled vertex code, but my error vertex code does not have any `#if` declaration, only `#define` have.

Perhaps preprocessor of `#if` or `#ifdef` processing timing problem?

proprocess `#ifdef`(this timing will only define `MaterialDefine`'s `#define`) → generate `uniform mat4 world` → process `#include` and put `#define WORLD_UBO` but `#ifdef` already processed, so runtime vertex code has `uniform mat4 world`.

I tried to add `WORLD_UBO = true` to MToonMaterialDefines, it does not have error, but no mesh are rendered. And in WebGL1, `VERTEX SHADER ERROR: 0:170: 'world' : undeclared identifier` error appears.

(sorry for poor english)

---

<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 15, 2021, 9:02am UTC](https://forum.babylonjs.com/t/vertex-shader-error-0-world-redefinition-errors-appeared-in-my-own-shader-mtoonmaterial/21665/6 "2021-06-15T09:02:47Z")

</div>

There are two problems:

- the .vert and .frag files should use LF as the line separator, not CRLF
- you need to add **Mesh** in the list of uniform buffers (line 989 of _mtoon-material.ts_):
  - `const uniformBuffers = ['Material', 'Scene', 'Mesh'];`

After those changes it does work for me locally.

---

<div class="post-metadata">

**Author:** ![il-m-yamagishi](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/il-m-yamagishi/32/2378_2.png) [@il-m-yamagishi](https://forum.babylonjs.com/u/il-m-yamagishi)\
**Post date:** [June 15, 2021, 9:08am UTC](https://forum.babylonjs.com/t/vertex-shader-error-0-world-redefinition-errors-appeared-in-my-own-shader-mtoonmaterial/21665/7 "2021-06-15T09:08:36Z")

</div>

Brilliant! It works for me! Thank you so much!
