1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-23 14:03:13 +00:00
Pixelorama/src/Shaders/ColorReplace.gdshader
Emmanouil Papadeas b0a284583b Add tolerance to the bucket's "similar area" mode, rename "similarity" to "tolerance" and make it work the inverse way
A slightly breaking change for a minor update, but one that needed to be done. The bucket tool's "similarity" (now renamed to "tolerance") used to work the opposite way from all other software, the maximum value meant exact color match and 0 meant no color match. Now it works the inverse way to make it be consistent with other software, and the range is now 0-255 instead of 0-100. 0 means exact color match, 255 means no color match. And tolerance also now works for the "similar area" mode as well.
2024-08-10 18:20:42 +03:00

41 lines
995 B
Text

shader_type canvas_item;
render_mode unshaded;
uniform vec2 size;
uniform vec4 old_color;
uniform vec4 new_color;
uniform float tolerance : hint_range(0.0, 1.0);
// Must be the same size as image
// Selected pixels are 1,1,1,1 and unselected 0,0,0,0
uniform sampler2D selection : filter_nearest;
uniform bool has_pattern;
uniform sampler2D pattern: repeat_enable;
uniform vec2 pattern_size;
uniform vec2 pattern_uv_offset;
bool similar_colors(vec4 c1, vec4 c2, float tol) {
return (
abs(c1.r - c2.r) <= tol
&& abs(c1.g - c2.g) <= tol
&& abs(c1.b - c2.b) <= tol
&& abs(c1.a - c2.a) <= tol
);
}
void fragment() {
vec4 original_color = texture(TEXTURE, UV);
vec4 selection_color = texture(selection, UV);
vec4 col = original_color;
if (similar_colors(original_color, old_color, tolerance))
if (has_pattern)
col = textureLod(pattern, UV * (size / pattern_size) + pattern_uv_offset, 0.0);
else
col = new_color;
COLOR = mix(original_color, col, selection_color.a);
}