I'm a bit new to WebGL, and I'm trying to display something akin to a colormap. Essentially, I have a variable that's per point, and I'd like to pick a color based on that. For example:
varying float point_label;
void main()
{
vec4 fragColor = vec4(1.0, 1.0, 1.0, 1.0);
if (point_label == 0.0)
{
fragColor = vec4(1.0, 0.0, 1.0, 1.0);
}
else if (point_label == 2.0)
{
fragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
else if (point_label == 3.0)
...
...
}
In my case point_label
is [0-7]
. I was told that it's inefficient to have a long if-else statement like this. What's the most efficient way to handle this without doing so? While creating no extra files, if possible (I was recommended using a texture and a ThreeJS LUT but I'd rather not create an additional file). And yes, the label I get is a float value, but it's always going to be a natural number.