Passing arrays to shader

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:

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.

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!

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.

1 Like

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