Pixel-Composer/shaders/sh_combine_hsv/sh_combine_hsv.fsh

30 lines
854 B
Text
Raw Normal View History

2022-12-27 04:00:50 +01:00
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
2024-03-17 14:24:24 +01:00
uniform sampler2D samH;
uniform sampler2D samS;
uniform sampler2D samV;
uniform sampler2D samA;
2024-03-19 09:49:29 +01:00
uniform int useH;
uniform int useS;
uniform int useV;
2024-03-17 14:24:24 +01:00
uniform int useA;
2022-12-27 04:00:50 +01:00
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
2024-03-17 14:24:24 +01:00
float sample(vec4 col, int ch) { return (col[0] + col[1] + col[2]) / 3. * col[3]; }
2022-12-27 04:00:50 +01:00
void main() {
2024-03-17 14:24:24 +01:00
float h = (useH == 1)? sample(texture2D( samH, v_vTexcoord ), 0) : 0.;
float s = (useS == 1)? sample(texture2D( samS, v_vTexcoord ), 1) : 0.;
float v = (useV == 1)? sample(texture2D( samV, v_vTexcoord ), 2) : 0.;
float a = (useA == 1)? sample(texture2D( samA, v_vTexcoord ), 3) : 1.;
2022-12-27 04:00:50 +01:00
2024-03-17 14:24:24 +01:00
gl_FragColor = vec4(hsv2rgb(vec3(h, s, v)), a);
2022-12-27 04:00:50 +01:00
}