From 543eb946a0dacaaf37d361661b01771f22c9772e Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 10 Sep 2013 21:41:01 +0000 Subject: [PATCH] btphystest: play with hue values. --- test/front_camera_sprite.lolfx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/test/front_camera_sprite.lolfx b/test/front_camera_sprite.lolfx index f9056144..e689d5ee 100644 --- a/test/front_camera_sprite.lolfx +++ b/test/front_camera_sprite.lolfx @@ -53,13 +53,32 @@ varying vec4 pass_color; const float cos_45 = 0.70710678118; const float PI = 3.14159265358979323846264; +vec3 rgb2hsv(vec3 c) +{ + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy); + vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + +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); +} + void main(void) { vec4 color = texture2D(in_texture, pass_texcoord.xy - - vec2(pass_texcoord.z * in_sprite_flip, 0.0)) * - pass_color; + vec2(pass_texcoord.z * in_sprite_flip, 0.0)); if (color.a < 0.01) discard; - gl_FragColor = color * pass_color; + vec3 hsv = rgb2hsv(color.rgb); + hsv.x = fract(hsv.x + rgb2hsv(pass_color.rgb).x); + gl_FragColor = vec4(hsv2rgb(hsv), color.a); }