# \[WebGPU\] Unable to use StorageBuffer in PostProcess shader

**URL:** <https://forum.babylonjs.com/t/webgpu-unable-to-use-storagebuffer-in-postprocess-shader/51375>\
**Category:** Questions\
**Tags:** webgpu, wgsl, postprocessing\
**Created:** [June 16, 2024, 11:22pm UTC](https://forum.babylonjs.com/t/webgpu-unable-to-use-storagebuffer-in-postprocess-shader/51375 "2024-06-16T23:22:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Propolisa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/propolisa/32/40423_2.png) [@Propolisa](https://forum.babylonjs.com/u/Propolisa)\
**Post date:** [June 16, 2024, 11:22pm UTC](https://forum.babylonjs.com/t/webgpu-unable-to-use-storagebuffer-in-postprocess-shader/51375/1 "2024-06-16T23:22:01Z")

</div>

Hello folks! I already owe so much of my progress with Babylon to the questions and answers here. ❤ Now I’m bringing one of my own:

I am using a WGSL-flavored pixel shader for post processing in my [game](https://github.com/Propolisa/cenote) (source not yet reflecting my port to Babylon.js).

I am able to update uniforms / samplers on the `PostProcess` instance’s resulting `Effect` with the exact same API as for the `Material` class.

However, the method `setStorageBuffer` which can be used on a `Material` instance (to pass a StorageBuffer to e.g. a WGSL fragment shader) seems to be missing on `Effect`. I would like to use storage buffers to pass instance information to my pixel shader code (which is an unmodified fragment shader). How can I achieve this?

For reference, [here is a PG](https://playground.babylonjs.com/#YSZLBS#4) showing StorageBuffer working in a normal WGSL fragment shader; and [here](https://playground.babylonjs.com/#8BHKCQ#27) is a working WGSL pixel shader PostProcess.

Thanks!

Chris

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [June 17, 2024, 7:30am UTC](https://forum.babylonjs.com/t/webgpu-unable-to-use-storagebuffer-in-postprocess-shader/51375/2 "2024-06-17T07:30:39Z")

</div>

@sebavan might be able to help here. Please be patient. He’ll only be able to answer in a few days.

---

<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:** [June 17, 2024, 4:30pm UTC](https://forum.babylonjs.com/t/webgpu-unable-to-use-storagebuffer-in-postprocess-shader/51375/3 "2024-06-17T16:30:09Z")

</div>

You can use the webgpuengine function directly [https://playground.babylonjs.com/#8BHKCQ#28](https://playground.babylonjs.com/#8BHKCQ#28)

---

<div class="post-metadata">

**Author:** ![Propolisa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/propolisa/32/40423_2.png) [@Propolisa](https://forum.babylonjs.com/u/Propolisa)\
**Post date:** [June 17, 2024, 6:09pm UTC](https://forum.babylonjs.com/t/webgpu-unable-to-use-storagebuffer-in-postprocess-shader/51375/4 "2024-06-17T18:09:01Z")

</div>

Thanks @sebavan, it’s working great!

Updated the playground for anyone else it might help (working WGSL PostProcess with StorageBuffer read / write): [https://playground.babylonjs.com/#8BHKCQ#31](https://playground.babylonjs.com/#8BHKCQ#31)

---

<div class="post-metadata">

**Author:** ![Eric.J](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/eric.j/32/34502_2.png) [@Eric.J](https://forum.babylonjs.com/u/Eric.J)\
**Post date:** [July 3, 2024, 6:29am UTC](https://forum.babylonjs.com/t/webgpu-unable-to-use-storagebuffer-in-postprocess-shader/51375/5 "2024-07-03T06:29:49Z")

</div>

@sebavan  
I have another problem here. If I want to pass a matrix variable to the WGSL shader, what should I do? I’ve tried as below and none was right.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/a/4ab02a7a4c916c8a95ff0c41ee8017df7e957001.png)

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

---

<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:** [July 3, 2024, 11:29am UTC](https://forum.babylonjs.com/t/webgpu-unable-to-use-storagebuffer-in-postprocess-shader/51375/6 "2024-07-03T11:29:50Z")

</div>

What’s the problem with the PG?

If you uncomment line 51, it does work as expected for me.

Note that if you want to access `viewMat2` in your code, you must use the syntax `uniforms.viewMat2`.

Also, you don’t have to call `camera.attachPostProcess(shader)`, as you passed the camera to the post process constructor: the post process is already attached to the camera. By doing this call, you attach the post process two times to the camera.

---

<div class="post-metadata">

**Author:** ![Eric.J](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/eric.j/32/34502_2.png) [@Eric.J](https://forum.babylonjs.com/u/Eric.J)\
**Post date:** [July 3, 2024, 12:32pm UTC](https://forum.babylonjs.com/t/webgpu-unable-to-use-storagebuffer-in-postprocess-shader/51375/7 "2024-07-03T12:32:34Z")

</div>

@Evgeni_Popov  
Thank you for your reply!

Actually I was confused about the syntax. “uniform viewMat2” seems to be GLSL language. When I wrote “var viewMat3” there will be some error messages.

And I didn’t find the “uniforms.viewMat2” syntax. Did I miss something in the documentation?

---

<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:** [July 3, 2024, 1:48pm UTC](https://forum.babylonjs.com/t/webgpu-unable-to-use-storagebuffer-in-postprocess-shader/51375/8 "2024-07-03T13:48:28Z")

</div>

This page also applies to post-processes written in WGSL:

[https://doc.babylonjs.com/setup/support/webGPU/webGPUWGSL](https://doc.babylonjs.com/setup/support/webGPU/webGPUWGSL)

I created a PR to make it clear:

> <https://github.com/BabylonJS/Documentation/pull/1160>

---

<div class="post-metadata">

**Author:** ![Eric.J](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/eric.j/32/34502_2.png) [@Eric.J](https://forum.babylonjs.com/u/Eric.J)\
**Post date:** [July 3, 2024, 1:57pm UTC](https://forum.babylonjs.com/t/webgpu-unable-to-use-storagebuffer-in-postprocess-shader/51375/9 "2024-07-03T13:57:58Z")

</div>

Great!
