From 4d26a6dd555eeb051504efd25175da2c8e9d3cd0 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:51:46 +0300 Subject: [PATCH] Fix warnings in some shaders --- src/Shaders/Effects/HSV.gdshader | 6 +++++- src/Shaders/Effects/OutlineInline.gdshader | 5 ++++- src/Shaders/Effects/Palettize.gdshader | 1 - 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Shaders/Effects/HSV.gdshader b/src/Shaders/Effects/HSV.gdshader index e3f70bdc6..fc0d1b1c5 100644 --- a/src/Shaders/Effects/HSV.gdshader +++ b/src/Shaders/Effects/HSV.gdshader @@ -6,6 +6,10 @@ uniform float saturation : hint_range(-1, 1); uniform float value : hint_range(-1, 1); uniform sampler2D selection : filter_nearest; +bool is_equal_approx(float a, float b) { + return abs(a - b) <= 0.0001; +} + vec3 rgb2hsb(vec3 c){ vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); vec4 p = mix(vec4(c.bg, K.wz), @@ -38,7 +42,7 @@ void fragment() { vec3 col = original_color.rgb; vec3 hsb = rgb2hsb(col); // If not greyscale - if(col[0] != col[1] || col[1] != col[2]) { + if(!is_equal_approx(col[0], col[1]) || !is_equal_approx(col[1], col[2])) { // Shift the color by shift_amount, but rolling over the value goes over 1 hsb.x = mod(hsb.x + hue, 1.0); } diff --git a/src/Shaders/Effects/OutlineInline.gdshader b/src/Shaders/Effects/OutlineInline.gdshader index 91491d817..f19b0ccac 100644 --- a/src/Shaders/Effects/OutlineInline.gdshader +++ b/src/Shaders/Effects/OutlineInline.gdshader @@ -8,6 +8,9 @@ uniform int pattern : hint_range(0, 2) = 0; // diamond, circle, square uniform bool inside = false; uniform sampler2D selection : filter_nearest; +bool is_zero_approx(float num) { + return num < 0.0001; +} bool has_contrary_neighbour(vec2 uv, vec2 texture_pixel_size, sampler2D tex) { for (float i = -ceil(width); i <= ceil(width); i++) { @@ -24,7 +27,7 @@ bool has_contrary_neighbour(vec2 uv, vec2 texture_pixel_size, sampler2D tex) { for (float j = -ceil(offset); j <= ceil(offset); j++) { vec2 xy = uv + texture_pixel_size * vec2(i, j); - if ((xy != clamp(xy, vec2(0.0), vec2(1.0)) || texture(tex, xy).a == 0.0) == inside) { + if ((xy != clamp(xy, vec2(0.0), vec2(1.0)) || is_zero_approx(texture(tex, xy).a)) == inside) { return true; } } diff --git a/src/Shaders/Effects/Palettize.gdshader b/src/Shaders/Effects/Palettize.gdshader index 6e6814c10..1c20c260a 100644 --- a/src/Shaders/Effects/Palettize.gdshader +++ b/src/Shaders/Effects/Palettize.gdshader @@ -31,4 +31,3 @@ void fragment() { vec4 color = swap_color(original_color); COLOR = mix(original_color.rgba, color, selection_color.a); } -