# ShaderToy using BufferA as input to Buffer A

**URL:** <https://forum.babylonjs.com/t/shadertoy-using-buffera-as-input-to-buffer-a/27681>\
**Category:** Questions\
**Created:** [February 15, 2022, 4:51pm UTC](https://forum.babylonjs.com/t/shadertoy-using-buffera-as-input-to-buffer-a/27681 "2022-02-15T16:51:39Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [March 12, 2023, 1:26pm UTC](https://forum.babylonjs.com/t/shadertoy-using-buffera-as-input-to-buffer-a/27681/21 "2023-03-12T13:26:36Z")

</div>

I managed to make the screen to texture conversion as you can see here:

> **[Babylon.js Playground](https://playground.babylonjs.com/#4C900K%2344)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Thank you both @sebavan and @Evgeni_Popov for your help, this is exactly what I wanted!

During my progress I noticed something weird, if you have the uniform “world” in the shader uniform array, the shader is not working anymore as expected. On the contrary, you have to indicate “worldViewProjection” in the array. I don’t know if it is a bug or something willing.

The [ShaderMaterial documentation](https://doc.babylonjs.com/features/featuresDeepDive/materials/shaders/shaderMaterial) do precise that:

`worldViewProjection` **must** be declared in the Vertex Shader as type `mat4` and **must** be in the `uniforms` array

but nothing concerning the “world” uniform.

Hope that helps 😉

---

<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:** [March 12, 2023, 2:55pm UTC](https://forum.babylonjs.com/t/shadertoy-using-buffera-as-input-to-buffer-a/27681/22 "2023-03-12T14:55:19Z")

</div>

You must declare in the uniform array the uniforms you are using in your shader:

```plaintext
            worldPos = world * vec4(position, 1.0);
    	    gl_Position = worldViewProjection * vec4(position, 1.0);

```

You use `world` and `worldViewProjection`, so they should be in the list of the uniforms.

However, `worldPos` is not used, so `world` is not really needed: you should remove the line which computes it and from the `uniform mat4 world, viewProjection, view, worldViewProjection;` declaration. You can also remove `view` and `viewProjection` as they are not used.

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [March 20, 2023, 4:17pm UTC](https://forum.babylonjs.com/t/shadertoy-using-buffera-as-input-to-buffer-a/27681/23 "2023-03-20T16:17:40Z")

</div>

Hello, I come back because I still have some issues with uniforms, unfortunately.

As you can see in [this playground](https://playground.babylonjs.com/#4C900K#53), I am using the uniform `world` in my shader code. But if I put it in the shader uniform array (see line 153), the shader mouse computation is broken.

Testing the code I realized that my shader also works using `viewProjection` instead of `world`. But again if I put `viewProjection` in the shader uniform array, it stops working.

I think I need more explanations on how to use uniforms. I read the documentation again and found nothing to explain what I experience but I will continue to dig in. 🫣

---

<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:** [March 20, 2023, 5:33pm UTC](https://forum.babylonjs.com/t/shadertoy-using-buffera-as-input-to-buffer-a/27681/24 "2023-03-20T17:33:48Z")

</div>

Actually, putting `world` in the uniform array is what you should do, else a wrong value for `world` is passed to the shader.

Using Spector:

- not adding `world` in the list:  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/d/8d959d9cdacae0e1d451132152f8fc3a42220aff.png)  
=\> empty matrix in `world`

- adding `world` in the list:  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/8/b8acee2b77c1fb08716321c477b8aaa2bcb56427.png)  
=\> identity matrix in `world`

You must have a bug somewhere in the shader if passing the identity matrix makes it break.

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [March 20, 2023, 7:18pm UTC](https://forum.babylonjs.com/t/shadertoy-using-buffera-as-input-to-buffer-a/27681/25 "2023-03-20T19:18:16Z")

</div>

Okayyyyy, this is actually way simpler than I thought:

> **[Babylon.js Playground](https://playground.babylonjs.com/#4C900K%2354)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Thanks, I now understand way better how uniforms must be managed!

---

<div class="post-metadata">

**Author:** ![PichouPichou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pichoupichou/32/316_2.png) [@PichouPichou](https://forum.babylonjs.com/u/PichouPichou)\
**Post date:** [March 28, 2023, 10:22pm UTC](https://forum.babylonjs.com/t/shadertoy-using-buffera-as-input-to-buffer-a/27681/26 "2023-03-28T22:22:28Z")

</div>

I am in front of a new issue: I can’t manage to deal with screen resizing and keeping the correct mouse position.  
[https://playground.babylonjs.com/#4C900K#57](https://playground.babylonjs.com/#4C900K#57) (Line 161)

I use the `rtt.resize` function and update the resolution uniform in all glsl code but if I resize the canvas window, I get an offset with the mouse.  
Should I also do something with the effect renderer maybe?

I also tried to check the scene SpectorJS but no clue.

Cheers 😉

---

<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:** [March 29, 2023, 10:52am UTC](https://forum.babylonjs.com/t/shadertoy-using-buffera-as-input-to-buffer-a/27681/27 "2023-03-29T10:52:04Z")

</div>

Don’t do `eWrapper.effect.setVector2("resolution", new BABYLON.Vector3(width, height))` in `engine.onResizeObservable`, `eWrapper.effect` is invalid in this function (it can only be used in the `eWrapper.onApplyObservable` observable):

> **[Babylon.js Playground](https://playground.babylonjs.com/#4C900K%2358)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

[Previous page](https://forum.babylonjs.com/t/shadertoy-using-buffera-as-input-to-buffer-a/27681.md?page=1)
