mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Make marching ants shader ratio-independent
This commit is contained in:
parent
6a7ee3407c
commit
bdd32a8239
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue