From 088c80aa2b5cf9e03b37ba3bf52371b021719e23 Mon Sep 17 00:00:00 2001 From: Digvijaysinh Gohil Date: Tue, 12 Mar 2024 16:45:35 +0530 Subject: [PATCH] Artistic nodes code refactored --- .../Artistic/Adjustment/Contrast.gdshaderinc | 4 ++-- .../Artistic/Adjustment/Hue.gdshaderinc | 18 +++++++++--------- .../Adjustment/ReplaceColor.gdshaderinc | 4 ++-- .../Artistic/Adjustment/Saturation.gdshaderinc | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/addons/ShaderLib/Artistic/Adjustment/Contrast.gdshaderinc b/addons/ShaderLib/Artistic/Adjustment/Contrast.gdshaderinc index 0c2b269..9559991 100644 --- a/addons/ShaderLib/Artistic/Adjustment/Contrast.gdshaderinc +++ b/addons/ShaderLib/Artistic/Adjustment/Contrast.gdshaderinc @@ -1,4 +1,4 @@ vec3 contrast(vec3 input, float contrast){ - float midpoint = pow(0.5, 2.2); - return (input - midpoint) * contrast + midpoint; + float midpoint = pow(0.5, 2.2); + return (input - midpoint) * contrast + midpoint; } \ No newline at end of file diff --git a/addons/ShaderLib/Artistic/Adjustment/Hue.gdshaderinc b/addons/ShaderLib/Artistic/Adjustment/Hue.gdshaderinc index 156d669..9919c9b 100644 --- a/addons/ShaderLib/Artistic/Adjustment/Hue.gdshaderinc +++ b/addons/ShaderLib/Artistic/Adjustment/Hue.gdshaderinc @@ -1,14 +1,14 @@ vec3 hue(vec3 input, float offset, int range_index){ - // RGB to HSV + // RGB to HSV vec4 k = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); - vec4 p = mix(vec4(input.bg, k.wz), vec4(input.gb, k.xy), step(input.b, input.g)); - vec4 q = mix(vec4(p.xyw, input.r), vec4(input.r, p.yzx), step(p.x, input.r)); - float d = q.x - min(q.w, q.y); - float e = 1.0e-10; - vec3 hsv = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); + vec4 p = mix(vec4(input.bg, k.wz), vec4(input.gb, k.xy), step(input.b, input.g)); + vec4 q = mix(vec4(p.xyw, input.r), vec4(input.r, p.yzx), step(p.x, input.r)); + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + vec3 hsv = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); offset = (range_index == 0) ? offset / 360.0 : offset; - float hue = hsv.x + offset; + float hue = hsv.x + offset; if(hue < 0.0){ hsv.x = hue + 1.; } @@ -20,8 +20,8 @@ vec3 hue(vec3 input, float offset, int range_index){ } // HSV to RGB - vec4 k2 = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); - vec3 p2 = abs(fract(hsv.xxx + k2.xyz) * 6.0 - k2.www); + vec4 k2 = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p2 = abs(fract(hsv.xxx + k2.xyz) * 6.0 - k2.www); vec3 rgb = hsv.z * mix(k2.xxx, clamp(p2 - k2.xxx, 0.0, 1.0), hsv.y); return rgb; } \ No newline at end of file diff --git a/addons/ShaderLib/Artistic/Adjustment/ReplaceColor.gdshaderinc b/addons/ShaderLib/Artistic/Adjustment/ReplaceColor.gdshaderinc index 9a5bbbb..2797299 100644 --- a/addons/ShaderLib/Artistic/Adjustment/ReplaceColor.gdshaderinc +++ b/addons/ShaderLib/Artistic/Adjustment/ReplaceColor.gdshaderinc @@ -1,4 +1,4 @@ vec3 replace_color(vec3 input, vec3 from, vec3 to, float range, float fuzziness){ - float dist = distance(from, input); - return mix(to, input, clamp((dist - range) / max(fuzziness, 1.0e-5), 0.0, 1.0)); + float dist = distance(from, input); + return mix(to, input, clamp((dist - range) / max(fuzziness, 1.0e-5), 0.0, 1.0)); } \ No newline at end of file diff --git a/addons/ShaderLib/Artistic/Adjustment/Saturation.gdshaderinc b/addons/ShaderLib/Artistic/Adjustment/Saturation.gdshaderinc index c61a9c6..f3f958b 100644 --- a/addons/ShaderLib/Artistic/Adjustment/Saturation.gdshaderinc +++ b/addons/ShaderLib/Artistic/Adjustment/Saturation.gdshaderinc @@ -1,4 +1,4 @@ vec3 saturation(vec3 input, float saturation){ - float luma = dot(input, vec3(0.2126729, 0.7151522, 0.0721750)); - return luma + saturation * (input - vec3(luma)); + float luma = dot(input, vec3(0.2126729, 0.7151522, 0.0721750)); + return luma + saturation * (input - vec3(luma)); } \ No newline at end of file