0

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.

Hal T
  • 527
  • 7
  • 22
  • WebGL or Three.js? The answer will be different. You don't need a file for a texture. https://stackoverflow.com/a/19719654/128511 – gman Jun 25 '18 at 23:15
  • That solves my problem, if you'd like to make that an answer I can mark it. – Hal T Jun 26 '18 at 21:24

0 Answers0