V
V
Vitaly Stolyarov2017-09-06 19:17:52
Graphic arts
Vitaly Stolyarov, 2017-09-06 19:17:52

Gradient on GLSL with variable number of colors?

How to make such a gradient?
There are no problems with the usual option for full screen and two colors (example of a radial one)

attribute vec2 position;
uniform vec2 resolution;
varying lowp vec2 coord;
void main(void) {
vec2 np = position/resolution;
np.x=np.x*2.0-1.0;
np.y=1.0-np.y*2.0;
coord = np;
gl_Position = vec4(np, 0.0, 1.0);
}

varying lowp vec2 coord;
uniform mediump vec3 color1;
uniform mediump vec3 color2;
void main(void) {
lowp float inten = sqrt(coord.x*coord.x+coord.y*coord.y);
mediump vec3 color = color1 * inten + color2 * (1.0 - inten);
gl_FragColor = vec4(color,1.0);
}

How can I make color start points and a variable number of them?
For example, the above is standard for 0% color1, 100% color2, and it is necessary with support for intermediate colors

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question