# Setting Array uniform on shader in webgpu?

**URL:** <https://forum.babylonjs.com/t/setting-array-uniform-on-shader-in-webgpu/42657>\
**Category:** Questions\
**Tags:** pbrcustommaterial\
**Created:** [July 23, 2023, 9:36pm UTC](https://forum.babylonjs.com/t/setting-array-uniform-on-shader-in-webgpu/42657 "2023-07-23T21:36:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [July 23, 2023, 9:36pm UTC](https://forum.babylonjs.com/t/setting-array-uniform-on-shader-in-webgpu/42657/1 "2023-07-23T21:36:22Z")

</div>

Hey team! ( @Evgeni_Popov🙏 )

Can we set a floatArray ( float[nb] ) uniform in a way that works on both webgl2 & webGPU?

I’m using the PBRCustomMaterial.  
Passing an array causes `GPUValidationError` when using webGPU.

Simplified example;

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

I’m having a tough time finding detailed documentation on uniforms, especially the different kinds, sorry if an answer already exists!

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [July 23, 2023, 10:30pm UTC](https://forum.babylonjs.com/t/setting-array-uniform-on-shader-in-webgpu/42657/2 "2023-07-23T22:30:24Z")

</div>

Okay…  
Replacing

> this.AddUniform(‘vTestArray’, ‘float[12]’);

with

> this.AddUniform(‘vTestArray[12]’, ‘float’);

seems to fix it?  
Is this OK?

---

<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 24, 2023, 11:29am UTC](https://forum.babylonjs.com/t/setting-array-uniform-on-shader-in-webgpu/42657/3 "2023-07-24T11:29:32Z")

</div>

If it works then it must be ok 🙂 (you are using the `PBRCustomMaterial` which is not in core, so I don’t really know).

If you use a material plugin or a `ShaderMaterial`, the method that let’s you define an uniform takes an array size in addition to the size of one element of the array.

---

<div class="post-metadata">

**Author:** ![aWeirdo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aweirdo/32/52_2.png) [@aWeirdo](https://forum.babylonjs.com/u/aWeirdo)\
**Post date:** [July 24, 2023, 4:49pm UTC](https://forum.babylonjs.com/t/setting-array-uniform-on-shader-in-webgpu/42657/4 "2023-07-24T16:49:05Z")

</div>

Thanks!  
My biggest concern is if it breaks randomly on different systems.

The GPUValidationError was seemingly from vulkan not liking the way the array was created.

I’ll check out the material plugins, looks very interesting!
