mirror of
https://github.com/Relintai/broken_seals.git
synced 2025-01-29 02:29:18 +01:00
Moved shapes to a new shapes.gd file.
This commit is contained in:
parent
55f85a9b2d
commit
44bdbeb56d
@ -246,75 +246,6 @@ static func ThickLine(uv : Vector2, posA : Vector2, posB : Vector2, radiusInv :
|
||||
|
||||
return finalGray;
|
||||
|
||||
|
||||
static func shape_circle(uv : Vector2, sides : float, size : float, edge : float) -> float:
|
||||
uv.x = 2.0 * uv.x - 1.0
|
||||
uv.y = 2.0 * uv.y - 1.0
|
||||
|
||||
edge = max(edge, 1.0e-8)
|
||||
|
||||
var distance : float = uv.length()
|
||||
|
||||
return clamp((1.0 - distance / size) / edge, 0.0, 1.0)
|
||||
|
||||
static func shape_polygon(uv : Vector2, sides : float, size : float, edge : float) -> float:
|
||||
uv.x = 2.0 * uv.x - 1.0
|
||||
uv.y = 2.0 * uv.y - 1.0
|
||||
|
||||
edge = max(edge, 1.0e-8)
|
||||
|
||||
#simple no branch for division by zero
|
||||
uv.x += 0.0000001
|
||||
|
||||
var angle : float = atan(uv.y / uv.x) + 3.14159265359
|
||||
var slice : float = 6.28318530718 / sides
|
||||
|
||||
return clamp((size - cos(floor(0.5 + angle / slice) * slice - angle) * uv.length()) / (edge * size), 0.0, 1.0)
|
||||
|
||||
static func shape_star(uv : Vector2, sides : float, size : float, edge : float) -> float:
|
||||
uv.x = 2.0 * uv.x - 1.0
|
||||
uv.y = 2.0 * uv.y - 1.0
|
||||
|
||||
edge = max(edge, 1.0e-8);
|
||||
|
||||
#simple no branch for division by zero
|
||||
uv.x += 0.0000001
|
||||
|
||||
var angle : float = atan(uv.y / uv.x)
|
||||
var slice : float = 6.28318530718 / sides
|
||||
|
||||
return clamp((size - cos(floor(1.5 + angle / slice - 2.0 * step(0.5 * slice, modf(angle, slice))) * slice - angle) * uv.length()) / (edge * size), 0.0, 1.0);
|
||||
|
||||
static func shape_curved_star(uv : Vector2, sides : float, size : float, edge : float) -> float:
|
||||
uv.x = 2.0 * uv.x - 1.0
|
||||
uv.y = 2.0 * uv.y - 1.0
|
||||
|
||||
edge = max(edge, 1.0e-8);
|
||||
|
||||
#simple no branch for division by zero
|
||||
uv.x += 0.0000001
|
||||
|
||||
var angle : float = 2.0*(atan(uv.y / uv.x) + 3.14159265359)
|
||||
var slice : float = 6.28318530718 / sides
|
||||
|
||||
return clamp((size - cos(floor(0.5 + 0.5 * angle / slice) * 2.0 * slice - angle) * uv.length())/(edge * size), 0.0, 1.0);
|
||||
|
||||
|
||||
static func shape_rays(uv : Vector2, sides : float, size : float, edge : float) -> float:
|
||||
|
||||
uv.x = 2.0 * uv.x - 1.0
|
||||
uv.y = 2.0 * uv.y - 1.0
|
||||
|
||||
edge = 0.5 * max(edge, 1.0e-8) * size
|
||||
|
||||
#simple no branch for division by zero
|
||||
uv.x += 0.0000001
|
||||
|
||||
var slice : float = 6.28318530718 / sides
|
||||
var angle : float = modf(atan(uv.y / uv.x) + 3.14159265359, slice) / slice
|
||||
|
||||
return clamp(min((size - angle) / edge, angle / edge), 0.0, 1.0);
|
||||
|
||||
static func adjust_hsv(color : Color, hue : float, saturation : float, value : float) -> Color:
|
||||
var hsv : Vector3 = rgb_to_hsv(Vector3(color.r, color.g, color.b));
|
||||
|
||||
|
71
game/addons/mat_maker_gd/nodes/common/shapes.gd
Normal file
71
game/addons/mat_maker_gd/nodes/common/shapes.gd
Normal file
@ -0,0 +1,71 @@
|
||||
extends Reference
|
||||
|
||||
const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
|
||||
static func shape_circle(uv : Vector2, sides : float, size : float, edge : float) -> float:
|
||||
uv.x = 2.0 * uv.x - 1.0
|
||||
uv.y = 2.0 * uv.y - 1.0
|
||||
|
||||
edge = max(edge, 1.0e-8)
|
||||
|
||||
var distance : float = uv.length()
|
||||
|
||||
return clamp((1.0 - distance / size) / edge, 0.0, 1.0)
|
||||
|
||||
static func shape_polygon(uv : Vector2, sides : float, size : float, edge : float) -> float:
|
||||
uv.x = 2.0 * uv.x - 1.0
|
||||
uv.y = 2.0 * uv.y - 1.0
|
||||
|
||||
edge = max(edge, 1.0e-8)
|
||||
|
||||
#simple no branch for division by zero
|
||||
uv.x += 0.0000001
|
||||
|
||||
var angle : float = atan(uv.y / uv.x) + 3.14159265359
|
||||
var slice : float = 6.28318530718 / sides
|
||||
|
||||
return clamp((size - cos(floor(0.5 + angle / slice) * slice - angle) * uv.length()) / (edge * size), 0.0, 1.0)
|
||||
|
||||
static func shape_star(uv : Vector2, sides : float, size : float, edge : float) -> float:
|
||||
uv.x = 2.0 * uv.x - 1.0
|
||||
uv.y = 2.0 * uv.y - 1.0
|
||||
|
||||
edge = max(edge, 1.0e-8);
|
||||
|
||||
#simple no branch for division by zero
|
||||
uv.x += 0.0000001
|
||||
|
||||
var angle : float = atan(uv.y / uv.x)
|
||||
var slice : float = 6.28318530718 / sides
|
||||
|
||||
return clamp((size - cos(floor(1.5 + angle / slice - 2.0 * Commons.step(0.5 * slice, Commons.modf(angle, slice))) * slice - angle) * uv.length()) / (edge * size), 0.0, 1.0);
|
||||
|
||||
static func shape_curved_star(uv : Vector2, sides : float, size : float, edge : float) -> float:
|
||||
uv.x = 2.0 * uv.x - 1.0
|
||||
uv.y = 2.0 * uv.y - 1.0
|
||||
|
||||
edge = max(edge, 1.0e-8);
|
||||
|
||||
#simple no branch for division by zero
|
||||
uv.x += 0.0000001
|
||||
|
||||
var angle : float = 2.0*(atan(uv.y / uv.x) + 3.14159265359)
|
||||
var slice : float = 6.28318530718 / sides
|
||||
|
||||
return clamp((size - cos(floor(0.5 + 0.5 * angle / slice) * 2.0 * slice - angle) * uv.length())/(edge * size), 0.0, 1.0);
|
||||
|
||||
|
||||
static func shape_rays(uv : Vector2, sides : float, size : float, edge : float) -> float:
|
||||
|
||||
uv.x = 2.0 * uv.x - 1.0
|
||||
uv.y = 2.0 * uv.y - 1.0
|
||||
|
||||
edge = 0.5 * max(edge, 1.0e-8) * size
|
||||
|
||||
#simple no branch for division by zero
|
||||
uv.x += 0.0000001
|
||||
|
||||
var slice : float = 6.28318530718 / sides
|
||||
var angle : float = Commons.modf(atan(uv.y / uv.x) + 3.14159265359, slice) / slice
|
||||
|
||||
return clamp(min((size - angle) / edge, angle / edge), 0.0, 1.0);
|
@ -1,7 +1,7 @@
|
||||
tool
|
||||
extends TextureRect
|
||||
|
||||
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
var Shapes = preload("res://addons/mat_maker_gd/nodes/common/shapes.gd")
|
||||
|
||||
var image : Image
|
||||
var tex : ImageTexture
|
||||
@ -39,6 +39,7 @@ func gen() -> void:
|
||||
# var bmin : Vector2 = Vector2(0.1, 0.1)
|
||||
# var bmax : Vector2 = Vector2(1, 1)
|
||||
|
||||
|
||||
image.lock()
|
||||
|
||||
var w : float = image.get_width()
|
||||
@ -50,11 +51,11 @@ func gen() -> void:
|
||||
for y in range(image.get_height()):
|
||||
var v : Vector2 = Vector2(x / w, y / h)
|
||||
|
||||
# var c : float = shape_circle(v, p_o69054_sides, p_o69054_radius * 1.0, p_o69054_edge * 1.0)
|
||||
# var c : float = shape_polygon(v, p_o69054_sides, p_o69054_radius * 1.0, p_o69054_edge * 1.0)
|
||||
# var c : float = shape_star(v, p_o69054_sides, p_o69054_radius * 1.0, p_o69054_edge * 1.0)
|
||||
# var c : float = shape_curved_star(v, p_o69054_sides, p_o69054_radius * 1.0, p_o69054_edge * 1.0)
|
||||
var c : float = Commons.shape_rays(v, p_o69054_sides, p_o69054_radius * 1.0, p_o69054_edge * 1.0)
|
||||
# var c : float = Commons.shape_circle(v, p_o69054_sides, p_o69054_radius * 1.0, p_o69054_edge * 1.0)
|
||||
# var c : float = Commons.shape_polygon(v, p_o69054_sides, p_o69054_radius * 1.0, p_o69054_edge * 1.0)
|
||||
# var c : float = Commons.shape_star(v, p_o69054_sides, p_o69054_radius * 1.0, p_o69054_edge * 1.0)
|
||||
# var c : float = Commons.shape_curved_star(v, p_o69054_sides, p_o69054_radius * 1.0, p_o69054_edge * 1.0)
|
||||
var c : float = Shapes.shape_rays(v, p_o69054_sides, p_o69054_radius * 1.0, p_o69054_edge * 1.0)
|
||||
|
||||
image.set_pixel(x, y, Color(c, c, c, 1))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user