Moved a lot more things to Commons.gd.

This commit is contained in:
Relintai 2021-10-02 10:39:30 +02:00
parent e4eccdc034
commit 01fd374344
22 changed files with 1105 additions and 1386 deletions

File diff suppressed because it is too large Load Diff

View File

@ -38,7 +38,7 @@ func gen() -> void:
for y in range(image.get_height()):
var v : Vector2 = Vector2(x / w, y / h)
var f : float = shape_circle(v, 3, 1.0 * 1.0, 1.0)
var f : float = Commons.shape_circle(v, 3, 1.0 * 1.0, 1.0)
var c : Color = Color(f, f, f, 1)
# c = invert(c)
@ -55,9 +55,6 @@ func gen() -> void:
tex.create_from_image(image)
texture = tex
func invert(color : Color) -> Color:
return Color(1.0 - color.r, 1.0 - color.g, 1.0 - color.b, color.a);
var p_o91644_brightness = 0.000000000;
var p_o91644_contrast = 1.000000000;
@ -76,108 +73,16 @@ var p_o102649_saturation = 1.000000000;
var p_o102649_value = 1.000000000;
func adjust_hsv(color : Color) -> Color:
var hsv : Vector3 = rgb_to_hsv(Vector3(color.r, color.g, color.b));
var hsv : Vector3 = Commons.rgb_to_hsv(Vector3(color.r, color.g, color.b));
var x : float = Commons.fract(hsv.x + p_o102649_hue)
var y : float = clamp(hsv.y * p_o102649_saturation, 0.0, 1.0)
var z : float = clamp(hsv.z * p_o102649_value, 0.0, 1.0)
var h : Vector3 = hsv_to_rgb(Vector3(x, y, z))
var h : Vector3 = Commons.hsv_to_rgb(Vector3(x, y, z))
return Color(h.x, h.y, h.z, color.a);
func rgb_to_hsv(c : Vector3) -> Vector3:
var K : Color = Color(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
var p : Color
if c.y < c.z:
p = Color(c.z, c.y, K.a, K.b)
else:
p = Color(c.y, c.z, K.r, K.g);
var q : Color
if c.x < p.r:
q = Color(p.r, p.g, p.a, c.x)
else:
q = Color(c.x, p.g, p.b, p.r);
var d : float = q.r - min(q.a, q.g);
var e : float = 1.0e-10;
return Vector3(abs(q.b + (q.a - q.g) / (6.0 * d + e)), d / (q.r + e), q.r);
func hsv_to_rgb(c : Vector3) -> Vector3:
var K : Color = Color(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
var p : Vector3 = Commons.absv3(Commons.fractv3(Vector3(c.x, c.x, c.x) + Vector3(K.r, K.g, K.b)) * 6.0 - Vector3(K.a, K.a, K.a));
return c.z * lerp(Vector3(K.r, K.r, K.r), Commons.clampv3(p - Vector3(K.r, K.r, K.r), Vector3(), Vector3(1, 1, 1)), c.y);
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)
func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector2, repeat : bool) -> Vector2:
var rv : Vector2 = Vector2();
uv -= translate;
uv -= Vector2(0.5, 0.5);
rv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;
rv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;
rv /= scale;
rv += Vector2(0.5, 0.5);
if (repeat):
return Commons.fractv2(rv);
else:
return Commons.clampv2(rv, Vector2(0, 0), Vector2(1, 1));
#common -----
#float rand(vec2 x) {
# return fract(cos(dot(x, vec2(13.9898, 8.141))) * 43758.5453);
#}
#
#vec2 rand2(vec2 x) {
# return fract(cos(vec2(dot(x, vec2(13.9898, 8.141)),
# dot(x, vec2(3.4562, 17.398)))) * 43758.5453);
#}
#
#vec3 rand3(vec2 x) {
# return fract(cos(vec3(dot(x, vec2(13.9898, 8.141)),
# dot(x, vec2(3.4562, 17.398)),
# dot(x, vec2(13.254, 5.867)))) * 43758.5453);
#}
#
#vec3 rgb2hsv(vec3 c) {
# vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
# vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
# vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
#
# float d = q.x - min(q.w, q.y);
# float e = 1.0e-10;
# return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
#}
#
#vec3 hsv2rgb(vec3 c) {
# vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
# vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
# return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
#}
#end common
func reffg():
return false

View File

@ -38,7 +38,7 @@ func gen() -> void:
for y in range(image.get_height()):
var v : Vector2 = Vector2(x / w, y / h)
var f : float = shape_circle(v, 3, 1.0 * 1.0, 1.0)
var f : float = Commons.shape_circle(v, 3, 1.0 * 1.0, 1.0)
f = gs_luminosity(Vector3(f, f, f));
@ -57,10 +57,6 @@ func gen() -> void:
tex.create_from_image(image)
texture = tex
func invert(color : Color) -> Color:
return Color(1.0 - color.r, 1.0 - color.g, 1.0 - color.b, color.a);
func gs_min(c : Vector3) -> float:
return min(c.x, min(c.y, c.z));
@ -76,72 +72,6 @@ func gs_average(c : Vector3) -> float:
func gs_luminosity(c : Vector3) -> float:
return 0.21 * c.x + 0.72 * c.y + 0.07 * c.z;
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)
func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector2, repeat : bool) -> Vector2:
var rv : Vector2 = Vector2();
uv -= translate;
uv -= Vector2(0.5, 0.5);
rv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;
rv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;
rv /= scale;
rv += Vector2(0.5, 0.5);
if (repeat):
return Commons.fractv2(rv);
else:
return Commons.clampv2(rv, Vector2(0, 0), Vector2(1, 1));
#common -----
#float rand(vec2 x) {
# return fract(cos(dot(x, vec2(13.9898, 8.141))) * 43758.5453);
#}
#
#vec2 rand2(vec2 x) {
# return fract(cos(vec2(dot(x, vec2(13.9898, 8.141)),
# dot(x, vec2(3.4562, 17.398)))) * 43758.5453);
#}
#
#vec3 rand3(vec2 x) {
# return fract(cos(vec3(dot(x, vec2(13.9898, 8.141)),
# dot(x, vec2(3.4562, 17.398)),
# dot(x, vec2(13.254, 5.867)))) * 43758.5453);
#}
#
#vec3 rgb2hsv(vec3 c) {
# vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
# vec4 p = c.y < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
# vec4 q = c.x < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
#
# float d = q.x - min(q.w, q.y);
# float e = 1.0e-10;
# return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
#}
#
#vec3 hsv2rgb(vec3 c) {
# vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
# vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
# return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
#}
#end common
func reffg():
return false

View File

@ -1,6 +1,8 @@
tool
extends TextureRect
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
var image : Image
var tex : ImageTexture
@ -54,7 +56,7 @@ func gen() -> void:
texture = tex
func o11853_input_in(uv : Vector2) -> Vector3:
var f : float = shape_circle(uv, 3, 1.0 * 1.0, 1.0)
var f : float = Commons.shape_circle(uv, 3, 1.0 * 1.0, 1.0)
return Vector3(f, f, f);
@ -69,54 +71,6 @@ func sharpen(uv : Vector2) -> Vector3:
return rv
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)
#common -----
#float rand(vec2 x) {
# return fract(cos(dot(x, vec2(13.9898, 8.141))) * 43758.5453);
#}
#
#vec2 rand2(vec2 x) {
# return fract(cos(vec2(dot(x, vec2(13.9898, 8.141)),
# dot(x, vec2(3.4562, 17.398)))) * 43758.5453);
#}
#
#vec3 rand3(vec2 x) {
# return fract(cos(vec3(dot(x, vec2(13.9898, 8.141)),
# dot(x, vec2(3.4562, 17.398)),
# dot(x, vec2(13.254, 5.867)))) * 43758.5453);
#}
#
#vec3 rgb2hsv(vec3 c) {
# vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
# vec4 p = c.y < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
# vec4 q = c.x < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
#
# float d = q.x - min(q.w, q.y);
# float e = 1.0e-10;
# return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
#}
#
#vec3 hsv2rgb(vec3 c) {
# vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
# vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
# return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
#}
#end common
func reffg():
return false

View File

@ -57,7 +57,6 @@ var p_o7136_frequency = 2.000000000;
var p_o7136_phase = 0.000000000;
func sinewave(uv : Vector2) -> Color:
var f : float = 1.0- abs(2.0 * (uv.y-0.5) - p_o7136_amplitude * sin((p_o7136_frequency* uv.x + p_o7136_phase) * 6.28318530718));
return Color(f, f, f, 1)

View File

@ -109,7 +109,7 @@ func o33355_fbm(coord : Vector2, size : Vector2, octaves : int, persistence : fl
var scale : float = 1.0;
for i in range(octaves):# (int i = 0; i < octaves; i++) {
value += fbm_value(coord*size, size, pseed) * scale;
value += Commons.fbm_value(coord*size, size, pseed) * scale;
normalize_factor += scale;
size *= 2.0;
scale *= persistence;
@ -122,7 +122,7 @@ func o33355_perlin(coord : Vector2, size : Vector2, octaves : int, persistence :
var scale : float = 1.0;
for i in range(octaves):# (int i = 0; i < octaves; i++) {
value += fbm_perlin(coord*size, size, pseed) * scale;
value += Commons.fbm_perlin(coord*size, size, pseed) * scale;
normalize_factor += scale;
size *= 2.0;
scale *= persistence;
@ -135,7 +135,7 @@ func o33355_cellular(coord : Vector2, size : Vector2, octaves : int, persistence
var scale : float = 1.0;
for i in range(octaves):# (int i = 0; i < octaves; i++) {
value += fbm_cellular(coord*size, size, pseed) * scale;
value += Commons.fbm_cellular(coord*size, size, pseed) * scale;
normalize_factor += scale;
size *= 2.0;
scale *= persistence;
@ -148,7 +148,7 @@ func o33355_cellular2(coord : Vector2, size : Vector2, octaves : int, persistenc
var scale : float = 1.0;
for i in range(octaves):# (int i = 0; i < octaves; i++) {
value += fbm_cellular2(coord*size, size, pseed) * scale;
value += Commons.fbm_cellular2(coord*size, size, pseed) * scale;
normalize_factor += scale;
size *= 2.0;
scale *= persistence;
@ -161,7 +161,7 @@ func o33355_cellular3(coord : Vector2, size : Vector2, octaves : int, persistenc
var scale : float = 1.0;
for i in range(octaves):# (int i = 0; i < octaves; i++) {
value += fbm_cellular3(coord*size, size, pseed) * scale;
value += Commons.fbm_cellular3(coord*size, size, pseed) * scale;
normalize_factor += scale;
size *= 2.0;
scale *= persistence;
@ -174,7 +174,7 @@ func o33355_cellular4(coord : Vector2, size : Vector2, octaves : int, persistenc
var scale : float = 1.0;
for i in range(octaves):# (int i = 0; i < octaves; i++) {
value += fbm_cellular4(coord*size, size, pseed) * scale;
value += Commons.fbm_cellular4(coord*size, size, pseed) * scale;
normalize_factor += scale;
size *= 2.0;
scale *= persistence;
@ -187,7 +187,7 @@ func o33355_cellular5(coord : Vector2, size : Vector2, octaves : int, persistenc
var scale : float = 1.0;
for i in range(octaves):# (int i = 0; i < octaves; i++) {
value += fbm_cellular5(coord*size, size, pseed) * scale;
value += Commons.fbm_cellular5(coord*size, size, pseed) * scale;
normalize_factor += scale;
size *= 2.0;
scale *= persistence;
@ -200,192 +200,13 @@ func o33355_cellular6(coord : Vector2, size : Vector2, octaves : int, persistenc
var scale : float = 1.0;
for i in range(octaves):# (int i = 0; i < octaves; i++) {
value += fbm_cellular6(coord*size, size, pseed) * scale;
value += Commons.fbm_cellular6(coord*size, size, pseed) * scale;
normalize_factor += scale;
size *= 2.0;
scale *= persistence;
return value / normalize_factor;
func fbm_value(coord : Vector2, size : Vector2, pseed : float) -> float:
var o : Vector2 = Commons.floorv2(coord) + Commons.rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size;
var f : Vector2 = Commons.fractv2(coord);
var p00 : float = Commons.rand(Commons.modv2(o, size));
var p01 : float = Commons.rand(Commons.modv2(o + Vector2(0.0, 1.0), size));
var p10 : float = Commons.rand(Commons.modv2(o + Vector2(1.0, 0.0), size));
var p11 : float = Commons.rand(Commons.modv2(o + Vector2(1.0, 1.0), size));
var t : Vector2 = f * f * (Vector2(3, 3) - 2.0 * f);
return lerp(lerp(p00, p10, t.x), lerp(p01, p11, t.x), t.y);
func fbm_perlin(coord : Vector2, size : Vector2, pseed : float) -> float:
var o : Vector2 = Commons.floorv2(coord) + Commons.rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size;
var f : Vector2 = Commons.fractv2(coord);
var a00 : float = Commons.rand(Commons.modv2(o, size)) * 6.28318530718;
var a01 : float = Commons.rand(Commons.modv2(o + Vector2(0.0, 1.0), size)) * 6.28318530718;
var a10 : float = Commons.rand(Commons.modv2(o + Vector2(1.0, 0.0), size)) * 6.28318530718;
var a11 : float = Commons.rand(Commons.modv2(o + Vector2(1.0, 1.0), size)) * 6.28318530718;
var v00 : Vector2 = Vector2(cos(a00), sin(a00));
var v01 : Vector2 = Vector2(cos(a01), sin(a01));
var v10 : Vector2 = Vector2(cos(a10), sin(a10));
var v11 : Vector2 = Vector2(cos(a11), sin(a11));
var p00 : float = v00.dot(f);
var p01 : float = v01.dot(f - Vector2(0.0, 1.0));
var p10 : float = v10.dot(f - Vector2(1.0, 0.0));
var p11 : float = v11.dot(f - Vector2(1.0, 1.0));
var t : Vector2 = f * f * (Vector2(3, 3) - 2.0 * f);
return 0.5 + lerp(lerp(p00, p10, t.x), lerp(p01, p11, t.x), t.y);
func fbm_cellular(coord : Vector2, size : Vector2, pseed : float) -> float:
var o : Vector2 = Commons.floorv2(coord) + Commons.rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size;
var f : Vector2 = Commons.fractv2(coord);
var min_dist : float = 2.0;
for xx in range(-1, 2): #(float x = -1.0; x <= 1.0; x++) {
var x : float = xx
for yy in range(-1, 2):#(float y = -1.0; y <= 1.0; y++) {
var y : float = yy
var node : Vector2 = Commons.rand2(Commons.modv2(o + Vector2(x, y), size)) + Vector2(x, y);
var dist : float = sqrt((f - node).x * (f - node).x + (f - node).y * (f - node).y);
min_dist = min(min_dist, dist);
return min_dist;
func fbm_cellular2(coord : Vector2, size : Vector2, pseed : float) -> float:
var o : Vector2 = Commons.floorv2(coord) + Commons.rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size;
var f : Vector2 = Commons.fractv2(coord);
var min_dist1 : float = 2.0;
var min_dist2 : float = 2.0;
for xx in range(-1, 2): #(float x = -1.0; x <= 1.0; x++) {
var x : float = xx
for yy in range(-1, 2):#(float y = -1.0; y <= 1.0; y++) {
var y : float = yy
var node : Vector2 = Commons.rand2(Commons.modv2(o + Vector2(x, y), size)) + Vector2(x, y);
var dist : float = sqrt((f - node).x * (f - node).x + (f - node).y * (f - node).y);
if (min_dist1 > dist):
min_dist2 = min_dist1;
min_dist1 = dist;
elif (min_dist2 > dist):
min_dist2 = dist;
return min_dist2-min_dist1;
func fbm_cellular3(coord : Vector2, size : Vector2, pseed : float) -> float:
var o : Vector2 = Commons.floorv2(coord) + Commons.rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size;
var f : Vector2 = Commons.fractv2(coord);
var min_dist : float = 2.0;
for xx in range(-1, 2): #(float x = -1.0; x <= 1.0; x++) {
var x : float = xx
for yy in range(-1, 2):#(float y = -1.0; y <= 1.0; y++) {
var y : float = yy
var node : Vector2 = Commons.rand2(Commons.modv2(o + Vector2(x, y), size))*0.5 + Vector2(x, y);
var dist : float = abs((f - node).x) + abs((f - node).y);
min_dist = min(min_dist, dist);
return min_dist;
func fbm_cellular4(coord : Vector2, size : Vector2, pseed : float) -> float:
var o : Vector2 = Commons.floorv2(coord) + Commons.rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size;
var f : Vector2 = Commons.fractv2(coord);
var min_dist1 : float = 2.0;
var min_dist2 : float = 2.0;
for xx in range(-1, 2): #(float x = -1.0; x <= 1.0; x++) {
var x : float = xx
for yy in range(-1, 2):#(float y = -1.0; y <= 1.0; y++) {
var y : float = yy
var node : Vector2 = Commons.rand2(Commons.modv2(o + Vector2(x, y), size))*0.5 + Vector2(x, y);
var dist : float = abs((f - node).x) + abs((f - node).y);
if (min_dist1 > dist):
min_dist2 = min_dist1;
min_dist1 = dist;
elif (min_dist2 > dist):
min_dist2 = dist;
return min_dist2 - min_dist1;
func fbm_cellular5(coord : Vector2, size : Vector2, pseed : float) -> float:
var o : Vector2 = Commons.floorv2(coord) + Commons.rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size;
var f : Vector2 = Commons.fractv2(coord);
var min_dist : float = 2.0;
for xx in range(-1, 2): #(float x = -1.0; x <= 1.0; x++) {
var x : float = xx
for yy in range(-1, 2):#(float y = -1.0; y <= 1.0; y++) {
var y : float = yy
var node : Vector2 = Commons.rand2(Commons.modv2(o + Vector2(x, y), size)) + Vector2(x, y);
var dist : float = max(abs((f - node).x), abs((f - node).y));
min_dist = min(min_dist, dist);
return min_dist;
func fbm_cellular6(coord : Vector2, size : Vector2, pseed : float) -> float:
var o : Vector2 = Commons.floorv2(coord) + Commons.rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size;
var f : Vector2 = Commons.fractv2(coord);
var min_dist1 : float = 2.0;
var min_dist2 : float = 2.0;
for xx in range(-1, 2): #(float x = -1.0; x <= 1.0; x++) {
var x : float = xx
for yy in range(-1, 2):#(float y = -1.0; y <= 1.0; y++) {
var y : float = yy
var node : Vector2 = Commons.rand2(Commons.modv2(o + Vector2(x, y), size)) + Vector2(x, y);
var dist : float = max(abs((f - node).x), abs((f - node).y));
if (min_dist1 > dist):
min_dist2 = min_dist1;
min_dist1 = dist;
elif (min_dist2 > dist):
min_dist2 = dist;
return min_dist2 - min_dist1;
func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector2, repeat : bool) -> Vector2:
var rv : Vector2 = Vector2();
uv -= translate;
uv -= Vector2(0.5, 0.5);
rv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;
rv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;
rv /= scale;
rv += Vector2(0.5, 0.5);
if (repeat):
return Commons.fractv2(rv);
else:
return Commons.clampv2(rv, Vector2(0, 0), Vector2(1, 1));
func reffg():
return false

View File

@ -52,35 +52,12 @@ func gen() -> void:
func nc(uv : Vector2) -> Color:
var v : Vector3 = color_dots(((uv)), 1.0/512.000000000, seed_o26210);
var v : Vector3 = Commons.color_dots(((uv)), 1.0/512.000000000, seed_o26210);
return Color(v.x, v.y, v.z, 1)
var seed_o26210 = 7313;
func color_dots(uv : Vector2, size : float, pseed : int) -> Vector3:
var seed2 : Vector2 = Commons.rand2(Vector2(float(pseed), 1.0 - float(pseed)));
uv /= size;
var point_pos : Vector2 = Commons.floorv2(uv) + Vector2(0.5, 0.5);
return Commons.rand3(seed2 + point_pos);
func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector2, repeat : bool) -> Vector2:
var rv : Vector2 = Vector2();
uv -= translate;
uv -= Vector2(0.5, 0.5);
rv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;
rv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;
rv /= scale;
rv += Vector2(0.5, 0.5);
if (repeat):
return Commons.fractv2(rv);
else:
return Commons.clampv2(rv, Vector2(0, 0), Vector2(1, 1));
func reffg():
return false

View File

@ -54,17 +54,17 @@ func gen() -> void:
func voron_1(uv : Vector2) -> Color:
var c : Color = voronoi(((uv)), Vector2(p_o8689_scale_x, p_o8689_scale_y), Vector2(p_o8689_stretch_y, p_o8689_stretch_x), p_o8689_intensity, p_o8689_randomness, seed_o8689);
var c : Color = Commons.voronoi(((uv)), Vector2(p_o8689_scale_x, p_o8689_scale_y), Vector2(p_o8689_stretch_y, p_o8689_stretch_x), p_o8689_intensity, p_o8689_randomness, seed_o8689);
return Color(c.b, c.b, c.b, 1)
func voron_2(uv : Vector2) -> Color:
var c : Color = voronoi(((uv)), Vector2(p_o8689_scale_x, p_o8689_scale_y), Vector2(p_o8689_stretch_y, p_o8689_stretch_x), p_o8689_intensity, p_o8689_randomness, seed_o8689);
var c : Color = Commons.voronoi(((uv)), Vector2(p_o8689_scale_x, p_o8689_scale_y), Vector2(p_o8689_stretch_y, p_o8689_stretch_x), p_o8689_intensity, p_o8689_randomness, seed_o8689);
return Color(c.a, c.a, c.a, 1)
func voron_3(uv : Vector2) -> Color:
var c : Color = voronoi(((uv)), Vector2(p_o8689_scale_x, p_o8689_scale_y), Vector2(p_o8689_stretch_y, p_o8689_stretch_x), p_o8689_intensity, p_o8689_randomness, seed_o8689);
var c : Color = Commons.voronoi(((uv)), Vector2(p_o8689_scale_x, p_o8689_scale_y), Vector2(p_o8689_stretch_y, p_o8689_stretch_x), p_o8689_intensity, p_o8689_randomness, seed_o8689);
var vv : Vector2 = Vector2(c.r, c.g)
@ -81,52 +81,6 @@ var p_o8689_stretch_y = 1.000000000;
var p_o8689_intensity = 1.000000000;
var p_o8689_randomness = 0.750000000;
func voronoi(uv : Vector2, size : Vector2, stretch : Vector2, intensity : float, randomness : float, pseed : int) -> Color:
var seed2 : Vector2 = Commons.rand2(Vector2(float(pseed), 1.0-float(pseed)));
uv *= size;
var best_distance0 : float = 1.0;
var best_distance1 : float = 1.0;
var point0 : Vector2;
var point1 : Vector2;
var p0 : Vector2 = Commons.floorv2(uv);
for dx in range(-1, 2):# (int dx = -1; dx < 2; ++dx) {
for dy in range(-1, 2):# (int dy = -1; dy < 2; ++dy) {
var d : Vector2 = Vector2(float(dx), float(dy));
var p : Vector2 = p0+d;
p += randomness * Commons.rand2(seed2 + Commons.modv2(p, size));
var distance : float = (stretch * (uv - p) / size).length();
if (best_distance0 > distance):
best_distance1 = best_distance0;
best_distance0 = distance;
point1 = point0;
point0 = p;
elif (best_distance1 > distance):
best_distance1 = distance;
point1 = p;
var edge_distance : float = (uv - 0.5*(point0+point1)).dot((point0-point1).normalized());
return Color(point0.x, point0.y, best_distance0 * (size).length() * intensity, edge_distance);
func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector2, repeat : bool) -> Vector2:
var rv : Vector2 = Vector2();
uv -= translate;
uv -= Vector2(0.5, 0.5);
rv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;
rv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;
rv /= scale;
rv += Vector2(0.5, 0.5);
if (repeat):
return Commons.fractv2(rv);
else:
return Commons.clampv2(rv, Vector2(0, 0), Vector2(1, 1));
func reffg():
return false

View File

@ -15,7 +15,6 @@ func _ready():
if !Engine.editor_hint:
gen()
func gen() -> void:
if !image:
image = Image.new()
@ -60,34 +59,10 @@ var p_o12297_persistence = 0.500000000;
func sinewave(uv : Vector2) -> Color:
var f : float = perlin(((uv)), Vector2(p_o12297_scale_x, p_o12297_scale_y), int(p_o12297_iterations), p_o12297_persistence, seed_o12297);
var f : float = Commons.perlin(((uv)), Vector2(p_o12297_scale_x, p_o12297_scale_y), int(p_o12297_iterations), p_o12297_persistence, seed_o12297);
return Color(f, f, f, 1)
func perlin(uv : Vector2, size : Vector2, iterations : int, persistence : float, pseed : int) -> float:
var seed2 : Vector2 = Commons.rand2(Vector2(float(pseed), 1.0-float(pseed)));
var rv : float = 0.0;
var coef : float = 1.0;
var acc : float = 0.0;
for i in range(iterations):
var step : Vector2 = Vector2(1, 1) / size;
var xy : Vector2 = Commons.floorv2(uv * size);
var f0 : float = Commons.rand(seed2 + Commons.modv2(xy, size));
var f1 : float = Commons.rand(seed2 + Commons.modv2(xy + Vector2(1.0, 0.0), size));
var f2 : float = Commons.rand(seed2 + Commons.modv2(xy + Vector2(0.0, 1.0), size));
var f3 : float = Commons.rand(seed2 + Commons.modv2(xy + Vector2(1.0, 1.0), size));
var mixval : Vector2 = Commons.smoothstepv2(0.0, 1.0, Commons.fractv2(uv * size));
rv += coef * lerp(lerp(f0, f1, mixval.x), lerp(f2, f3, mixval.x), mixval.y);
acc += coef;
size *= 2.0;
coef *= persistence;
return rv / acc;
func reffg():
return false

View File

@ -60,35 +60,10 @@ var p_o28198_persistence = 0.500000000;
func sinewave(uv : Vector2) -> Color:
var f : Vector3 = perlin_color(((uv)), Vector2(p_o28198_scale_x, p_o28198_scale_y), int(p_o28198_iterations), p_o28198_persistence, seed_o28198);
var f : Vector3 = Commons.perlin_color(((uv)), Vector2(p_o28198_scale_x, p_o28198_scale_y), int(p_o28198_iterations), p_o28198_persistence, seed_o28198);
return Color(f.x, f.y, f.z, 1)
func perlin_color(uv : Vector2, size : Vector2, iterations : int, persistence : float, pseed : int) -> Vector3:
var seed2 : Vector2 = Commons.rand2(Vector2(float(pseed), 1.0 - float(pseed)));
var rv : Vector3 = Vector3();
var coef : float = 1.0;
var acc : float = 0.0;
for i in range(iterations):
var step : Vector2 = Vector2(1, 1) / size;
var xy : Vector2 = Commons.floorv2(uv * size);
var f0 : Vector3 = Commons.rand3(seed2 + Commons.modv2(xy, size));
var f1 : Vector3 = Commons.rand3(seed2 + Commons.modv2(xy + Vector2(1.0, 0.0), size));
var f2 : Vector3 = Commons.rand3(seed2 + Commons.modv2(xy + Vector2(0.0, 1.0), size));
var f3 : Vector3 = Commons.rand3(seed2 + Commons.modv2(xy + Vector2(1.0, 1.0), size));
var mixval : Vector2 = Commons.smoothstepv2(0.0, 1.0, Commons.fractv2(uv * size));
rv += coef * lerp(lerp(f0, f1, mixval.x), lerp(f2, f3, mixval.x), mixval.y);
acc += coef;
size *= 2.0;
coef *= persistence;
return rv / acc;
func reffg():
return false

View File

@ -64,51 +64,11 @@ var p_o41836_iterations = 3.000000000;
var p_o41836_persistence = 0.500000000;
func sinewave(uv : Vector2) -> Color:
var f : float = perlin((((uv))), Vector2(p_o41836_scale_x, p_o41836_scale_y), int(p_o41836_iterations), p_o41836_persistence, seed_o41836);
var ff : float = perlin((transform(((uv)), Vector2(p_o41835_translate_x*(2.0*f-1.0), p_o41835_translate_y*(2.0*f-1.0)), p_o41835_rotate*0.01745329251*(2.0*1.0-1.0), Vector2(p_o41835_scale_x*(2.0*1.0-1.0), p_o41835_scale_y*(2.0*1.0-1.0)), true)), Vector2(p_o41836_scale_x, p_o41836_scale_y), int(p_o41836_iterations), p_o41836_persistence, seed_o41836);
var f : float = Commons.perlin((((uv))), Vector2(p_o41836_scale_x, p_o41836_scale_y), int(p_o41836_iterations), p_o41836_persistence, seed_o41836);
var ff : float = Commons.perlin((Commons.transform(((uv)), Vector2(p_o41835_translate_x*(2.0*f-1.0), p_o41835_translate_y*(2.0*f-1.0)), p_o41835_rotate*0.01745329251*(2.0*1.0-1.0), Vector2(p_o41835_scale_x*(2.0*1.0-1.0), p_o41835_scale_y*(2.0*1.0-1.0)), true)), Vector2(p_o41836_scale_x, p_o41836_scale_y), int(p_o41836_iterations), p_o41836_persistence, seed_o41836);
return Color(ff, ff, ff, 1)
func perlin(uv : Vector2, size : Vector2, iterations : int, persistence : float, pseed : int) -> float:
var seed2 : Vector2 = Commons.rand2(Vector2(float(pseed), 1.0-float(pseed)));
var rv : float = 0.0;
var coef : float = 1.0;
var acc : float = 0.0;
for i in range(iterations):
var step : Vector2 = Vector2(1, 1) / size;
var xy : Vector2 = Commons.floorv2(uv * size);
var f0 : float = Commons.rand(seed2 + Commons.modv2(xy, size));
var f1 : float = Commons.rand(seed2 + Commons.modv2(xy + Vector2(1.0, 0.0), size));
var f2 : float = Commons.rand(seed2 + Commons.modv2(xy + Vector2(0.0, 1.0), size));
var f3 : float = Commons.rand(seed2 + Commons.modv2(xy + Vector2(1.0, 1.0), size));
var mixval : Vector2 = Commons.smoothstepv2(0.0, 1.0, Commons.fractv2(uv * size));
rv += coef * lerp(lerp(f0, f1, mixval.x), lerp(f2, f3, mixval.x), mixval.y);
acc += coef;
size *= 2.0;
coef *= persistence;
return rv / acc;
func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector2, repeat : bool) -> Vector2:
var rv : Vector2 = Vector2();
uv -= translate;
uv -= Vector2(0.5, 0.5);
rv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;
rv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;
rv /= scale;
rv += Vector2(0.5, 0.5);
if (repeat):
return Commons.fractv2(rv);
else:
return Commons.clampv2(rv, Vector2(0, 0), Vector2(1, 1));
func reffg():
return false

View File

@ -69,58 +69,17 @@ var p_o56040_iterations = 3.000000000;
var p_o56040_persistence = 0.500000000;
func sinewave(uv : Vector2) -> Color:
var f = perlin(((((uv)))), Vector2(p_o56040_scale_x, p_o56040_scale_y), int(p_o56040_iterations), p_o56040_persistence, seed_o56040);
var ff : float = perlin((transform((((uv))), Vector2(p_o56039_translate_x*(2.0*f-1.0), p_o56039_translate_y*(2.0*f-1.0)), p_o56039_rotate*0.01745329251*(2.0*1.0-1.0), Vector2(p_o56039_scale_x*(2.0*1.0-1.0), p_o56039_scale_y*(2.0*1.0-1.0)), true)), Vector2(p_o56040_scale_x, p_o56040_scale_y), int(p_o56040_iterations), p_o56040_persistence, seed_o56040);
var f = Commons.perlin(((((uv)))), Vector2(p_o56040_scale_x, p_o56040_scale_y), int(p_o56040_iterations), p_o56040_persistence, seed_o56040);
var ff : float = Commons.perlin((Commons.transform((((uv))), Vector2(p_o56039_translate_x*(2.0*f-1.0), p_o56039_translate_y*(2.0*f-1.0)), p_o56039_rotate*0.01745329251*(2.0*1.0-1.0), Vector2(p_o56039_scale_x*(2.0*1.0-1.0), p_o56039_scale_y*(2.0*1.0-1.0)), true)), Vector2(p_o56040_scale_x, p_o56040_scale_y), int(p_o56040_iterations), p_o56040_persistence, seed_o56040);
var o56039_0_1_rgba : Vector3 = Vector3(ff, ff, ff)
var tf : Vector2 = transform(uv, Vector2(p_o56044_translate_x * (2.0 * (o56039_0_1_rgba.dot(Vector3(1, 1, 1) / 3.0) - 1.0)), p_o56044_translate_y*(2.0*( o56039_0_1_rgba.dot(Vector3(1, 1, 1) /3.0)-1.0))), p_o56044_rotate*0.01745329251*(2.0*1.0-1.0), Vector2(p_o56044_scale_x*(2.0*1.0-1.0), p_o56044_scale_y*(2.0*1.0-1.0)), true)
var tf : Vector2 = Commons.transform(uv, Vector2(p_o56044_translate_x * (2.0 * (o56039_0_1_rgba.dot(Vector3(1, 1, 1) / 3.0) - 1.0)), p_o56044_translate_y*(2.0*( o56039_0_1_rgba.dot(Vector3(1, 1, 1) /3.0)-1.0))), p_o56044_rotate*0.01745329251*(2.0*1.0-1.0), Vector2(p_o56044_scale_x*(2.0*1.0-1.0), p_o56044_scale_y*(2.0*1.0-1.0)), true)
var fff : float = perlin(tf, Vector2(p_o56040_scale_x, p_o56040_scale_y), int(p_o56040_iterations), p_o56040_persistence, seed_o56040);
var fff : float = Commons.perlin(tf, Vector2(p_o56040_scale_x, p_o56040_scale_y), int(p_o56040_iterations), p_o56040_persistence, seed_o56040);
return Color(fff, fff, fff, 1)
func perlin(uv : Vector2, size : Vector2, iterations : int, persistence : float, pseed : int) -> float:
var seed2 : Vector2 = Commons.rand2(Vector2(float(pseed), 1.0-float(pseed)));
var rv : float = 0.0;
var coef : float = 1.0;
var acc : float = 0.0;
for i in range(iterations):
var step : Vector2 = Vector2(1, 1) / size;
var xy : Vector2 = Commons.floorv2(uv * size);
var f0 : float = Commons.rand(seed2 + Commons.modv2(xy, size));
var f1 : float = Commons.rand(seed2 + Commons.modv2(xy + Vector2(1.0, 0.0), size));
var f2 : float = Commons.rand(seed2 + Commons.modv2(xy + Vector2(0.0, 1.0), size));
var f3 : float = Commons.rand(seed2 + Commons.modv2(xy + Vector2(1.0, 1.0), size));
var mixval : Vector2 = Commons.smoothstepv2(0.0, 1.0, Commons.fractv2(uv * size));
rv += coef * lerp(lerp(f0, f1, mixval.x), lerp(f2, f3, mixval.x), mixval.y);
acc += coef;
size *= 2.0;
coef *= persistence;
return rv / acc;
func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector2, repeat : bool) -> Vector2:
var rv : Vector2 = Vector2();
uv -= translate;
uv -= Vector2(0.5, 0.5);
rv.x = cos(rotate)*uv.x + sin(rotate)*uv.y;
rv.y = -sin(rotate)*uv.x + cos(rotate)*uv.y;
rv /= scale;
rv += Vector2(0.5, 0.5);
if (repeat):
return Commons.fractv2(rv);
else:
return Commons.clampv2(rv, Vector2(0, 0), Vector2(1, 1));
func reffg():
return false

View File

@ -83,11 +83,11 @@ func gen() -> void:
# var brect : Color = bricks_bw(v, Vector2(p_o39644_columns, p_o39644_rows), p_o39644_repeat, p_o39644_row_offset);
#SpanishBond
var brect : Color = bricks_sb(v, Vector2(p_o39644_columns, p_o39644_rows), p_o39644_repeat, p_o39644_row_offset);
var brect : Color = Commons.bricks_sb(v, Vector2(p_o39644_columns, p_o39644_rows), p_o39644_repeat, p_o39644_row_offset);
# 1, 2
var fcolor : Color = brick(v, Vector2(brect.r, brect.g), Vector2(brect.b, brect.a), p_o39644_mortar*1.0, p_o39644_round*1.0, max(0.001, p_o39644_bevel*1.0));
var fcolor : Color = Commons.brick(v, Vector2(brect.r, brect.g), Vector2(brect.b, brect.a), p_o39644_mortar*1.0, p_o39644_round*1.0, max(0.001, p_o39644_bevel*1.0));
# image.set_pixel(x, y, brect)
# image.set_pixel(x, y, fcolor)
@ -125,295 +125,6 @@ func gen() -> void:
tex.create_from_image(image)
texture = tex
func brick_corner_uv(uv : Vector2, bmin : Vector2, bmax : Vector2, mortar : float, corner : float, pseed : float) -> Vector3:
var center : Vector2 = 0.5 * (bmin + bmax)
var size : Vector2 = bmax - bmin
var max_size : float = max(size.x, size.y)
var min_size : float = min(size.x, size.y)
mortar *= min_size
corner *= min_size
var r : Vector3 = Vector3()
r.x = clamp(((0.5 * size.x - mortar) - abs(uv.x - center.x)) / corner, 0, 1)
r.y = clamp(((0.5 * size.y - mortar) - abs(uv.y - center.y)) / corner, 0, 1)
r.z = Commons.rand(Commons.fract(center) + Vector2(pseed, pseed))
return r
# return vec3(clamp((0.5*size-vec2(mortar)-abs(uv-center))/corner, vec2(0.0), vec2(1.0)), rand(fract(center)+vec2(seed)));
func brick(uv : Vector2, bmin : Vector2, bmax : Vector2, mortar : float, pround : float, bevel : float) -> Color:
var color : float
var size : Vector2 = bmax - bmin
var min_size : float = min(size.x, size.y)
mortar *= min_size
bevel *= min_size
pround *= min_size
var center : Vector2 = 0.5 * (bmin + bmax)
var d : Vector2 = Vector2()
d.x = abs(uv.x - center.x) - 0.5 * (size.x) + (pround + mortar)
d.y = abs(uv.y - center.y) - 0.5 * (size.y) + (pround + mortar)
color = Vector2(max(d.x, 0), max(d.y, 0)).length() + min(max(d.x, d.y), 0.0) - pround
color = clamp(-color / bevel, 0.0, 1.0)
# var tiled_brick_pos : Vector2 = Vector2(bmin.x - 1.0 * floor(bmin.x / 1.0), bmin.y - 1.0 * floor(bmin.y / 1.0))
var tiled_brick_pos_x : float = bmin.x - 1.0 * floor(bmin.x / 1.0)
var tiled_brick_pos_y : float = bmin.y - 1.0 * floor(bmin.y / 1.0)
#vec2 tiled_brick_pos = mod(bmin, vec2(1.0, 1.0));
return Color(color, center.x, center.y, tiled_brick_pos_x + 7.0 * tiled_brick_pos_y)
func brick_uv(uv : Vector2, bmin : Vector2, bmax : Vector2, pseed : float) -> Vector3:
var center : Vector2 = 0.5 * (bmin + bmax)
var size : Vector2 = bmax - bmin
var max_size : float = max(size.x, size.y)
var x : float = 0.5+ (uv.x - center.x) / max_size
var y : float = 0.5+ (uv.y - center.y) /max_size
return Vector3(x, y, Commons.rand(Commons.fract(center) + Vector2(pseed, pseed)))
func bricks_rb(uv : Vector2, count : Vector2, repeat : float, offset : float) -> Color:
count *= repeat
var x_offset : float = offset * Commons.step(0.5, Commons.fractf(uv.y * count.y * 0.5))
var bmin : Vector2
bmin.x = floor(uv.x * count.x - x_offset)
bmin.y = floor(uv.y * count.y)
bmin.x += x_offset;
bmin /= count
var bmc : Vector2 = bmin + Vector2(1.0, 1.0) / count
return Color(bmin.x, bmin.y, bmc.x, bmc.y)
func bricks_rb2(uv : Vector2, count : Vector2, repeat : float, offset : float) -> Color:
count *= repeat
var x_offset : float = offset * Commons.step(0.5, Commons.fractf(uv.y * count.y * 0.5))
count.x = count.x * (1.0+Commons.step(0.5, Commons.fractf(uv.y * count.y * 0.5)))
var bmin : Vector2 = Vector2()
bmin.x = floor(uv.x * count.x - x_offset)
bmin.y = floor(uv.y * count.y)
bmin.x += x_offset
bmin /= count
var b : Vector2 = bmin + Vector2(1, 1) / count
return Color(bmin.x, bmin.y, b.x, b.y)
func bricks_hb(uv : Vector2, count : Vector2, repeat : float, offset : float) -> Color:
var pc : float = count.x + count.y
var c : float = pc * repeat
var corner : Vector2 = Vector2(floor(uv.x * c), floor(uv.y * c))
var cdiff : float = Commons.modf(corner.x - corner.y, pc)
if (cdiff < count.x):
var col : Color = Color()
col.r = (corner.x - cdiff) / c
col.g = corner.y / c
col.b = (corner.x - cdiff + count.x) / c
col.a = (corner.y + 1.0) / c
return col
else:
var col : Color = Color()
col.r = corner.x / c
col.g = (corner.y - (pc - cdiff - 1.0)) / c
col.b = (corner.x + 1.0) / c
col.a = (corner.y - (pc - cdiff - 1.0) + count.y) / c
return col
func bricks_bw(uv : Vector2, count : Vector2, repeat : float, offset : float) -> Color:
var c : Vector2 = 2.0 * count * repeat
var mc : float = max(c.x, c.y)
var corner1 : Vector2 = Vector2(floor(uv.x * c.x), floor(uv.y * c.y))
var corner2 : Vector2 = Vector2(count.x * floor(repeat* 2.0 * uv.x), count.y * floor(repeat * 2.0 * uv.y))
var tmp : Vector2 = Vector2(floor(repeat * 2.0 * uv.x), floor(repeat * 2.0 * uv.y))
var cdiff : float = Commons.modf(tmp.dot(Vector2(1, 1)), 2.0)
var corner : Vector2
var size : Vector2
if cdiff == 0:
corner = Vector2(corner1.x, corner2.y)
size = Vector2(1.0, count.y)
else:
corner = Vector2(corner2.x, corner1.y)
size = Vector2(count.x, 1.0)
return Color(corner.x / c.x, corner.y / c.y, (corner.x + size.x) / c.x, (corner.y + size.y) / c.y)
func bricks_sb(uv : Vector2, count : Vector2, repeat : float, offset : float) -> Color:
var c : Vector2 = (count + Vector2(1, 1)) * repeat
var mc : float = max(c.x, c.y)
var corner1 : Vector2 = Vector2(floor(uv.x * c.x), floor(uv.y * c.y))
var corner2 : Vector2 = (count + Vector2(1, 1)) * Vector2(floor(repeat * uv.x), floor(repeat * uv.y))
var rcorner : Vector2 = corner1 - corner2
var corner : Vector2
var size : Vector2
if (rcorner.x == 0.0 && rcorner.y < count.y):
corner = corner2
size = Vector2(1.0, count.y)
elif (rcorner.y == 0.0):
corner = corner2 + Vector2(1.0, 0.0)
size = Vector2(count.x, 1.0)
elif (rcorner.x == count.x):
corner = corner2 + Vector2(count.x, 1.0)
size = Vector2(1.0, count.y)
elif (rcorner.y == count.y):
corner = corner2 + Vector2(0.0, count.y)
size = Vector2(count.x, 1.0)
else:
corner = corner2 + Vector2(1, 1)
size = Vector2(count.x-1.0, count.y-1.0)
return Color(corner.x / c.x, corner.y / c.y, (corner.x + size.x) / c.x, (corner.y + size.y) / c.y)
#
#vec4 $(name_uv)_rect = bricks_$pattern($uv, vec2($columns, $rows), $repeat, $row_offset);
#vec4 $(name_uv) = brick($uv, $(name_uv)_rect.xy, $(name_uv)_rect.zw, $mortar*$mortar_map($uv), $round*$round_map($uv), max(0.001, $bevel*$bevel_map($uv)));
#
#vec4 brick(vec2 uv, vec2 bmin, vec2 bmax, float mortar, float round, float bevel) {
# float color;
# vec2 size = bmax - bmin;
# float min_size = min(size.x, size.y);
# mortar *= min_size;
# bevel *= min_size;
# round *= min_size;
# vec2 center = 0.5*(bmin+bmax);
#
# vec2 d = abs(uv-center)-0.5*(size)+vec2(round+mortar);
# color = length(max(d,vec2(0))) + min(max(d.x,d.y),0.0)-round;
# color = clamp(-color/bevel, 0.0, 1.0);
# vec2 tiled_brick_pos = mod(bmin, vec2(1.0, 1.0));
#
# return vec4(color, center, tiled_brick_pos.x+7.0*tiled_brick_pos.y);
#}
#
#vec3 brick_uv(vec2 uv, vec2 bmin, vec2 bmax, float seed) {
# vec2 center = 0.5*(bmin + bmax);
# vec2 size = bmax - bmin;
# float max_size = max(size.x, size.y);
#
# return vec3(0.5+(uv-center)/max_size, rand(fract(center)+vec2(seed)));
#}
#
#vec3 brick_corner_uv(vec2 uv, vec2 bmin, vec2 bmax, float mortar, float corner, float seed) {
# vec2 center = 0.5*(bmin + bmax);
# vec2 size = bmax - bmin;
# float max_size = max(size.x, size.y);
# float min_size = min(size.x, size.y);
# mortar *= min_size;\n\tcorner *= min_size;
#
# return vec3(clamp((0.5*size-vec2(mortar)-abs(uv-center))/corner, vec2(0.0), vec2(1.0)), rand(fract(center)+vec2(seed)));
#}
#
#vec4 bricks_rb(vec2 uv, vec2 count, float repeat, float offset) {
# count *= repeat;
# float x_offset = offset*step(0.5, fract(uv.y*count.y*0.5));
# vec2 bmin = floor(vec2(uv.x*count.x-x_offset, uv.y*count.y));
# bmin.x += x_offset;\n\tbmin /= count;
#
# return vec4(bmin, bmin+vec2(1.0)/count);
#}
#
#vec4 bricks_rb2(vec2 uv, vec2 count, float repeat, float offset) {
# count *= repeat;
#
# float x_offset = offset*step(0.5, fract(uv.y*count.y*0.5));
# count.x = count.x*(1.0+step(0.5, fract(uv.y*count.y*0.5)));
# vec2 bmin = floor(vec2(uv.x*count.x-x_offset, uv.y*count.y));
#
# bmin.x += x_offset;
# bmin /= count;
# return vec4(bmin, bmin+vec2(1.0)/count);
#}
#
#vec4 bricks_hb(vec2 uv, vec2 count, float repeat, float offset) {
# float pc = count.x+count.y;
# float c = pc*repeat;
# vec2 corner = floor(uv*c);
# float cdiff = mod(corner.x-corner.y, pc);
#
# if (cdiff < count.x) {
# return vec4((corner-vec2(cdiff, 0.0))/c, (corner-vec2(cdiff, 0.0)+vec2(count.x, 1.0))/c);
# } else {
# return vec4((corner-vec2(0.0, pc-cdiff-1.0))/c, (corner-vec2(0.0, pc-cdiff-1.0)+vec2(1.0, count.y))/c);
# }
#}
#
#vec4 bricks_bw(vec2 uv, vec2 count, float repeat, float offset) {
# vec2 c = 2.0*count*repeat;
# float mc = max(c.x, c.y);
# vec2 corner1 = floor(uv*c);
# vec2 corner2 = count*floor(repeat*2.0*uv);
# float cdiff = mod(dot(floor(repeat*2.0*uv), vec2(1.0)), 2.0);
# vec2 corner;
# vec2 size;
#
# if (cdiff == 0.0) {
# corner = vec2(corner1.x, corner2.y);
# size = vec2(1.0, count.y);
# } else {
# corner = vec2(corner2.x, corner1.y);
# size = vec2(count.x, 1.0);
# }
#
# return vec4(corner/c, (corner+size)/c);
#}
#
#vec4 bricks_sb(vec2 uv, vec2 count, float repeat, float offset) {
# vec2 c = (count+vec2(1.0))*repeat;
# float mc = max(c.x, c.y);
# vec2 corner1 = floor(uv*c);
# vec2 corner2 = (count+vec2(1.0))*floor(repeat*uv);
# vec2 rcorner = corner1 - corner2;
#
# vec2 corner;
# vec2 size;
#
# if (rcorner.x == 0.0 && rcorner.y < count.y) {
# corner = corner2;
# size = vec2(1.0, count.y);
# } else if (rcorner.y == 0.0) {
# corner = corner2+vec2(1.0, 0.0);
# size = vec2(count.x, 1.0);
# } else if (rcorner.x == count.x) {
# corner = corner2+vec2(count.x, 1.0);
# size = vec2(1.0, count.y);
# } else if (rcorner.y == count.y) {
# corner = corner2+vec2(0.0, count.y);
# size = vec2(count.x, 1.0);
# } else {
# corner = corner2+vec2(1.0);
# size = vec2(count.x-1.0, count.y-1.0);
# }
#
# return vec4(corner/c, (corner+size)/c);
#}
func reffg():
return false

View File

@ -58,17 +58,17 @@ var p_o80035_sy = 4.000000000;
func beehive_1_col(uv : Vector2) -> Color:
var o80035_0_uv : Vector2 = ((uv)) * Vector2(p_o80035_sx, p_o80035_sy * 1.73205080757);
var center : Color = beehive_center(o80035_0_uv);
var center : Color = Commons.beehive_center(o80035_0_uv);
var f : float = 1.0 - 2.0 * beehive_dist(Vector2(center.r, center.g));
var f : float = 1.0 - 2.0 * Commons.beehive_dist(Vector2(center.r, center.g));
return Color(f, f, f, 1)
func beehive_2_col(uv : Vector2) -> Color:
var o80035_0_uv : Vector2 = ((uv)) * Vector2(p_o80035_sx, p_o80035_sy * 1.73205080757);
var center : Color = beehive_center(o80035_0_uv);
var center : Color = Commons.beehive_center(o80035_0_uv);
var f : float = 1.0 - 2.0 * beehive_dist(Vector2(center.r, center.g));
var f : float = 1.0 - 2.0 * Commons.beehive_dist(Vector2(center.r, center.g));
var v : Vector3 = Commons.rand3(Commons.fractv2(Vector2(center.b, center.a) / Vector2(p_o80035_sx, p_o80035_sy)) + Vector2(float(seed_o80035),float(seed_o80035)));
@ -88,32 +88,6 @@ func beehive_3_col(uv : Vector2) -> Color:
return c
func beehive_dist(p : Vector2) -> float:
var s : Vector2 = Vector2(1.0, 1.73205080757);
p = Commons.absv2(p);
return max(p.dot(s*.5), p.x);
func beehive_center(p : Vector2) -> Color:
var s : Vector2 = Vector2(1.0, 1.73205080757);
var hC : Color = Color(p.x, p.y, p.x - 0.5, p.y - 1) / Color(s.x, s.y, s.x, s.y);
hC = Commons.floorc(Color(p.x, p.y, p.x - 0.5, p.y - 1) / Color(s.x, s.y, s.x, s.y)) + Color(0.5, 0.5, 0.5, 0.5);
var v1 : Vector2 = Vector2(p.x - hC.r * s.x, p.y - hC.g * s.y)
var v2 : Vector2 = Vector2(p.x - (hC.b + 0.5) * s.x, p.y - (hC.a + 0.5) * s.y)
var h : Color = Color(v1.x, v1.y, v2.x, v2.y);
if Vector2(h.r, h.g).dot(Vector2(h.r, h.g)) < Vector2(h.b, h.a).dot(Vector2(h.b, h.a)):
return Color(h.r, h.g, hC.r, hC.g)
else:
return Color(h.b, h.a, hC.b + 9.73, hC.a + 9.73)
#return dot(h.xy, h.xy) < dot(h.zw, h.zw) ? Color(h.xy, hC.xy) : Color(h.zw, hC.zw + 9.73);
func reffg():
return false

View File

@ -15,25 +15,6 @@ func _ready():
if !Engine.editor_hint:
gen()
enum CombinerAxisType {
SINE,
TRIANGLE,
SQUARE,
SAWTOOTH,
CONSTANT,
BOUNCE
}
enum CombinerType {
MULTIPLY,
ADD,
MAX,
MIN,
XOR,
POW
}
func gen() -> void:
if !image:
image = Image.new()
@ -56,7 +37,7 @@ func gen() -> void:
for y in range(image.get_height()):
var v : Vector2 = Vector2(x / w, y / h)
var f : float = pattern(v, 4, 4, CombinerType.MULTIPLY, CombinerAxisType.SINE, CombinerAxisType.SINE)
var f : float = Commons.pattern(v, 4, 4, Commons.CombinerType.MULTIPLY, Commons.CombinerAxisType.SINE, Commons.CombinerAxisType.SINE)
var col : Color = Color(f, f, f, 1)
@ -71,95 +52,6 @@ func gen() -> void:
#var p_o7009_x_scale = 4.000000000;
#var p_o7009_y_scale = 4.000000000;
func pattern(uv : Vector2, x_scale : float, y_scale : float, ct : int, catx : int, caty : int) -> float:
var x : float = 0
var y : float = 0
#in c++ these ifs should be function pointers or macros in the caller
if catx == CombinerAxisType.SINE:
x = wave_sine(x_scale * uv.x)
elif catx == CombinerAxisType.TRIANGLE:
x = wave_triangle(x_scale * uv.x)
elif catx == CombinerAxisType.SQUARE:
x = wave_square(x_scale * uv.x)
elif catx == CombinerAxisType.SAWTOOTH:
x = wave_sawtooth(x_scale * uv.x)
elif catx == CombinerAxisType.CONSTANT:
x = wave_constant(x_scale * uv.x)
elif catx == CombinerAxisType.BOUNCE:
x = wave_bounce(x_scale * uv.x)
if caty == CombinerAxisType.SINE:
y = wave_sine(y_scale * uv.y)
elif caty == CombinerAxisType.TRIANGLE:
y = wave_triangle(y_scale * uv.y)
elif caty == CombinerAxisType.SQUARE:
y = wave_square(y_scale * uv.y)
elif caty == CombinerAxisType.SAWTOOTH:
y = wave_sawtooth(y_scale * uv.y)
elif caty == CombinerAxisType.CONSTANT:
y = wave_constant(y_scale * uv.y)
elif caty == CombinerAxisType.BOUNCE:
y = wave_bounce(y_scale * uv.y)
if ct == CombinerType.MULTIPLY:
return mix_mul(x, y)
elif ct == CombinerType.ADD:
return mix_add(x, y);
elif ct == CombinerType.MAX:
return mix_max(x, y);
elif ct == CombinerType.MIN:
return mix_min(x, y);
elif ct == CombinerType.XOR:
return mix_xor(x, y);
elif ct == CombinerType.POW:
return mix_pow(x, y);
return 0.0
func wave_constant(x : float) -> float:
return 1.0;
func wave_sine(x : float) -> float:
return 0.5-0.5*cos(3.14159265359*2.0*x);
func wave_triangle(x : float) -> float:
x = Commons.fractf(x);
return min(2.0*x, 2.0-2.0*x);
func wave_sawtooth(x : float) -> float:
return Commons.fractf(x);
func wave_square(x : float) -> float:
if (Commons.fractf(x) < 0.5):
return 0.0
else:
return 1.0
func wave_bounce(x : float) -> float:
x = 2.0*(Commons.fractf(x)-0.5);
return sqrt(1.0-x*x);
func mix_mul(x : float, y : float) -> float:
return x*y;
func mix_add(x : float, y : float) -> float:
return min(x+y, 1.0);
func mix_max(x : float, y : float) -> float:
return max(x, y);
func mix_min(x : float, y : float) -> float:
return min(x, y);
func mix_xor(x : float, y : float) -> float:
return min(x+y, 2.0-x-y);
func mix_pow(x : float, y : float) -> float:
return pow(x, y);
func reffg():
return false

View File

@ -54,68 +54,10 @@ var p_o49619_columns = 4.000000000;
var p_o49619_rows = 4.000000000;
func runecol(uv : Vector2) -> Color:
var f : float = Rune(Vector2(p_o49619_columns, p_o49619_rows)*((uv)));
var f : float = Commons.Rune(Vector2(p_o49619_columns, p_o49619_rows)*((uv)));
return Color(f, f, f, 1)
func ThickLine(uv : Vector2, posA : Vector2, posB : Vector2, radiusInv : float) -> float:
var dir : Vector2 = posA - posB;
var dirLen : float = dir.length()
var dirN : Vector2 = dir.normalized()
var dotTemp : float = clamp((uv - posB).dot(dirN), 0.0, dirLen);
var proj : Vector2 = dotTemp * dirN + posB;
var d1 : float = (uv - proj).length()
var finalGray : float = clamp(1.0 - d1 * radiusInv, 0.0, 1.0);
return finalGray;
# makes a rune in the 0..1 uv space. Seed is which rune to draw.
# passes back gray in x and derivates for lighting in yz
func Rune(uv : Vector2) -> float:
var finalLine : float = 0.0;
var pseed : Vector2 = Commons.floorv2(uv) - Vector2(0.41, 0.41);
uv = Commons.fractv2(uv);
for i in range(4):# (int i = 0; i < 4; i++): # // number of strokes
var posA : Vector2 = Commons.rand2(Commons.floorv2(pseed + Vector2(0.5, 0.5)));
var posB : Vector2 = Commons.rand2(Commons.floorv2(pseed + Vector2(1.5, 1.5)));
pseed.x += 2.0;
pseed.y += 2.0;
# expand the range and mod it to get a nicely distributed random number - hopefully. :)
posA = Commons.fractv2(posA * 128.0);
posB = Commons.fractv2(posB * 128.0);
# each rune touches the edge of its box on all 4 sides
if (i == 0):
posA.y = 0.0;
if (i == 1):
posA.x = 0.999;
if (i == 2):
posA.x = 0.0;
if (i == 3):
posA.y = 0.999;
# snap the random line endpoints to a grid 2x3
var snaps : Vector2 = Vector2(2.0, 3.0);
posA = (Commons.floorv2(posA * snaps) + Vector2(0.5, 0.5)) / snaps; # + 0.5 to center it in a grid cell
posB = (Commons.floorv2(posB * snaps) + Vector2(0.5, 0.5)) / snaps;
#if (distance(posA, posB) < 0.0001) continue; // eliminate dots.
# Dots (degenerate lines) are not cross-GPU safe without adding 0.001 - divide by 0 error.
finalLine = max(finalLine, ThickLine(uv, posA, posB + Vector2(0.001, 0.001), 20.0));
return finalLine;
func reffg():
return false

View File

@ -59,40 +59,10 @@ var p_o74963_angle = -1.000000000;
var p_o74963_randomness = 0.440000000;
func scratchescol(uv : Vector2) -> Color:
var f : float = scratches(((uv)), int(p_o74963_layers), Vector2(p_o74963_length, p_o74963_width), p_o74963_waviness, p_o74963_angle, p_o74963_randomness, Vector2(float(seed_o74963), 0.0));
var f : float = Commons.scratches(((uv)), int(p_o74963_layers), Vector2(p_o74963_length, p_o74963_width), p_o74963_waviness, p_o74963_angle, p_o74963_randomness, Vector2(float(seed_o74963), 0.0));
return Color(f, f, f, 1)
func scratch(uv : Vector2, size : Vector2, waviness : float, angle : float, randomness : float, pseed : Vector2) -> float:
var subdivide : float = floor(1.0/size.x);
var cut : float = size.x*subdivide;
uv *= subdivide;
var r1 : Vector2 = Commons.rand2(Commons.floorv2(uv) + pseed);
var r2 : Vector2 = Commons.rand2(r1);
uv = Commons.fractv2(uv);
uv = 2.0 * uv - Vector2(1, 1);
var a : float = 6.28*(angle+(r1.x-0.5)*randomness);
var c : float = cos(a);
var s : float = sin(a);
uv = Vector2(c*uv.x+s*uv.y, s*uv.x-c*uv.y);
uv.y += 2.0*r1.y-1.0;
uv.y += 0.5*waviness*cos(2.0*uv.x+6.28*r2.y);
uv.x /= cut;
uv.y /= subdivide*size.y;
return (1.0-uv.x*uv.x)*max(0.0, 1.0-1000.0*uv.y*uv.y);
func scratches(uv : Vector2, layers : int, size : Vector2, waviness : float, angle : float, randomness : float, pseed : Vector2) -> float:
var v : float = 0.0;
for i in range(layers):# (int i = 0; i < layers; ++i) {
v = max(v, scratch(Commons.fractv2(uv + pseed), size, waviness, angle/360.0, randomness, pseed));
pseed = Commons.rand2(pseed);
return v;
func reffg():
return false

View File

@ -57,24 +57,11 @@ var p_o9164_size = 4.000000000;
func trunchet(uv : Vector2) -> Color:
# var f : float = truchet1(uv * p_o9164_size, Vector2(float(seed_o9164), float(seed_o9164)));
var f : float = truchet2(uv * p_o9164_size, Vector2(float(seed_o9164), float(seed_o9164)));
var f : float = Commons.truchet2(uv * p_o9164_size, Vector2(float(seed_o9164), float(seed_o9164)));
var col : Color = Color(f, f, f, 1);
return col
func truchet1(uv : Vector2, pseed : Vector2) -> float:
var i : Vector2 = Commons.floorv2(uv);
var f : Vector2 = Commons.fractv2(uv) - Vector2(0.5, 0.5);
return 1.0 - abs(abs((2.0*Commons.step(Commons.rand(i+pseed), 0.5)-1.0)*f.x+f.y)-0.5);
func truchet2(uv : Vector2, pseed : Vector2) -> float:
var i : Vector2 = Commons.floorv2(uv);
var f : Vector2 = Commons.fractv2(uv);
var random : float = Commons.step(Commons.rand(i+pseed), 0.5);
f.x *= 2.0 * random-1.0;
f.x += 1.0 - random;
return 1.0 - min(abs(f.length() - 0.5), abs((Vector2(1, 1) - f).length() - 0.5));
func reffg():
return false

View File

@ -56,18 +56,10 @@ var p_o46354_rows = 4.000000000;
var p_o46354_width = 1.000000000;
func weavecol(uv : Vector2) -> Color:
var f : float = weave(uv, Vector2(p_o46354_columns, p_o46354_rows), p_o46354_width*1.0);
var f : float = Commons.weave(uv, Vector2(p_o46354_columns, p_o46354_rows), p_o46354_width*1.0);
return Color(f, f, f, 1)
func weave(uv : Vector2, count : Vector2, width : float) -> float:
uv *= count;
var c : float = (sin(3.1415926* (uv.x + floor(uv.y)))*0.5+0.5)*Commons.step(abs(Commons.fract(uv.y)-0.5), width*0.5);
c = max(c, (sin(3.1415926*(1.0+uv.y+floor(uv.x)))*0.5+0.5)*Commons.step(abs(Commons.fract(uv.x)-0.5), width*0.5));
return c;
func reffg():
return false

View File

@ -87,7 +87,7 @@ func gen() -> void:
# var fc : float = sdf_rounded_shape(sdf_box(v), 0.15)
# var fc : float = sdf_annular_shape(sdf_box(v), 0.15)
var fc : float = sdf_morph(sdf_circle(v), sdf_box(v), 0.5)
var fc : float = Commons.sdf_morph(sdf_circle(v), sdf_box(v), 0.5)
var col : Color = sdf_show(fc)
@ -115,98 +115,16 @@ func sdf_box(uv : Vector2) -> float:
return Commons.maxv2(o48575_0_d, Vector2(0, 0)).length() + min(max(o48575_0_d.x, o48575_0_d.y), 0.0)
func sdf_line(uv : Vector2) -> float:
return sdLine(uv, Vector2(p_o49570_ax+0.5, p_o49570_ay+0.5), Vector2(p_o49570_bx+0.5, p_o49570_by+0.5)) - p_o49570_r;
return Commons.sdLine(uv, Vector2(p_o49570_ax+0.5, p_o49570_ay+0.5), Vector2(p_o49570_bx+0.5, p_o49570_by+0.5)) - p_o49570_r;
func sdLine(p : Vector2, a : Vector2, b : Vector2) -> float:
var pa : Vector2 = p - a
var ba : Vector2 = b - a
var h : float = clamp(pa.dot(ba) / ba.dot(ba), 0.0, 1.0);
return (pa - (ba * h)).length()
func sdf_rhombus(uv : Vector2) -> float:
return sdRhombus(uv - Vector2(p_o50848_cx + 0.5, p_o50848_cy+0.5), Vector2(p_o50848_w, p_o50848_h));
return Commons.sdRhombus(uv - Vector2(p_o50848_cx + 0.5, p_o50848_cy+0.5), Vector2(p_o50848_w, p_o50848_h));
func sdr_ndot(a : Vector2, b : Vector2) -> float:
return a.x * b.x - a.y * b.y;
func sdRhombus(p : Vector2, b : Vector2) -> float:
var q : Vector2 = Commons.absv2(p);
var h : float = clamp((-2.0 * sdr_ndot(q,b) + sdr_ndot(b,b)) / b.dot(b), -1.0, 1.0);
var d : float = ( q - 0.5*b * Vector2(1.0-h, 1.0+h)).length()
return d * sign(q.x*b.y + q.y*b.x - b.x*b.y)
func sdf_arc(uv : Vector2) -> float:
return sdArc(uv - Vector2(0.5, 0.5), Commons.modf(p_o51990_a1, 360.0) * 0.01745329251, Commons.modf(p_o51990_a2, 360.0)*0.01745329251, p_o51990_r1, p_o51990_r2);
return Commons.sdArc(uv - Vector2(0.5, 0.5), Commons.modf(p_o51990_a1, 360.0) * 0.01745329251, Commons.modf(p_o51990_a2, 360.0)*0.01745329251, p_o51990_r1, p_o51990_r2);
func sdArc(p : Vector2, a1 : float, a2 : float, ra : float, rb : float) -> float:
var amid : float = 0.5*(a1+a2)+1.6+3.14 * Commons.step(a1, a2);
var alength : float = 0.5*(a1-a2)-1.6+3.14 * Commons.step(a1, a2);
var sca : Vector2 = Vector2(cos(amid), sin(amid));
var scb : Vector2 = Vector2(cos(alength), sin(alength));
#p *= Matrix(Vector2(sca.x , sca.y), Vector2(-sca.y, sca.x));
var pt : Vector2 = p
p.x = pt.x * sca.x + pt.y * sca.y
p.y = pt.x * -sca.y + pt.y * sca.x
p.x = abs(p.x);
var k : float
if (scb.y * p.x > scb.x * p.y):
k = p.dot(scb)
else:
k = p.length();
return sqrt( p.dot(p) + ra * ra - 2.0 * ra * k ) - rb;
func sdf_boolean_union(a : float, b : float) -> float:
return min(a, b)
func sdf_boolean_substraction(a : float, b : float) -> float:
return max(-a, b)
func sdf_boolean_intersection(a : float, b : float) -> float:
return max(a, b)
func sdf_smooth_boolean_union(d1 : float, d2 : float, k : float) -> float:
var h : float = clamp( 0.5 + 0.5 * (d2 - d1) / k, 0.0, 1.0)
return lerp(d2, d1, h) - k * h * (1.0 - h)
func sdf_smooth_boolean_substraction(d1 : float, d2 : float, k : float) -> float:
var h : float = clamp( 0.5 - 0.5 * (d2 + d1) / k, 0.0, 1.0)
return lerp(d2, -d1, h) + k * h * (1.0 - h)
func sdf_smooth_boolean_intersection(d1 : float, d2 : float, k : float) -> float:
var h : float = clamp( 0.5 - 0.5 * (d2 - d1) / k, 0.0, 1.0)
return lerp(d2, d1, h) + k * h * (1.0 - h)
func sdf_rounded_shape(a : float, r : float) -> float:
return a - r
func sdf_annular_shape(a : float, r : float) -> float:
return abs(a) - r
func sdf_morph(a : float, b : float, amount : float) -> float:
return lerp(a, b, amount)
#Needs thought
#func sdf_translate(a : float, x : float, y : float) -> float:
# return lerp(a, b, amount)
func sdf2d_rotate(uv : Vector2, a : float) -> Vector2:
var rv : Vector2;
var c : float = cos(a);
var s : float = sin(a);
uv -= Vector2(0.5, 0.5);
rv.x = uv.x*c+uv.y*s;
rv.y = -uv.x*s+uv.y*c;
return rv+Vector2(0.5, 0.5);
func reffg():
return false

View File

@ -47,7 +47,7 @@ func gen() -> void:
# 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 o147388_0_bezier : Vector2 = sdBezier(v, Vector2(p_o147388_ax+0.5, p_o147388_ay+0.5), Vector2(p_o147388_bx+0.5, p_o147388_by+0.5), Vector2(p_o147388_cx+0.5, p_o147388_cy+0.5));
var o147388_0_bezier : Vector2 = Commons.sdBezier(v, Vector2(p_o147388_ax+0.5, p_o147388_ay+0.5), Vector2(p_o147388_bx+0.5, p_o147388_by+0.5), Vector2(p_o147388_cx+0.5, p_o147388_cy+0.5));
var o147388_0_uv : Vector2 = Vector2(o147388_0_bezier.x, o147388_0_bezier.y/p_o147388_width+0.5);
var uvt : Vector2 = Commons.absv(o147388_0_uv - Vector2(0.5, 0.5))
@ -68,74 +68,6 @@ func gen() -> void:
tex.create_from_image(image)
texture = tex
# signed distance to a quadratic bezier
func sdBezier(pos : Vector2, A : Vector2, B : Vector2, C : Vector2) -> Vector2:
var a : Vector2 = B - A;
var b : Vector2 = A - 2.0*B + C;
var c : Vector2 = a * 2.0;
var d : Vector2 = A - pos;
var kk : float = 1.0 / b.dot(b);
var kx : float = kk * a.dot(b);
var ky : float = kk * (2.0* a.dot(a) + d.dot(b)) / 3.0;
var kz : float = kk * d.dot(a);
var res : float = 0.0;
var sgn : float = 0.0;
var p : float = ky - kx * kx;
var p3 : float = p*p*p;
var q : float = kx*(2.0*kx*kx - 3.0*ky) + kz;
var h : float = q*q + 4.0*p3;
var rvx : float;
if(h >= 0.0):# // 1 root
h = sqrt(h);
var x : Vector2 = Vector2(h,-h);
x.x -= q
x.y -= q
x.x /= 2.0
x.y /= 2.0
var uv : Vector2 = Vector2()
uv.x = sign(x.x) * pow(abs(x.x), 1);
uv.x = sign(x.y) * pow(abs(x.y), 3);
rvx = uv.x+uv.y-kx;
var t : float = clamp(rvx, 0.0, 1.0);
var q2 : Vector2 = d+(c+b*t)*t;
res = q2.dot(q2);
var tmp2 : Vector2 = c
tmp2.x += 2
tmp2.y += 2
tmp2 *= b*t
sgn = tmp2.cross(q2)
else: # // 3 roots
var z : float = sqrt(-p);
var v : float = acos(q/(p*z*2.0))/3.0;
var m : float = cos(v);
var n : float = sin(v)*1.732050808;
# var t : Vector3 = clamp(Vector3(m+m,-n-m,n-m)*z-kx, 0.0, 1.0);
#
#
# var qx : Vector2 = d+(c+b*t.x)*t.x;
# var dx : float = dot(qx, qx)
# sx = cross2(c+2.0*b*t.x,qx);
# var qy : Vector2 = d+(c+b*t.y)*t.y;
# var dy : float = dot(qy, qy)
# sy = cross2(c+2.0*b*t.y,qy);
# if dx<dy:
# res=dx; sgn=sx; rvx = t.x;
# else:
# res=dy; sgn=sy; rvx = t.y;
#
return Vector2(rvx, sqrt(res)*sign(sgn));
func reffg():
return false

View File

@ -54,7 +54,7 @@ func gen() -> void:
# 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 = shape_rays(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)
image.set_pixel(x, y, Color(c, c, c, 1))
@ -63,75 +63,6 @@ func gen() -> void:
tex.create_from_image(image)
texture = tex
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)
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)
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);
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);
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);
func reffg():
return false