I am looking for some way how to get smooth gradient with fragment shader. I have palette with 11
colors and value
which used to define color (it lays in range from 0.0
to 1.0
).
I am trying to get smooth color translation with such fragment shader
:
#version 150 core
in float value;
uniform vec3 colors[11];
out vec4 out_Color;
void main(void)
{
int index = int(round(value * 10));
int floorIndex = 0;
if (index != 0) floorIndex = index - 1;
out_Color = vec4(mix(colors[floorIndex], colors[index], value), 1.0f);
}
But using such approach I could get only stepped colors distribution.
And my desirable result looks like:
I know how to get this with path-through shader just passing color as attribute, but this is not that way. I am going to get such smooth distribution with single float value passed to fragment shader
.