Hi All. I wonder if I can just like in the desktop GLSL pass an attribute into the shader which is an array(like vertex attribute array).
I need to write a program in Unity that deforms meshes surface based on sound spectrum input in real time.So in the typical OpenGL program I would pass on each draw call an attribute array containing the sound spectrum floats and then inside the vertex shader calculate an offset for the vertex taking as the scale factor values from the spectrum array.How can do it in Unity using GLSL ? I see that I can’t also pass a uniform that is array -something I can do in the standard OpenGL.
Thanks .
You can’t (as far as I know) pass arrays in to shaders in Unity.
You’d need to do this via script - editing the meshes vertices each frame before they get sent for rendering. It’s pretty fast to do, though.
As farfarer says, I would assume that you can assign new arrays for the standard attributes, e.g. tangents (an array of 4d vectors):
Unity - Scripting API: Mesh.tangents’
or uv2 (an array of 2d vector):
Unity - Scripting API: Mesh.uv2
In my understanding these arrays are then sent to the shader as attributes.
(Farfarer: I would say that this IS THE WAY to pass arrays in to shader in Unity.)
Arrays of uniforms are not supported by Unity as far as I know. (And the size of uniform arrays is usually limited by the GPU, in particular for mobile GPUs, thus, this wouldn’t be a feasible alternative anyways.)
The problem with both of these arrays is that they have a 1 on 1 relationship to the vertices and are not generally available to transport freeform data.
the only generally available array i could think if is pumping in a matrix4x4 beside the totally natural array naturally upon which CUDA bases too: use a texture, its nothing but a big fat array
That gives you up to 4096x4096 values on desktop or 2048x2048 on mobile
Heh, actually I hadn’t thought of passing in the values from an array as vertex attributes.
What I meant was simply using the mesh scripting interface to modify the vertex positions, rather than doing it inside the shader.