From e974d1fe98087c7eff333345f58155437ca529cd Mon Sep 17 00:00:00 2001 From: Dickby Date: Sun, 12 Nov 2023 17:20:23 +0100 Subject: [PATCH] shaders: Some more changes in rgb2hsl. (#3834) --- src/render/shaders/Textures.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/render/shaders/Textures.hpp b/src/render/shaders/Textures.hpp index e32712fa..e78f39fc 100644 --- a/src/render/shaders/Textures.hpp +++ b/src/render/shaders/Textures.hpp @@ -234,11 +234,11 @@ vec3 rgb2hsl(vec3 col) { sat = delta / (mul * 2.0); } - vec3 masks = vec3((maxc == red && maxc != green) ? 1.0 : 0.0, (maxc == green && maxc != blue) ? 1.0 : 0.0, (maxc == blue && maxc != red) ? 1.0 : 0.0); - - vec3 adds = vec3(((green - blue) / delta), 2.0 + ((blue - red) / delta), 4.0 + ((red - green) / delta)); - if (delta > 0.0) { + vec3 maxcVec = vec3(maxc); + vec3 masks = vec3(equal(maxcVec, col)) * vec3(notEqual(maxcVec, vec3(green, blue, red))); + vec3 adds = vec3(0.0, 2.0, 4.0) + vec3(green - blue, blue - red, red - green) / delta; + hue += dot(adds, masks); hue /= 6.0; @@ -248,6 +248,7 @@ vec3 rgb2hsl(vec3 col) { return vec3(hue, sat, lum); } + vec3 hsl2rgb(vec3 col) { const float onethird = 1.0 / 3.0; const float twothird = 2.0 / 3.0;