diff --git a/game/addons/mat_maker_gd/nodes/noise/noise.gd b/game/addons/mat_maker_gd/nodes/noise/noise.gd index 33a3d4d3..613dba66 100644 --- a/game/addons/mat_maker_gd/nodes/noise/noise.gd +++ b/game/addons/mat_maker_gd/nodes/noise/noise.gd @@ -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 @@ -60,169 +62,6 @@ func sinewave(uv : Vector2) -> Color: return Color(f, f, f, 1) - -func clampv3(v : Vector3, mi : Vector3, ma : Vector3) -> Vector3: - v.x = clamp(v.x, mi.x, ma.x) - v.y = clamp(v.y, mi.y, ma.y) - v.y = clamp(v.z, mi.z, ma.z) - - return v - -func floorc(a : Color) -> Color: - var v : Color = Color() - - v.r = floor(a.r) - v.g = floor(a.g) - v.b = floor(a.b) - v.a = floor(a.a) - - return v - - -func floorv2(a : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = floor(a.x) - v.y = floor(a.y) - - return v - -func maxv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - - return v - -func maxv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - v.z = max(a.z, b.z) - - return v - -func absv2(v : Vector2) -> Vector2: - v.x = abs(v.x) - v.y = abs(v.y) - - return v - -func absv3(v : Vector3) -> Vector3: - v.x = abs(v.x) - v.y = abs(v.y) - v.y = abs(v.y) - - return v - -func cosv2(v : Vector2) -> Vector2: - v.x = cos(v.x) - v.y = cos(v.y) - - return v - -func cosv3(v : Vector3) -> Vector3: - v.x = cos(v.x) - v.y = cos(v.y) - v.y = cos(v.y) - - return v - -func modv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - v.z = modf(a.z, b.z) - - return v - - -func modv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - - return v - -func modf(x : float, y : float) -> float: - return x - y * floor(x / y) - -func fractv2(v : Vector2) -> Vector2: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - - return v - -func fractv3(v : Vector3) -> Vector3: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - v.z = v.z - floor(v.z) - - return v - -func fract(f : float) -> float: - return f - floor(f) - -func rand(x : Vector2) -> float: - return fract(cos(x.dot(Vector2(13.9898, 8.141))) * 43758.5453); - -func rand2(x : Vector2) -> Vector2: - return fractv2(cosv2(Vector2(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)))) * 43758.5453); - -func rand3(x : Vector2) -> Vector3: - return fractv3(cosv3(Vector3(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)), - x.dot(Vector2(13.254, 5.867)))) * 43758.5453); - -func step(edge : float, x : float) -> float: - if x < edge: - return 0.0 - else: - return 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.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 diff --git a/game/addons/mat_maker_gd/nodes/noise/noise_FBM.gd b/game/addons/mat_maker_gd/nodes/noise/noise_FBM.gd index 1093cb53..f33bf18e 100644 --- a/game/addons/mat_maker_gd/nodes/noise/noise_FBM.gd +++ b/game/addons/mat_maker_gd/nodes/noise/noise_FBM.gd @@ -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 @@ -206,23 +208,23 @@ func o33355_cellular6(coord : Vector2, size : Vector2, octaves : int, persistenc return value / normalize_factor; func fbm_value(coord : Vector2, size : Vector2, pseed : float) -> float: - var o : Vector2 = floorv2(coord) + rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size; - var f : Vector2 = fractv2(coord); - var p00 : float = rand(modv2(o, size)); - var p01 : float = rand(modv2(o + Vector2(0.0, 1.0), size)); - var p10 : float = rand(modv2(o + Vector2(1.0, 0.0), size)); - var p11 : float = rand(modv2(o + Vector2(1.0, 1.0), size)); + 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 = floorv2(coord) + rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size; - var f : Vector2 = fractv2(coord); - var a00 : float = rand(modv2(o, size)) * 6.28318530718; - var a01 : float = rand(modv2(o + Vector2(0.0, 1.0), size)) * 6.28318530718; - var a10 : float = rand(modv2(o + Vector2(1.0, 0.0), size)) * 6.28318530718; - var a11 : float = rand(modv2(o + Vector2(1.0, 1.0), size)) * 6.28318530718; + 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)); @@ -238,8 +240,8 @@ func fbm_perlin(coord : Vector2, size : Vector2, pseed : float) -> float: func fbm_cellular(coord : Vector2, size : Vector2, pseed : float) -> float: - var o : Vector2 = floorv2(coord) + rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size; - var f : Vector2 = fractv2(coord); + 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++) { @@ -248,15 +250,15 @@ func fbm_cellular(coord : Vector2, size : Vector2, pseed : float) -> float: for yy in range(-1, 2):#(float y = -1.0; y <= 1.0; y++) { var y : float = yy - var node : Vector2 = rand2(modv2(o + Vector2(x, y), size)) + Vector2(x, y); + 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 = floorv2(coord) + rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size; - var f : Vector2 = fractv2(coord); + 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; @@ -267,7 +269,7 @@ func fbm_cellular2(coord : Vector2, size : Vector2, pseed : float) -> float: for yy in range(-1, 2):#(float y = -1.0; y <= 1.0; y++) { var y : float = yy - var node : Vector2 = rand2(modv2(o + Vector2(x, y), size)) + Vector2(x, y); + 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); @@ -280,8 +282,8 @@ func fbm_cellular2(coord : Vector2, size : Vector2, pseed : float) -> float: return min_dist2-min_dist1; func fbm_cellular3(coord : Vector2, size : Vector2, pseed : float) -> float: - var o : Vector2 = floorv2(coord) + rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size; - var f : Vector2 = fractv2(coord); + 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; @@ -291,7 +293,7 @@ func fbm_cellular3(coord : Vector2, size : Vector2, pseed : float) -> float: for yy in range(-1, 2):#(float y = -1.0; y <= 1.0; y++) { var y : float = yy - var node : Vector2 = rand2(modv2(o + Vector2(x, y), size))*0.5 + Vector2(x, y); + 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); @@ -300,8 +302,8 @@ func fbm_cellular3(coord : Vector2, size : Vector2, pseed : float) -> float: return min_dist; func fbm_cellular4(coord : Vector2, size : Vector2, pseed : float) -> float: - var o : Vector2 = floorv2(coord) + rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size; - var f : Vector2 = fractv2(coord); + 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; @@ -312,7 +314,7 @@ func fbm_cellular4(coord : Vector2, size : Vector2, pseed : float) -> float: for yy in range(-1, 2):#(float y = -1.0; y <= 1.0; y++) { var y : float = yy - var node : Vector2 = rand2(modv2(o + Vector2(x, y), size))*0.5 + Vector2(x, y); + 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); @@ -325,8 +327,8 @@ func fbm_cellular4(coord : Vector2, size : Vector2, pseed : float) -> float: return min_dist2 - min_dist1; func fbm_cellular5(coord : Vector2, size : Vector2, pseed : float) -> float: - var o : Vector2 = floorv2(coord) + rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size; - var f : Vector2 = fractv2(coord); + 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; @@ -336,7 +338,7 @@ func fbm_cellular5(coord : Vector2, size : Vector2, pseed : float) -> float: for yy in range(-1, 2):#(float y = -1.0; y <= 1.0; y++) { var y : float = yy - var node : Vector2 = rand2(modv2(o + Vector2(x, y), size)) + Vector2(x, y); + 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); @@ -345,8 +347,8 @@ func fbm_cellular5(coord : Vector2, size : Vector2, pseed : float) -> float: func fbm_cellular6(coord : Vector2, size : Vector2, pseed : float) -> float: - var o : Vector2 = floorv2(coord) + rand2(Vector2(float(pseed), 1.0 - float(pseed))) + size; - var f : Vector2 = fractv2(coord); + 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; @@ -357,7 +359,7 @@ func fbm_cellular6(coord : Vector2, size : Vector2, pseed : float) -> float: for yy in range(-1, 2):#(float y = -1.0; y <= 1.0; y++) { var y : float = yy - var node : Vector2 = rand2(modv2(o + Vector2(x, y), size)) + Vector2(x, y); + 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): @@ -379,187 +381,11 @@ func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector rv += Vector2(0.5, 0.5); if (repeat): - return fractv2(rv); + return Commons.fractv2(rv); else: - return clampv2(rv, Vector2(0, 0), Vector2(1, 1)); + return Commons.clampv2(rv, Vector2(0, 0), Vector2(1, 1)); -func clampv3(v : Vector3, mi : Vector3, ma : Vector3) -> Vector3: - v.x = clamp(v.x, mi.x, ma.x) - v.y = clamp(v.y, mi.y, ma.y) - v.y = clamp(v.z, mi.z, ma.z) - - return v - -func floorc(a : Color) -> Color: - var v : Color = Color() - - v.r = floor(a.r) - v.g = floor(a.g) - v.b = floor(a.b) - v.a = floor(a.a) - - return v - - -func floorv2(a : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = floor(a.x) - v.y = floor(a.y) - - return v - -func smoothstepv2(a : float, b : float, c : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = smoothstep(a, b, c.x) - v.y = smoothstep(a, b, c.y) - - return v - -func maxv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - - return v - -func maxv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - v.z = max(a.z, b.z) - - return v - -func absv2(v : Vector2) -> Vector2: - v.x = abs(v.x) - v.y = abs(v.y) - - return v - -func absv3(v : Vector3) -> Vector3: - v.x = abs(v.x) - v.y = abs(v.y) - v.y = abs(v.y) - - return v - -func cosv2(v : Vector2) -> Vector2: - v.x = cos(v.x) - v.y = cos(v.y) - - return v - -func cosv3(v : Vector3) -> Vector3: - v.x = cos(v.x) - v.y = cos(v.y) - v.y = cos(v.y) - - return v - -func modv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - v.z = modf(a.z, b.z) - - return v - - -func modv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - - return v - -func modf(x : float, y : float) -> float: - return x - y * floor(x / y) - -func fractv2(v : Vector2) -> Vector2: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - - return v - -func fractv3(v : Vector3) -> Vector3: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - v.z = v.z - floor(v.z) - - return v - -func fract(f : float) -> float: - return f - floor(f) - -func clampv2(v : Vector2, pmin : Vector2, pmax : Vector2) -> Vector2: - v.x = clamp(v.x, pmin.x, pmax.x) - v.y = clamp(v.y, pmin.y, pmax.y) - - return v - -func rand(x : Vector2) -> float: - return fract(cos(x.dot(Vector2(13.9898, 8.141))) * 43758.5453); - -func rand2(x : Vector2) -> Vector2: - return fractv2(cosv2(Vector2(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)))) * 43758.5453); - -func rand3(x : Vector2) -> Vector3: - return fractv3(cosv3(Vector3(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)), - x.dot(Vector2(13.254, 5.867)))) * 43758.5453); - -func step(edge : float, x : float) -> float: - if x < edge: - return 0.0 - else: - return 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.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 diff --git a/game/addons/mat_maker_gd/nodes/noise/noise_color.gd b/game/addons/mat_maker_gd/nodes/noise/noise_color.gd index 306acfd8..3679de5b 100644 --- a/game/addons/mat_maker_gd/nodes/noise/noise_color.gd +++ b/game/addons/mat_maker_gd/nodes/noise/noise_color.gd @@ -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 @@ -58,10 +60,10 @@ func nc(uv : Vector2) -> Color: var seed_o26210 = 7313; func color_dots(uv : Vector2, size : float, pseed : int) -> Vector3: - var seed2 : Vector2 = rand2(Vector2(float(pseed), 1.0 - float(pseed))); + var seed2 : Vector2 = Commons.rand2(Vector2(float(pseed), 1.0 - float(pseed))); uv /= size; - var point_pos : Vector2 = floorv2(uv) + Vector2(0.5, 0.5); - return rand3(seed2 + point_pos); + 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: @@ -74,186 +76,10 @@ func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector rv += Vector2(0.5, 0.5); if (repeat): - return fractv2(rv); + return Commons.fractv2(rv); else: - return clampv2(rv, Vector2(0, 0), Vector2(1, 1)); - - -func clampv3(v : Vector3, mi : Vector3, ma : Vector3) -> Vector3: - v.x = clamp(v.x, mi.x, ma.x) - v.y = clamp(v.y, mi.y, ma.y) - v.y = clamp(v.z, mi.z, ma.z) + return Commons.clampv2(rv, Vector2(0, 0), Vector2(1, 1)); - return v - -func floorc(a : Color) -> Color: - var v : Color = Color() - - v.r = floor(a.r) - v.g = floor(a.g) - v.b = floor(a.b) - v.a = floor(a.a) - - return v - - -func floorv2(a : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = floor(a.x) - v.y = floor(a.y) - - return v - -func smoothstepv2(a : float, b : float, c : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = smoothstep(a, b, c.x) - v.y = smoothstep(a, b, c.y) - - return v - -func maxv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - - return v - -func maxv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - v.z = max(a.z, b.z) - - return v - -func absv2(v : Vector2) -> Vector2: - v.x = abs(v.x) - v.y = abs(v.y) - - return v - -func absv3(v : Vector3) -> Vector3: - v.x = abs(v.x) - v.y = abs(v.y) - v.y = abs(v.y) - - return v - -func cosv2(v : Vector2) -> Vector2: - v.x = cos(v.x) - v.y = cos(v.y) - - return v - -func cosv3(v : Vector3) -> Vector3: - v.x = cos(v.x) - v.y = cos(v.y) - v.y = cos(v.y) - - return v - -func modv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - v.z = modf(a.z, b.z) - - return v - - -func modv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - - return v - -func modf(x : float, y : float) -> float: - return x - y * floor(x / y) - -func fractv2(v : Vector2) -> Vector2: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - - return v - -func fractv3(v : Vector3) -> Vector3: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - v.z = v.z - floor(v.z) - - return v - -func fract(f : float) -> float: - return f - floor(f) - -func clampv2(v : Vector2, pmin : Vector2, pmax : Vector2) -> Vector2: - v.x = clamp(v.x, pmin.x, pmax.x) - v.y = clamp(v.y, pmin.y, pmax.y) - - return v - -func rand(x : Vector2) -> float: - return fract(cos(x.dot(Vector2(13.9898, 8.141))) * 43758.5453); - -func rand2(x : Vector2) -> Vector2: - return fractv2(cosv2(Vector2(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)))) * 43758.5453); - -func rand3(x : Vector2) -> Vector3: - return fractv3(cosv3(Vector3(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)), - x.dot(Vector2(13.254, 5.867)))) * 43758.5453); - -func step(edge : float, x : float) -> float: - if x < edge: - return 0.0 - else: - return 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.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 diff --git a/game/addons/mat_maker_gd/nodes/noise/noise_voronoi.gd b/game/addons/mat_maker_gd/nodes/noise/noise_voronoi.gd index 7196453d..db8f6580 100644 --- a/game/addons/mat_maker_gd/nodes/noise/noise_voronoi.gd +++ b/game/addons/mat_maker_gd/nodes/noise/noise_voronoi.gd @@ -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 @@ -66,7 +68,7 @@ func voron_3(uv : Vector2) -> Color: var vv : Vector2 = Vector2(c.r, c.g) - var v : Vector3 = rand3(fractv2(vv)); + var v : Vector3 = Commons.rand3(Commons.fractv2(vv)); return Color(v.x, v.y, v.z, 1) @@ -81,20 +83,20 @@ var p_o8689_randomness = 0.750000000; func voronoi(uv : Vector2, size : Vector2, stretch : Vector2, intensity : float, randomness : float, pseed : int) -> Color: - var seed2 : Vector2 = rand2(Vector2(float(pseed), 1.0-float(pseed))); + 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 = floorv2(uv); + 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 * rand2(seed2 + modv2(p, size)); + p += randomness * Commons.rand2(seed2 + Commons.modv2(p, size)); var distance : float = (stretch * (uv - p) / size).length(); if (best_distance0 > distance): @@ -120,187 +122,11 @@ func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector rv += Vector2(0.5, 0.5); if (repeat): - return fractv2(rv); + return Commons.fractv2(rv); else: - return clampv2(rv, Vector2(0, 0), Vector2(1, 1)); + return Commons.clampv2(rv, Vector2(0, 0), Vector2(1, 1)); -func clampv3(v : Vector3, mi : Vector3, ma : Vector3) -> Vector3: - v.x = clamp(v.x, mi.x, ma.x) - v.y = clamp(v.y, mi.y, ma.y) - v.y = clamp(v.z, mi.z, ma.z) - - return v - -func floorc(a : Color) -> Color: - var v : Color = Color() - - v.r = floor(a.r) - v.g = floor(a.g) - v.b = floor(a.b) - v.a = floor(a.a) - - return v - - -func floorv2(a : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = floor(a.x) - v.y = floor(a.y) - - return v - -func smoothstepv2(a : float, b : float, c : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = smoothstep(a, b, c.x) - v.y = smoothstep(a, b, c.y) - - return v - -func maxv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - - return v - -func maxv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - v.z = max(a.z, b.z) - - return v - -func absv2(v : Vector2) -> Vector2: - v.x = abs(v.x) - v.y = abs(v.y) - - return v - -func absv3(v : Vector3) -> Vector3: - v.x = abs(v.x) - v.y = abs(v.y) - v.y = abs(v.y) - - return v - -func cosv2(v : Vector2) -> Vector2: - v.x = cos(v.x) - v.y = cos(v.y) - - return v - -func cosv3(v : Vector3) -> Vector3: - v.x = cos(v.x) - v.y = cos(v.y) - v.y = cos(v.y) - - return v - -func modv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - v.z = modf(a.z, b.z) - - return v - - -func modv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - - return v - -func modf(x : float, y : float) -> float: - return x - y * floor(x / y) - -func fractv2(v : Vector2) -> Vector2: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - - return v - -func fractv3(v : Vector3) -> Vector3: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - v.z = v.z - floor(v.z) - - return v - -func fract(f : float) -> float: - return f - floor(f) - -func clampv2(v : Vector2, pmin : Vector2, pmax : Vector2) -> Vector2: - v.x = clamp(v.x, pmin.x, pmax.x) - v.y = clamp(v.y, pmin.y, pmax.y) - - return v - -func rand(x : Vector2) -> float: - return fract(cos(x.dot(Vector2(13.9898, 8.141))) * 43758.5453); - -func rand2(x : Vector2) -> Vector2: - return fractv2(cosv2(Vector2(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)))) * 43758.5453); - -func rand3(x : Vector2) -> Vector3: - return fractv3(cosv3(Vector3(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)), - x.dot(Vector2(13.254, 5.867)))) * 43758.5453); - -func step(edge : float, x : float) -> float: - if x < edge: - return 0.0 - else: - return 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.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 diff --git a/game/addons/mat_maker_gd/nodes/noise/perlin.gd b/game/addons/mat_maker_gd/nodes/noise/perlin.gd index f18bd7ec..5d2fef65 100644 --- a/game/addons/mat_maker_gd/nodes/noise/perlin.gd +++ b/game/addons/mat_maker_gd/nodes/noise/perlin.gd @@ -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 @@ -63,20 +65,20 @@ func sinewave(uv : Vector2) -> Color: return Color(f, f, f, 1) 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 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 = 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 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 = smoothstepv2(0.0, 1.0, fractv2(uv * 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; @@ -86,177 +88,6 @@ func perlin(uv : Vector2, size : Vector2, iterations : int, persistence : float, return rv / acc; - -func clampv3(v : Vector3, mi : Vector3, ma : Vector3) -> Vector3: - v.x = clamp(v.x, mi.x, ma.x) - v.y = clamp(v.y, mi.y, ma.y) - v.y = clamp(v.z, mi.z, ma.z) - - return v - -func floorc(a : Color) -> Color: - var v : Color = Color() - - v.r = floor(a.r) - v.g = floor(a.g) - v.b = floor(a.b) - v.a = floor(a.a) - - return v - - -func floorv2(a : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = floor(a.x) - v.y = floor(a.y) - - return v - -func smoothstepv2(a : float, b : float, c : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = smoothstep(a, b, c.x) - v.y = smoothstep(a, b, c.y) - - return v - -func maxv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - - return v - -func maxv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - v.z = max(a.z, b.z) - - return v - -func absv2(v : Vector2) -> Vector2: - v.x = abs(v.x) - v.y = abs(v.y) - - return v - -func absv3(v : Vector3) -> Vector3: - v.x = abs(v.x) - v.y = abs(v.y) - v.y = abs(v.y) - - return v - -func cosv2(v : Vector2) -> Vector2: - v.x = cos(v.x) - v.y = cos(v.y) - - return v - -func cosv3(v : Vector3) -> Vector3: - v.x = cos(v.x) - v.y = cos(v.y) - v.y = cos(v.y) - - return v - -func modv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - v.z = modf(a.z, b.z) - - return v - - -func modv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - - return v - -func modf(x : float, y : float) -> float: - return x - y * floor(x / y) - -func fractv2(v : Vector2) -> Vector2: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - - return v - -func fractv3(v : Vector3) -> Vector3: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - v.z = v.z - floor(v.z) - - return v - -func fract(f : float) -> float: - return f - floor(f) - -func rand(x : Vector2) -> float: - return fract(cos(x.dot(Vector2(13.9898, 8.141))) * 43758.5453); - -func rand2(x : Vector2) -> Vector2: - return fractv2(cosv2(Vector2(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)))) * 43758.5453); - -func rand3(x : Vector2) -> Vector3: - return fractv3(cosv3(Vector3(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)), - x.dot(Vector2(13.254, 5.867)))) * 43758.5453); - -func step(edge : float, x : float) -> float: - if x < edge: - return 0.0 - else: - return 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.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 diff --git a/game/addons/mat_maker_gd/nodes/noise/perlin_color.gd b/game/addons/mat_maker_gd/nodes/noise/perlin_color.gd index d581e008..5b250ca3 100644 --- a/game/addons/mat_maker_gd/nodes/noise/perlin_color.gd +++ b/game/addons/mat_maker_gd/nodes/noise/perlin_color.gd @@ -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 @@ -63,21 +65,21 @@ func sinewave(uv : Vector2) -> Color: 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 = rand2(Vector2(float(pseed), 1.0 - float(pseed))); + 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 = floorv2(uv * size); + var xy : Vector2 = Commons.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 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 = smoothstepv2(0.0, 1.0, fractv2(uv * 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); @@ -87,176 +89,6 @@ func perlin_color(uv : Vector2, size : Vector2, iterations : int, persistence : return rv / acc; -func clampv3(v : Vector3, mi : Vector3, ma : Vector3) -> Vector3: - v.x = clamp(v.x, mi.x, ma.x) - v.y = clamp(v.y, mi.y, ma.y) - v.y = clamp(v.z, mi.z, ma.z) - - return v - -func floorc(a : Color) -> Color: - var v : Color = Color() - - v.r = floor(a.r) - v.g = floor(a.g) - v.b = floor(a.b) - v.a = floor(a.a) - - return v - - -func floorv2(a : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = floor(a.x) - v.y = floor(a.y) - - return v - -func smoothstepv2(a : float, b : float, c : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = smoothstep(a, b, c.x) - v.y = smoothstep(a, b, c.y) - - return v - -func maxv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - - return v - -func maxv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - v.z = max(a.z, b.z) - - return v - -func absv2(v : Vector2) -> Vector2: - v.x = abs(v.x) - v.y = abs(v.y) - - return v - -func absv3(v : Vector3) -> Vector3: - v.x = abs(v.x) - v.y = abs(v.y) - v.y = abs(v.y) - - return v - -func cosv2(v : Vector2) -> Vector2: - v.x = cos(v.x) - v.y = cos(v.y) - - return v - -func cosv3(v : Vector3) -> Vector3: - v.x = cos(v.x) - v.y = cos(v.y) - v.y = cos(v.y) - - return v - -func modv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - v.z = modf(a.z, b.z) - - return v - - -func modv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - - return v - -func modf(x : float, y : float) -> float: - return x - y * floor(x / y) - -func fractv2(v : Vector2) -> Vector2: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - - return v - -func fractv3(v : Vector3) -> Vector3: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - v.z = v.z - floor(v.z) - - return v - -func fract(f : float) -> float: - return f - floor(f) - -func rand(x : Vector2) -> float: - return fract(cos(x.dot(Vector2(13.9898, 8.141))) * 43758.5453); - -func rand2(x : Vector2) -> Vector2: - return fractv2(cosv2(Vector2(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)))) * 43758.5453); - -func rand3(x : Vector2) -> Vector3: - return fractv3(cosv3(Vector3(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)), - x.dot(Vector2(13.254, 5.867)))) * 43758.5453); - -func step(edge : float, x : float) -> float: - if x < edge: - return 0.0 - else: - return 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.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 diff --git a/game/addons/mat_maker_gd/nodes/noise/perlin_warp1.gd b/game/addons/mat_maker_gd/nodes/noise/perlin_warp1.gd index 3010aa26..57ca8ae4 100644 --- a/game/addons/mat_maker_gd/nodes/noise/perlin_warp1.gd +++ b/game/addons/mat_maker_gd/nodes/noise/perlin_warp1.gd @@ -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 @@ -69,20 +71,20 @@ func sinewave(uv : Vector2) -> Color: 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 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 = 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 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 = smoothstepv2(0.0, 1.0, fractv2(uv * 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; @@ -103,186 +105,9 @@ func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector rv += Vector2(0.5, 0.5); if (repeat): - return fractv2(rv); + return Commons.fractv2(rv); else: - return clampv2(rv, Vector2(0, 0), Vector2(1, 1)); - - -func clampv3(v : Vector3, mi : Vector3, ma : Vector3) -> Vector3: - v.x = clamp(v.x, mi.x, ma.x) - v.y = clamp(v.y, mi.y, ma.y) - v.y = clamp(v.z, mi.z, ma.z) - - return v - -func floorc(a : Color) -> Color: - var v : Color = Color() - - v.r = floor(a.r) - v.g = floor(a.g) - v.b = floor(a.b) - v.a = floor(a.a) - - return v - - -func floorv2(a : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = floor(a.x) - v.y = floor(a.y) - - return v - -func smoothstepv2(a : float, b : float, c : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = smoothstep(a, b, c.x) - v.y = smoothstep(a, b, c.y) - - return v - -func maxv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - - return v - -func maxv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - v.z = max(a.z, b.z) - - return v - -func absv2(v : Vector2) -> Vector2: - v.x = abs(v.x) - v.y = abs(v.y) - - return v - -func absv3(v : Vector3) -> Vector3: - v.x = abs(v.x) - v.y = abs(v.y) - v.y = abs(v.y) - - return v - -func cosv2(v : Vector2) -> Vector2: - v.x = cos(v.x) - v.y = cos(v.y) - - return v - -func cosv3(v : Vector3) -> Vector3: - v.x = cos(v.x) - v.y = cos(v.y) - v.y = cos(v.y) - - return v - -func modv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - v.z = modf(a.z, b.z) - - return v - - -func modv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - - return v - -func modf(x : float, y : float) -> float: - return x - y * floor(x / y) - -func fractv2(v : Vector2) -> Vector2: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - - return v - -func fractv3(v : Vector3) -> Vector3: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - v.z = v.z - floor(v.z) - - return v - -func fract(f : float) -> float: - return f - floor(f) - -func clampv2(v : Vector2, pmin : Vector2, pmax : Vector2) -> Vector2: - v.x = clamp(v.x, pmin.x, pmax.x) - v.y = clamp(v.y, pmin.y, pmax.y) - - return v - -func rand(x : Vector2) -> float: - return fract(cos(x.dot(Vector2(13.9898, 8.141))) * 43758.5453); - -func rand2(x : Vector2) -> Vector2: - return fractv2(cosv2(Vector2(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)))) * 43758.5453); - -func rand3(x : Vector2) -> Vector3: - return fractv3(cosv3(Vector3(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)), - x.dot(Vector2(13.254, 5.867)))) * 43758.5453); - -func step(edge : float, x : float) -> float: - if x < edge: - return 0.0 - else: - return 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.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 - + return Commons.clampv2(rv, Vector2(0, 0), Vector2(1, 1)); func reffg(): return false diff --git a/game/addons/mat_maker_gd/nodes/noise/perlin_warp2.gd b/game/addons/mat_maker_gd/nodes/noise/perlin_warp2.gd index 65a62159..3e79a792 100644 --- a/game/addons/mat_maker_gd/nodes/noise/perlin_warp2.gd +++ b/game/addons/mat_maker_gd/nodes/noise/perlin_warp2.gd @@ -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 @@ -80,20 +82,20 @@ func sinewave(uv : Vector2) -> Color: 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 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 = 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 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 = smoothstepv2(0.0, 1.0, fractv2(uv * 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; @@ -113,186 +115,11 @@ func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector rv += Vector2(0.5, 0.5); if (repeat): - return fractv2(rv); + return Commons.fractv2(rv); else: - return clampv2(rv, Vector2(0, 0), Vector2(1, 1)); + return Commons.clampv2(rv, Vector2(0, 0), Vector2(1, 1)); -func clampv3(v : Vector3, mi : Vector3, ma : Vector3) -> Vector3: - v.x = clamp(v.x, mi.x, ma.x) - v.y = clamp(v.y, mi.y, ma.y) - v.y = clamp(v.z, mi.z, ma.z) - - return v - -func floorc(a : Color) -> Color: - var v : Color = Color() - - v.r = floor(a.r) - v.g = floor(a.g) - v.b = floor(a.b) - v.a = floor(a.a) - - return v - - -func floorv2(a : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = floor(a.x) - v.y = floor(a.y) - - return v - -func smoothstepv2(a : float, b : float, c : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = smoothstep(a, b, c.x) - v.y = smoothstep(a, b, c.y) - - return v - -func maxv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - - return v - -func maxv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = max(a.x, b.x) - v.y = max(a.y, b.y) - v.z = max(a.z, b.z) - - return v - -func absv2(v : Vector2) -> Vector2: - v.x = abs(v.x) - v.y = abs(v.y) - - return v - -func absv3(v : Vector3) -> Vector3: - v.x = abs(v.x) - v.y = abs(v.y) - v.y = abs(v.y) - - return v - -func cosv2(v : Vector2) -> Vector2: - v.x = cos(v.x) - v.y = cos(v.y) - - return v - -func cosv3(v : Vector3) -> Vector3: - v.x = cos(v.x) - v.y = cos(v.y) - v.y = cos(v.y) - - return v - -func modv3(a : Vector3, b : Vector3) -> Vector3: - var v : Vector3 = Vector3() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - v.z = modf(a.z, b.z) - - return v - - -func modv2(a : Vector2, b : Vector2) -> Vector2: - var v : Vector2 = Vector2() - - v.x = modf(a.x, b.x) - v.y = modf(a.y, b.y) - - return v - -func modf(x : float, y : float) -> float: - return x - y * floor(x / y) - -func fractv2(v : Vector2) -> Vector2: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - - return v - -func fractv3(v : Vector3) -> Vector3: - v.x = v.x - floor(v.x) - v.y = v.y - floor(v.y) - v.z = v.z - floor(v.z) - - return v - -func fract(f : float) -> float: - return f - floor(f) - -func clampv2(v : Vector2, pmin : Vector2, pmax : Vector2) -> Vector2: - v.x = clamp(v.x, pmin.x, pmax.x) - v.y = clamp(v.y, pmin.y, pmax.y) - - return v - -func rand(x : Vector2) -> float: - return fract(cos(x.dot(Vector2(13.9898, 8.141))) * 43758.5453); - -func rand2(x : Vector2) -> Vector2: - return fractv2(cosv2(Vector2(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)))) * 43758.5453); - -func rand3(x : Vector2) -> Vector3: - return fractv3(cosv3(Vector3(x.dot(Vector2(13.9898, 8.141)), - x.dot(Vector2(3.4562, 17.398)), - x.dot(Vector2(13.254, 5.867)))) * 43758.5453); - -func step(edge : float, x : float) -> float: - if x < edge: - return 0.0 - else: - return 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.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