mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-12-18 01:06:47 +01:00
Curve node.
This commit is contained in:
parent
fc8fa79624
commit
577e9d705a
@ -1,4 +1,4 @@
|
||||
[gd_resource type="Resource" load_steps=103 format=2]
|
||||
[gd_resource type="Resource" load_steps=107 format=2]
|
||||
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/mm_material.gd" type="Script" id=1]
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/noise/noise.gd" type="Script" id=2]
|
||||
@ -27,6 +27,7 @@
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_op_repeat.gd" type="Script" id=25]
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_op_circle_repeat.gd" type="Script" id=26]
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/sdf2d/sd_op_morph.gd" type="Script" id=27]
|
||||
[ext_resource path="res://addons/mat_maker_gd/nodes/simple/curve.gd" type="Script" id=28]
|
||||
|
||||
[sub_resource type="Resource" id=3]
|
||||
script = ExtResource( 5 )
|
||||
@ -64,7 +65,7 @@ sides = 11
|
||||
radius = SubResource( 4 )
|
||||
edge = SubResource( 3 )
|
||||
|
||||
[sub_resource type="Resource" id=86]
|
||||
[sub_resource type="Resource" id=101]
|
||||
script = ExtResource( 5 )
|
||||
default_type = 5
|
||||
default_int = 0
|
||||
@ -76,7 +77,7 @@ default_color = Color( 0, 0, 0, 1 )
|
||||
[sub_resource type="Resource" id=6]
|
||||
script = ExtResource( 6 )
|
||||
graph_position = Vector2( 300, -400 )
|
||||
image = SubResource( 86 )
|
||||
image = SubResource( 101 )
|
||||
postfix = "-test"
|
||||
|
||||
[sub_resource type="Resource" id=9]
|
||||
@ -677,7 +678,37 @@ input2 = SubResource( 95 )
|
||||
output = SubResource( 93 )
|
||||
amount = 0.5
|
||||
|
||||
[sub_resource type="Resource" id=98]
|
||||
script = ExtResource( 5 )
|
||||
default_type = 5
|
||||
default_int = 0
|
||||
default_float = 0.0
|
||||
default_vector2 = Vector2( 0, 0 )
|
||||
default_vector3 = Vector3( 0, 0, 0 )
|
||||
default_color = Color( 0, 0, 0, 1 )
|
||||
|
||||
[sub_resource type="Resource" id=102]
|
||||
script = ExtResource( 5 )
|
||||
default_type = 1
|
||||
default_int = 0
|
||||
default_float = 1.0
|
||||
default_vector2 = Vector2( 0, 0 )
|
||||
default_vector3 = Vector3( 0, 0, 0 )
|
||||
default_color = Color( 0, 0, 0, 1 )
|
||||
input_property = SubResource( 44 )
|
||||
|
||||
[sub_resource type="Resource" id=100]
|
||||
script = ExtResource( 28 )
|
||||
graph_position = Vector2( 1140, -220 )
|
||||
image = SubResource( 98 )
|
||||
input = SubResource( 102 )
|
||||
a = Vector2( -0.35, -0.2 )
|
||||
b = Vector2( 0, 0.5 )
|
||||
c = Vector2( 0.35, -0.2 )
|
||||
width = 0.24
|
||||
repeat = 5
|
||||
|
||||
[resource]
|
||||
script = ExtResource( 1 )
|
||||
image_size = Vector2( 128, 128 )
|
||||
nodes = [ SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ), SubResource( 27 ), SubResource( 39 ), SubResource( 42 ), SubResource( 45 ), SubResource( 49 ), SubResource( 54 ), SubResource( 58 ), SubResource( 60 ), SubResource( 63 ), SubResource( 66 ), SubResource( 69 ), SubResource( 71 ), SubResource( 73 ), SubResource( 78 ), SubResource( 82 ), SubResource( 85 ), SubResource( 88 ), SubResource( 90 ), SubResource( 92 ), SubResource( 96 ) ]
|
||||
nodes = [ SubResource( 5 ), SubResource( 6 ), SubResource( 12 ), SubResource( 15 ), SubResource( 18 ), SubResource( 21 ), SubResource( 24 ), SubResource( 27 ), SubResource( 39 ), SubResource( 42 ), SubResource( 45 ), SubResource( 49 ), SubResource( 54 ), SubResource( 58 ), SubResource( 60 ), SubResource( 63 ), SubResource( 66 ), SubResource( 69 ), SubResource( 71 ), SubResource( 73 ), SubResource( 78 ), SubResource( 82 ), SubResource( 85 ), SubResource( 88 ), SubResource( 90 ), SubResource( 92 ), SubResource( 96 ), SubResource( 100 ) ]
|
||||
|
@ -164,6 +164,12 @@ static func cosv3(v : Vector3) -> Vector3:
|
||||
|
||||
return v
|
||||
|
||||
static func powv2(x : Vector2, y : Vector2) -> Vector2:
|
||||
x.x = pow(x.x, y.x)
|
||||
x.y = pow(x.y, y.y)
|
||||
|
||||
return x
|
||||
|
||||
static func modv3(a : Vector3, b : Vector3) -> Vector3:
|
||||
var v : Vector3 = Vector3()
|
||||
|
||||
@ -225,6 +231,18 @@ static func step(edge : float, x : float) -> float:
|
||||
else:
|
||||
return 1.0
|
||||
|
||||
static func stepv2(edge : Vector2, x : Vector2) -> Vector2:
|
||||
edge.x = step(edge.x, x.x)
|
||||
edge.y = step(edge.y, x.y)
|
||||
|
||||
return edge
|
||||
|
||||
static func signv2(x : Vector2) -> Vector2:
|
||||
x.x = sign(x.x)
|
||||
x.y = sign(x.y)
|
||||
|
||||
return x
|
||||
|
||||
static func transform(uv : Vector2, translate : Vector2, rotate : float, scale : Vector2, repeat : bool) -> Vector2:
|
||||
var rv : Vector2 = Vector2();
|
||||
uv -= translate;
|
||||
|
@ -2206,7 +2206,8 @@ static func sdf2d_rotate(uv : Vector2, a : float) -> Vector2:
|
||||
# // 1 root\n
|
||||
# h = sqrt(h);\n
|
||||
# vec2 x = (vec2(h,-h)-q)/2.0;\n
|
||||
# vec2 uv = sign(x)*pow(abs(x), vec2(1.0/3.0));\n\t\trvx = uv.x+uv.y-kx;\n
|
||||
# vec2 uv = sign(x)*pow(abs(x), vec2(1.0/3.0));
|
||||
# rvx = uv.x+uv.y-kx;\n
|
||||
# float t = clamp(rvx, 0.0, 1.0);\n
|
||||
# vec2 q2 = d+(c+b*t)*t;\n
|
||||
# res = dot(q2, q2);\n \t
|
||||
@ -2252,56 +2253,48 @@ static func sdBezier(pos : Vector2, A : Vector2, B : Vector2, C : Vector2) -> Ve
|
||||
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;
|
||||
var rvx : float = 0
|
||||
|
||||
if(h >= 0.0):# // 1 root
|
||||
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 x : Vector2 = (Vector2(h,-h) - Vector2(q, q)) / 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);
|
||||
var uv : Vector2 = Commons.signv2(x) * Commons.powv2(Commons.absv2(x), Vector2(1.0/3.0, 1.0/3.0));
|
||||
|
||||
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
|
||||
sgn = (c + Vector2(2, 2) * b * t).cross(q2)
|
||||
|
||||
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));
|
||||
var t : Vector3 = Commons.clampv3(Vector3(m+m, -n-m, n-m) * z - Vector3(kx, kx, kx), Vector3(), Vector3(1, 1, 1));
|
||||
|
||||
var qx : Vector2 = d + (c + b * t.x) * t.x;
|
||||
var dx : float = qx.dot(qx)
|
||||
var sx : float = (c + Vector2(2, 2) * b * t.x).cross(qx)
|
||||
var qy : Vector2 = d + (c + b * t.y) * t.y
|
||||
var dy : float = qy.dot(qy)
|
||||
var sy : float = (c + Vector2(2, 2) * b * t.y).cross(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))
|
||||
|
||||
#vec2 circle_repeat_transform_2d(vec2 p, float count) {
|
||||
# float r = 6.28/count;
|
||||
|
@ -213,6 +213,10 @@ func get_default_value(uv : Vector2 = Vector2()):
|
||||
image.lock()
|
||||
var x : int = uv.x * image.get_width()
|
||||
var y : int = uv.y * image.get_height()
|
||||
|
||||
x = clamp(x, 0, image.get_width() - 1)
|
||||
y = clamp(y, 0, image.get_width() - 1)
|
||||
|
||||
var c : Color = image.get_pixel(x, y)
|
||||
image.unlock()
|
||||
|
||||
|
118
game/addons/mat_maker_gd/nodes/simple/curve.gd
Normal file
118
game/addons/mat_maker_gd/nodes/simple/curve.gd
Normal file
@ -0,0 +1,118 @@
|
||||
tool
|
||||
extends MMNode
|
||||
|
||||
var Commons = preload("res://addons/mat_maker_gd/nodes/common/commons.gd")
|
||||
var SDF2D = preload("res://addons/mat_maker_gd/nodes/common/sdf2d.gd")
|
||||
|
||||
export(Resource) var image : Resource
|
||||
|
||||
export(Resource) var input : Resource
|
||||
export(Vector2) var a : Vector2 = Vector2(-0.35, -0.2)
|
||||
export(Vector2) var b : Vector2 = Vector2(0, 0.5)
|
||||
export(Vector2) var c : Vector2 = Vector2(0.35, -0.2)
|
||||
export(float) var width : float = 0.05
|
||||
export(int) var repeat : int = 1
|
||||
|
||||
func _init_properties():
|
||||
if !image:
|
||||
image = MMNodeUniversalProperty.new()
|
||||
image.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_IMAGE
|
||||
|
||||
image.output_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE
|
||||
|
||||
if !input:
|
||||
input = MMNodeUniversalProperty.new()
|
||||
input.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
|
||||
input.set_default_value(1.0)
|
||||
|
||||
input.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
|
||||
input.slot_name = ">>> Input "
|
||||
|
||||
register_input_property(input)
|
||||
register_output_property(image)
|
||||
|
||||
func _register_methods(mm_graph_node) -> void:
|
||||
mm_graph_node.add_slot_texture_universal(image)
|
||||
mm_graph_node.add_slot_label_universal(input)
|
||||
|
||||
mm_graph_node.add_slot_vector2("get_a", "set_a", "A", 0.01)
|
||||
mm_graph_node.add_slot_vector2("get_b", "set_b", "B", 0.01)
|
||||
mm_graph_node.add_slot_vector2("get_c", "set_c", "C", 0.01)
|
||||
mm_graph_node.add_slot_float("get_width", "set_width", "Width", 0.01)
|
||||
mm_graph_node.add_slot_int("get_repeat", "set_repeat", "Repeat")
|
||||
|
||||
func get_value_for(uv : Vector2, pseed : int) -> Color:
|
||||
var nuv : Vector2 = transform_uv(uv)
|
||||
|
||||
var f : float = 0
|
||||
|
||||
if nuv.x != 0 && nuv.y != 0:
|
||||
f = input.get_value(nuv)
|
||||
|
||||
return Color(f, f, f, 1)
|
||||
|
||||
func _render(material) -> void:
|
||||
var img : Image = render_image(material)
|
||||
|
||||
image.set_value(img)
|
||||
|
||||
func transform_uv(uv : Vector2) -> Vector2:
|
||||
#vec2 $(name_uv)_bezier = sdBezier($uv, vec2($ax+0.5, $ay+0.5), vec2($bx+0.5, $by+0.5), vec2($cx+0.5, $cy+0.5));
|
||||
var bezier : Vector2 = SDF2D.sdBezier(uv, Vector2(a.x + 0.5, a.y + 0.5), Vector2(b.x + 0.5, b.y + 0.5), Vector2(c.x + 0.5, c.y + 0.5))
|
||||
|
||||
#vec2 $(name_uv)_uv = vec2($(name_uv)_bezier.x, $(name_uv)_bezier.y / $width+0.5);
|
||||
var new_uv : Vector2 = Vector2(bezier.x, bezier.y / width + 0.5)
|
||||
|
||||
#vec2 $(name_uv)_uvtest = step(vec2(0.5), abs($(name_uv)_uv-vec2(0.5)));
|
||||
var uv_test : Vector2 = Commons.stepv2(Vector2(0.5, 0.5), Commons.absv2(new_uv - Vector2(0.5, 0.5)))
|
||||
|
||||
#$(name_uv)_uv = mix(vec2(fract($repeat*$(name_uv)_uv.x), $(name_uv)_uv.y), vec2(0.0), max($(name_uv)_uvtest.x, $(name_uv)_uvtest.y));
|
||||
var final_uv : Vector2 = lerp(Vector2(Commons.fract(repeat * new_uv.x), new_uv.y), Vector2(), max(uv_test.x, uv_test.y))
|
||||
|
||||
return final_uv
|
||||
|
||||
#b
|
||||
func get_a() -> Vector2:
|
||||
return a
|
||||
|
||||
func set_a(val : Vector2) -> void:
|
||||
a = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#b
|
||||
func get_b() -> Vector2:
|
||||
return b
|
||||
|
||||
func set_b(val : Vector2) -> void:
|
||||
b = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#c
|
||||
func get_c() -> Vector2:
|
||||
return c
|
||||
|
||||
func set_c(val : Vector2) -> void:
|
||||
c = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#width
|
||||
func get_width() -> float:
|
||||
return width
|
||||
|
||||
func set_width(val : float) -> void:
|
||||
width = val
|
||||
|
||||
set_dirty(true)
|
||||
|
||||
#repeat
|
||||
func get_repeat() -> int:
|
||||
return repeat
|
||||
|
||||
func set_repeat(val : int) -> void:
|
||||
repeat = val
|
||||
|
||||
set_dirty(true)
|
||||
|
Loading…
Reference in New Issue
Block a user