Same change to perlin related calculations.

This commit is contained in:
Relintai 2021-10-02 18:45:29 +02:00
parent 735b1f67cd
commit 5129cda7f1
5 changed files with 65 additions and 76 deletions

View File

@ -18,7 +18,6 @@ enum CombinerType {
POW POW
} }
static func clampv3(v : Vector3, mi : Vector3, ma : Vector3) -> Vector3: static func clampv3(v : Vector3, mi : Vector3, ma : Vector3) -> Vector3:
v.x = clamp(v.x, mi.x, ma.x) v.x = clamp(v.x, mi.x, ma.x)
v.y = clamp(v.y, mi.y, ma.y) v.y = clamp(v.y, mi.y, ma.y)
@ -201,63 +200,12 @@ static func transform(uv : Vector2, translate : Vector2, rotate : float, scale :
else: else:
return clampv2(rv, Vector2(0, 0), Vector2(1, 1)); return clampv2(rv, Vector2(0, 0), Vector2(1, 1));
static func color_dots(uv : Vector2, size : float, pseed : int) -> Vector3: static func color_dots(uv : Vector2, size : float, pseed : int) -> Vector3:
var seed2 : Vector2 = rand2(Vector2(float(pseed), 1.0 - float(pseed))); var seed2 : Vector2 = rand2(Vector2(float(pseed), 1.0 - float(pseed)));
uv /= size; uv /= size;
var point_pos : Vector2 = floorv2(uv) + Vector2(0.5, 0.5); var point_pos : Vector2 = floorv2(uv) + Vector2(0.5, 0.5);
return rand3(seed2 + point_pos); return rand3(seed2 + point_pos);
static func perlin(uv : Vector2, size : Vector2, iterations : int, persistence : float, pseed : int) -> float:
var seed2 : Vector2 = 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 = floorv2(uv * size);
var f0 : float = rand(seed2 + modv2(xy, size));
var f1 : float = rand(seed2 + modv2(xy + Vector2(1.0, 0.0), size));
var f2 : float = rand(seed2 + modv2(xy + Vector2(0.0, 1.0), size));
var f3 : float = rand(seed2 + modv2(xy + Vector2(1.0, 1.0), size));
var mixval : Vector2 = smoothstepv2(0.0, 1.0, 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;
static func perlin_color(uv : Vector2, size : Vector2, iterations : int, persistence : float, pseed : int) -> Vector3:
var seed2 : Vector2 = 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 = floorv2(uv * size);
var f0 : Vector3 = rand3(seed2 + modv2(xy, size));
var f1 : Vector3 = rand3(seed2 + modv2(xy + Vector2(1.0, 0.0), size));
var f2 : Vector3 = rand3(seed2 + modv2(xy + Vector2(0.0, 1.0), size));
var f3 : Vector3 = rand3(seed2 + modv2(xy + Vector2(1.0, 1.0), size));
var mixval : Vector2 = smoothstepv2(0.0, 1.0, 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;
static func beehive_dist(p : Vector2) -> float: static func beehive_dist(p : Vector2) -> float:
var s : Vector2 = Vector2(1.0, 1.73205080757); var s : Vector2 = Vector2(1.0, 1.73205080757);

View File

@ -0,0 +1,52 @@
extends Reference
const Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
static 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;
static func perlinc(uv : Vector2, size : Vector2, iterations : int, persistence : float, pseed : int) -> Color:
var f : float = perlin(uv, size, iterations, persistence, pseed)
return Color(f, f, f, 1)
static func perlin_warp_1(uv : Vector2, size : Vector2, iterations : int, persistence : float, pseed : int, translate : Vector2, rotate : float, size2 : Vector2) -> Color:
var f : float = perlin(uv, size2, iterations, persistence, pseed)
var vt : Vector2 = Commons.transform(uv, Vector2(translate.x*(2.0*f-1.0), translate.y*(2.0*f-1.0)), rotate*0.01745329251*(2.0*1.0-1.0), Vector2(size.x*(2.0*1.0-1.0), size.y*(2.0*1.0-1.0)), true)
var ff : float = perlin(vt, size2, iterations, persistence, pseed)
return Color(ff, ff, ff, 1)
static func perlin_warp_2(uv : Vector2, size : Vector2, iterations : int, persistence : float, pseed : int, translate : Vector2, rotate : float, size2 : Vector2) -> Color:
var f = perlin(uv, size2, iterations, persistence, pseed)
var vt : Vector2 = Commons.transform(uv, Vector2(translate.x*(2.0*f-1.0), translate.y*(2.0*f-1.0)), rotate*0.01745329251*(2.0*1.0-1.0), Vector2(size.x*(2.0*1.0-1.0), size.y*(2.0*1.0-1.0)), true)
var ff : float = perlin(vt, size2, iterations, persistence, pseed)
var rgba : Vector3 = Vector3(ff, ff, ff)
var tf : Vector2 = Commons.transform(uv, Vector2(translate.x * (2.0 * (rgba.dot(Vector3(1, 1, 1) / 3.0) - 1.0)), translate.y*(2.0*(rgba.dot(Vector3(1, 1, 1) /3.0)-1.0))), rotate*0.01745329251*(2.0*1.0-1.0), Vector2(size.x*(2.0*1.0-1.0), size.y*(2.0*1.0-1.0)), true)
var fff : float = perlin(tf, size2, iterations, persistence, pseed);
return Color(fff, fff, fff, 1)

View File

@ -1,7 +1,7 @@
tool tool
extends TextureRect extends TextureRect
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd") var NoisePerlin = preload("res://addons/mat_maker_gd/nodes/common/noise_perlin.gd")
var image : Image var image : Image
var tex : ImageTexture var tex : ImageTexture
@ -39,7 +39,7 @@ func gen() -> void:
# var f : float = pattern(v, 4, 4, CombinerType.MULTIPLY, CombinerAxisType.SINE, CombinerAxisType.SINE) # var f : float = pattern(v, 4, 4, CombinerType.MULTIPLY, CombinerAxisType.SINE, CombinerAxisType.SINE)
var col : Color = sinewave(v) var col : Color = perlin(v)
# var col : Color = beehive_2_col(v) # var col : Color = beehive_2_col(v)
# var col : Color = beehive_3_col(v) # var col : Color = beehive_3_col(v)
@ -57,11 +57,9 @@ var p_o12297_scale_y = 4.000000000;
var p_o12297_iterations = 3.000000000; var p_o12297_iterations = 3.000000000;
var p_o12297_persistence = 0.500000000; var p_o12297_persistence = 0.500000000;
func sinewave(uv : Vector2) -> Color: func perlin(uv : Vector2) -> Color:
var a = NoisePerlin.perlinc(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 a
return Color(f, f, f, 1)
func reffg(): func reffg():
return false return false

View File

@ -2,6 +2,7 @@ tool
extends TextureRect extends TextureRect
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd") var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
var NoisePerlin = preload("res://addons/mat_maker_gd/nodes/common/noise_perlin.gd")
var image : Image var image : Image
var tex : ImageTexture var tex : ImageTexture
@ -40,7 +41,7 @@ func gen() -> void:
# var f : float = pattern(v, 4, 4, CombinerType.MULTIPLY, CombinerAxisType.SINE, CombinerAxisType.SINE) # var f : float = pattern(v, 4, 4, CombinerType.MULTIPLY, CombinerAxisType.SINE, CombinerAxisType.SINE)
var col : Color = sinewave(v) var col : Color = perlin_warp_1(v)
# var col : Color = beehive_2_col(v) # var col : Color = beehive_2_col(v)
# var col : Color = beehive_3_col(v) # var col : Color = beehive_3_col(v)
@ -63,11 +64,8 @@ var p_o41836_scale_y = 4.000000000;
var p_o41836_iterations = 3.000000000; var p_o41836_iterations = 3.000000000;
var p_o41836_persistence = 0.500000000; var p_o41836_persistence = 0.500000000;
func sinewave(uv : Vector2) -> Color: func perlin_warp_1(uv : Vector2) -> Color:
var f : float = Commons.perlin((((uv))), Vector2(p_o41836_scale_x, p_o41836_scale_y), int(p_o41836_iterations), p_o41836_persistence, seed_o41836); return NoisePerlin.perlin_warp_1(uv, Vector2(p_o41835_scale_x, p_o41835_scale_y), int(p_o41836_iterations), p_o41836_persistence, seed_o41836, Vector2(p_o41835_translate_x, p_o41835_translate_y), p_o41835_rotate, Vector2(p_o41836_scale_x, p_o41836_scale_y))
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 reffg(): func reffg():
return false return false

View File

@ -2,6 +2,7 @@ tool
extends TextureRect extends TextureRect
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd") var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
var NoisePerlin = preload("res://addons/mat_maker_gd/nodes/common/noise_perlin.gd")
var image : Image var image : Image
var tex : ImageTexture var tex : ImageTexture
@ -40,7 +41,7 @@ func gen() -> void:
# var f : float = pattern(v, 4, 4, CombinerType.MULTIPLY, CombinerAxisType.SINE, CombinerAxisType.SINE) # var f : float = pattern(v, 4, 4, CombinerType.MULTIPLY, CombinerAxisType.SINE, CombinerAxisType.SINE)
var col : Color = sinewave(v) var col : Color = perlin_warp_2(v)
# var col : Color = beehive_2_col(v) # var col : Color = beehive_2_col(v)
# var col : Color = beehive_3_col(v) # var col : Color = beehive_3_col(v)
@ -68,17 +69,9 @@ var p_o56040_scale_y = 4.000000000;
var p_o56040_iterations = 3.000000000; var p_o56040_iterations = 3.000000000;
var p_o56040_persistence = 0.500000000; var p_o56040_persistence = 0.500000000;
func sinewave(uv : Vector2) -> Color: func perlin_warp_2(uv : Vector2) -> Color:
var f = Commons.perlin(((((uv)))), Vector2(p_o56040_scale_x, p_o56040_scale_y), int(p_o56040_iterations), p_o56040_persistence, seed_o56040); return NoisePerlin.perlin_warp_2(uv, Vector2(p_o56044_scale_x, p_o56044_scale_y), int(p_o56040_iterations), p_o56040_persistence, seed_o56040, Vector2(p_o56044_translate_x, p_o56044_translate_y), p_o56044_rotate, Vector2(p_o56040_scale_x, p_o56040_scale_y))
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 = 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 = 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 reffg(): func reffg():
return false return false