scenejs icon indicating copy to clipboard operation
scenejs copied to clipboard

uniform array doesn't work in shaders

Open KlausBlass opened this issue 10 years ago • 4 comments

Passing an array into a shader does not seem to be implemented: "uniform float values[3];",

If I just change it to
"uniform vec3 values;", I can use it without problems (so the array declaration and passing in params are fine). If I know that it is not implemented I can stop searching where I am doing something wrong...

KlausBlass avatar Dec 22 '15 14:12 KlausBlass

No, array uniforms are not supported in shaders at present (at least I hadn't even considered doing that until now).

So if passing in a vector works for you, then go with that for now and we can revisit arrays later if needed.

On Tue, Dec 22, 2015 at 3:23 PM, Klaus Blass [email protected] wrote:

Passing an array into a shader does not seem to be implemented: "uniform float values[3];",

If I just change it to

"uniform vec3 values;", I can use it without problems (so the array declaration and passing in params are fine) If I know that it is not implemented I can stop searching where I am doing something wrong

— Reply to this email directly or view it on GitHub https://github.com/xeolabs/scenejs/issues/425.

Lindsay Kay http://xeolabs.com

xeolabs avatar Dec 22 '15 14:12 xeolabs

Passing in a vector just was a test to make sure the problem wasn't somewhere else. What I need is passing a float value for each vertex in the vertex stage to determine a vertex colour which is then passed to the fragment stage. Maybe you can think of another mechanism to do that?

KlausBlass avatar Dec 23 '15 07:12 KlausBlass

Here's a short description what I am trying to do: On a grid I have a number of measurement points (say, for temperature). I want to show each temperature with a different shade of colour. Then passing it to the fragment shader this will interpolate the colour between the measured points giving a colour map showing the temperature over the entire plane covered by the grid. (works nicely for a couple of points passed in through uniform floats).

KlausBlass avatar Dec 23 '15 11:12 KlausBlass

After finding out that array uniforms are limited to at most a hundred or so elements I looked for another solution. Here's what I did: Since I only use x/y coordinates for my diagram I pass in the measurement values as the z-values of the vertices (I use a modified plane geometry). The vertex shader then uses these z-values to determine a colour which it passes to the fragment stage and substitutes a zero z-value to yield a plane. Works beautifully, if someone needs it, contact me...

KlausBlass avatar Dec 27 '15 11:12 KlausBlass