mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
73 lines
2.2 KiB
GDScript
73 lines
2.2 KiB
GDScript
tool
|
|
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);
|