Debian Codegraph @

qCC/shaders/ColorRamp/color_ramp.frag

raw
1 #version 110
2
3 // Color Ramp Shader (CloudCompare - 04/23/2013)
4
5 uniform float uf_minSaturation; //minimum saturation value (between 0 and 1)
6 uniform float uf_maxSaturation; //maximum saturation value (between 0 and 1)
7
8 uniform float uf_colormapTable[256]; //float-packed RGB colors (max: 256)
9 uniform float uf_colormapSize; //colormap size (as a float as we only use it as a float!)
10 uniform float uf_colorGray; //color for grayed-out points
11
12 void main(void)
13 {
14 //input: gl_Color
15 // - gl_Color[0] = normalized scalar value
16 // - gl_Color[1] = flag: whether point should be grayed (< 1.0) or not (1.0)
17 // - gl_Color[2] = true lighting value
18 //output: gl_FragColor
19
20 vec3 unpackedValues = vec3(1.0, 256.0, 65536.0);
21
22 if (gl_Color[1] > 0.99) //0.99 to cope with round-off issues (in perspective mode for instance)
23 {
24 //determine position in current colormap
25 int rampPosi;
26 if (gl_Color[0] <= uf_minSaturation)
27 rampPosi = 0;
28 else if (gl_Color[0] < uf_maxSaturation)
29 rampPosi = int((gl_Color[0]-uf_minSaturation)*uf_colormapSize/(uf_maxSaturation-uf_minSaturation));
30 else
31 rampPosi = int(uf_colormapSize)-1;
32
33 //unpack the corresponding color
34 unpackedValues = fract(unpackedValues * uf_colormapTable[rampPosi]);
35 }
36 else //grayed point
37 {
38 unpackedValues = fract(unpackedValues * uf_colorGray);
39 }
40
41 //modulate unpacked color with true lighting value
42 gl_FragColor = vec4(gl_Color[2] * unpackedValues, gl_Color[3]);
43 }