diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 6c27cd2c0..c697d9572 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -765,15 +765,11 @@ func resize_bitmap(bitmap: BitMap, new_size: Vector2) -> BitMap: # Unexposed BitMap class function # https://github.com/godotengine/godot/blob/master/scene/resources/bit_map.cpp#L622 -func bitmap_to_image(bitmap: BitMap, square := true) -> Image: +func bitmap_to_image(bitmap: BitMap) -> Image: var image := Image.new() var width := bitmap.get_size().x var height := bitmap.get_size().y - if square: - var square_size = max(width, height) - image.create(square_size, square_size, false, Image.FORMAT_LA8) - else: - image.create(width, height, false, Image.FORMAT_LA8) + image.create(width, height, false, Image.FORMAT_LA8) image.lock() for x in width: for y in height: diff --git a/src/Shaders/MarchingAntsOutline.shader b/src/Shaders/MarchingAntsOutline.shader index 0d0d63da2..d7231a281 100644 --- a/src/Shaders/MarchingAntsOutline.shader +++ b/src/Shaders/MarchingAntsOutline.shader @@ -10,7 +10,7 @@ uniform float frequency = 50.0; uniform float stripe_direction : hint_range(0, 1) = 0.5; -bool hasContraryNeighbour(vec2 uv, vec2 texture_pixel_size, sampler2D texture) { +bool has_contrary_neighbour(vec2 uv, vec2 texture_pixel_size, sampler2D tex) { float i = -ceil(width); float j = ceil(width); float x1 = abs(i) > width ? width * sign(i) : i; @@ -21,7 +21,7 @@ bool hasContraryNeighbour(vec2 uv, vec2 texture_pixel_size, sampler2D texture) { vec2 xy1 = uv + texture_pixel_size * vec2(x1, y1); vec2 xy2 = uv + texture_pixel_size * vec2(x2, y2); - if (xy1 != clamp(xy1, vec2(0.0), vec2(1.0)) || texture(texture, xy1).a == 0.0 || xy2 != clamp(xy2, vec2(0.0), vec2(1.0)) || texture(texture, xy2).a == 0.0) { + if (xy1 != clamp(xy1, vec2(0.0), vec2(1.0)) || texture(tex, xy1).a == 0.0 || xy2 != clamp(xy2, vec2(0.0), vec2(1.0)) || texture(tex, xy2).a == 0.0) { return true; } @@ -29,21 +29,18 @@ bool hasContraryNeighbour(vec2 uv, vec2 texture_pixel_size, sampler2D texture) { } void fragment() { - vec2 uv = UV; - COLOR = texture(TEXTURE, uv); + COLOR = texture(TEXTURE, UV); + vec2 ts = TEXTURE_PIXEL_SIZE; - if ((COLOR.a > 0.0) == true && hasContraryNeighbour(uv, TEXTURE_PIXEL_SIZE, TEXTURE)) { - vec4 final_color = first_color; - // Generate diagonal stripes + if (COLOR.a > 0.0 && has_contrary_neighbour(UV, ts, TEXTURE)) { + vec2 ratio = (ts.x > ts.y) ? vec2(ts.y / ts.x, 1) : vec2(1, ts.x / ts.y); + vec2 uv = UV * ratio; if(animated) uv -= TIME / frequency; + // Generate diagonal stripes float pos = mix(uv.x, uv.y, stripe_direction) * frequency; float value = floor(fract(pos) + 0.5); - if (mod(value, 2.0) == 0.0) - final_color = second_color; - - COLOR.rgb = mix(COLOR.rgb, final_color.rgb, final_color.a); - COLOR.a += (1.0 - COLOR.a) * final_color.a; + COLOR = mix(first_color, second_color, step(1.0, mod(value, 2.0))); } else { // Erase the texture's pixels in order to only keep the outline visible diff --git a/src/Tools/Bucket.gd b/src/Tools/Bucket.gd index e06b311b7..55df84f9c 100644 --- a/src/Tools/Bucket.gd +++ b/src/Tools/Bucket.gd @@ -181,7 +181,7 @@ func fill_in_color(position: Vector2) -> void: var selection: Image var selection_tex := ImageTexture.new() if project.has_selection: - selection = project.bitmap_to_image(project.selection_bitmap, false) + selection = project.bitmap_to_image(project.selection_bitmap) else: selection = Image.new() selection.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8) diff --git a/src/UI/Dialogs/ImageEffects/DesaturateDialog.gd b/src/UI/Dialogs/ImageEffects/DesaturateDialog.gd index f6eb21260..835aa1454 100644 --- a/src/UI/Dialogs/ImageEffects/DesaturateDialog.gd +++ b/src/UI/Dialogs/ImageEffects/DesaturateDialog.gd @@ -30,7 +30,7 @@ func _confirmed() -> void: func commit_action(cel: Image, project: Project = Global.current_project) -> void: - var selection: Image = project.bitmap_to_image(project.selection_bitmap, false) + var selection: Image = project.bitmap_to_image(project.selection_bitmap) var selection_tex := ImageTexture.new() selection_tex.create_from_image(selection) diff --git a/src/UI/Dialogs/ImageEffects/HSVDialog.gd b/src/UI/Dialogs/ImageEffects/HSVDialog.gd index dfbb27552..700fbf3dc 100644 --- a/src/UI/Dialogs/ImageEffects/HSVDialog.gd +++ b/src/UI/Dialogs/ImageEffects/HSVDialog.gd @@ -37,7 +37,7 @@ func _confirmed() -> void: func commit_action(cel: Image, project: Project = Global.current_project) -> void: - var selection: Image = project.bitmap_to_image(project.selection_bitmap, false) + var selection: Image = project.bitmap_to_image(project.selection_bitmap) var selection_tex := ImageTexture.new() selection_tex.create_from_image(selection) diff --git a/src/UI/Dialogs/ImageEffects/InvertColorsDialog.gd b/src/UI/Dialogs/ImageEffects/InvertColorsDialog.gd index c2e1e652a..425e64424 100644 --- a/src/UI/Dialogs/ImageEffects/InvertColorsDialog.gd +++ b/src/UI/Dialogs/ImageEffects/InvertColorsDialog.gd @@ -30,7 +30,7 @@ func _confirmed() -> void: func commit_action(cel: Image, project: Project = Global.current_project) -> void: - var selection: Image = project.bitmap_to_image(project.selection_bitmap, false) + var selection: Image = project.bitmap_to_image(project.selection_bitmap) var selection_tex := ImageTexture.new() selection_tex.create_from_image(selection)