Gradient with fixed number of levels

后端 未结 2 1349
陌清茗
陌清茗 2021-01-19 08:26

I drawing a set of quads. For each quad I have a defined color in a vertex of it.

E.g. now my set of quads looks like:

2条回答
  •  余生分开走
    2021-01-19 09:01

    My guess is there will be issues with the hue colours you're using and vertex interpolation (e.g. skipping some bands). Instead, maybe pass in a single channel value and calculate the hue and discrete levels (as @vesan does) within the fragment shader. I use these functions myself...

    vec3 hueToRGB(float h)
    {
        h = fract(h) * 6.0;
        vec3 rgb;
        rgb.r = clamp(abs(3.0 - h)-1.0, 0.0, 1.0);
        rgb.g = clamp(2.0 - abs(2.0 - h), 0.0, 1.0);
        rgb.b = clamp(2.0 - abs(4.0 - h), 0.0, 1.0);
        return rgb;
    }
    
    vec3 heat(float x)
    {
        return hueToRGB(2.0/3.0-(2.0/3.0)*clamp(x,0.0,1.0));
    }
    

    and then

    float discrete = floor(pass_Value * steps + 0.5) / steps; //0.5 to round
    out_Color = vec4(heat(discrete), 1.0);
    

    where in float in_Value is 0 to 1.

提交回复
热议问题