found some shader made by Yojimbo2000 here: https://codea.io/talk-archive/discussion/6772/multiple-step-colour-gradient-shader
With my currently very limited shader knowledge I’ve tried to eliminate a hardcoded value from it.
Clearly there was a reason it is hardcoded because trying to send it to the shader it doesn’t work for some reason.
Outside of the shader I’m passing the value to it just like all other things were passed to it:
local n = #Gradient.mesh.shader.gradationPositions
Gradient.mesh.shader.numberOfGradationPoints = n
inside the shader (I left the vertex part unchanged):
--fragment
[[
precision highp float;
// the number of gradation points you want to have
uniform int numberOfGradationPoints; //-- why doesn't this work?
//const int numberOfGradationPoints = 7; //-- original, the value is hardcoded, this works.
//--transition points between colours, 0.0 - 1.0
uniform float gradationPositions[numberOfGradationPoints];
uniform lowp vec4 colors[numberOfGradationPoints]; // colours to grade between
uniform float repeats;
uniform lowp sampler2D texture;
//varying lowp vec4 vColor;
varying highp vec2 vTexCoord;
varying float vDistance;
void main()
{
lowp vec4 col = colors[0];
for (int i=1; i<numberOfGradationPoints; ++i) {
col = mix(col, colors[i], smoothstep(gradationPositions[i-1], gradationPositions[i], fract(vTexCoord.y*repeats)));
}
gl_FragColor = texture2D( texture, vTexCoord ) * col;
}
]]
how would one do this?
is it because I’m trying to use the value right after ?
isn’t there some way to get an array’s length inside the shader?