picker_shader.glsl (771B)
1 /* See LICENSE for copyright details */ 2 #version 330 3 4 in vec2 fragTexCoord; 5 in vec4 fragColor; 6 7 out vec4 out_colour; 8 9 #define MODE_H 0 10 #define MODE_SV 1 11 12 uniform int u_mode; 13 uniform vec4 u_hsv[2]; 14 uniform vec2 u_offset; 15 uniform vec2 u_size; 16 17 /* input: h [0,360] | s,v [0, 1] * 18 * output: rgb [0,1] */ 19 vec3 hsv2rgb(vec3 hsv) 20 { 21 vec3 k = mod(vec3(5, 3, 1) + hsv.x / 60, 6); 22 k = max(min(min(k, 4 - k), 1), 0); 23 return hsv.z - hsv.z * hsv.y * k; 24 } 25 26 void main() 27 { 28 vec2 pos = (gl_FragCoord.xy - u_offset) / u_size; 29 30 vec4 out_hsv; 31 switch (u_mode) { 32 case MODE_H: 33 out_hsv = mix(u_hsv[0], u_hsv[1], pos.y); 34 break; 35 case MODE_SV: 36 out_hsv = vec4(u_hsv[0].x, pos.x, pos.y, 1); 37 break; 38 } 39 out_hsv.x *= 360; 40 out_colour = vec4(hsv2rgb(out_hsv.xyz), 1); 41 }