# Passing arrays to shader

**URL:** https://discourse.libcinder.org/t/passing-arrays-to-shader/952
**Category:** Using Cinder
**Created:** [November 15, 2017, 9:56pm UTC](https://discourse.libcinder.org/t/passing-arrays-to-shader/952 "2017-11-15T21:56:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sandblasted7](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/sandblasted7/32/675_2.png) [@sandblasted7](https://discourse.libcinder.org/u/sandblasted7)
#### Post date: [November 15, 2017, 9:56pm UTC](https://discourse.libcinder.org/t/passing-arrays-to-shader/952/1 "2017-11-15T21:56:28Z")

</div>

Hello,

I am trying to pass an array of vec2’s to my shader using an array. It is an array of the entire pixel positions. So basically an array that would look like:

```auto
vec2 arrayPixel[640][480];
int arrayPixelSize = 640* 480;

```

How would I send this array to the shader as an uniform? I am trying to use the following function in my draw() function, but I am not sure how to properly make it work.

```auto
gl::setMatricesWindow( getWindowWidth(), getWindowHeight() );
gl::translate( getWindowCenter() );
gl::ScopedGlslProg glslProg( mGlsl );
mGlsl->uniform("uArrayPixel", arrayPixel, arrayPixelSize); // this is showing an invalid argument error.

```

Please let me know if I am missing something. Thanks!

---

<div class="post-metadata">

### Author: ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)
#### Post date: [November 16, 2017, 4:05pm UTC](https://discourse.libcinder.org/t/passing-arrays-to-shader/952/2 "2017-11-16T16:05:42Z")

</div>

That’s way too big to be passing as a uniform. Stuff that data into a texture and read it via `texture()` or `texelFetch()` in your shader.

That aside, to answer your question, you can send array uniforms thus:

`mGlsl->uniform("uArrayPixel[n]", value)`, where `n` is the index and value is the …value.

Hope that helps,

A.

---

<div class="post-metadata">

### Author: ![sandblasted7](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/sandblasted7/32/675_2.png) [@sandblasted7](https://discourse.libcinder.org/u/sandblasted7)
#### Post date: [November 16, 2017, 4:18pm UTC](https://discourse.libcinder.org/t/passing-arrays-to-shader/952/3 "2017-11-16T16:18:55Z")

</div>

Hey @lithium, thank you for the advice! I’ll try to send the info using textures first. Regards.
