mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
Added a runes generator and a detailed edit for gradients
This commit is contained in:
parent
4cfd8fbc1e
commit
d024688511
1
addons/material_maker/nodes/runes.mmg
Normal file
1
addons/material_maker/nodes/runes.mmg
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"name":"runes","node_position":{"x":0,"y":0},"parameters":{"columns":8,"rows":8},"shader_model":{"global":"float ThickLine(vec2 uv, vec2 posA, vec2 posB, float radiusInv)\n{\n\tvec2 dir = posA - posB;\n\tfloat dirLen = length(dir);\n\tvec2 dirN = normalize(dir);\n\tfloat dotTemp = clamp(dot(uv - posB, dirN), 0.0, dirLen);\n\tvec2 proj = dotTemp * dirN + posB;\n\tfloat d1 = length(uv - proj);\n\tfloat finalGray = clamp(1.0 - d1 * radiusInv, 0.0, 1.0);\n\treturn finalGray;\n}\n\n// makes a rune in the 0..1 uv space. Seed is which rune to draw.\n// passes back gray in x and derivates for lighting in yz\nfloat Rune(vec2 uv) {\n\tfloat finalLine = 0.0;\n\tvec2 seed = floor(uv)-0.41;\n\tuv = fract(uv);\n\tfor (int i = 0; i < 4; i++)\t// number of strokes\n\t{\n\t\tvec2 posA = rand2(floor(seed+0.5));\n\t\tvec2 posB = rand2(floor(seed+1.5));\n\t\tseed += 2.0;\n\t\t// expand the range and mod it to get a nicely distributed random number - hopefully. :)\n\t\tposA = fract(posA * 128.0);\n\t\tposB = fract(posB * 128.0);\n\t\t// each rune touches the edge of its box on all 4 sides\n\t\tif (i == 0) posA.y = 0.0;\n\t\tif (i == 1) posA.x = 0.999;\n\t\tif (i == 2) posA.x = 0.0;\n\t\tif (i == 3) posA.y = 0.999;\n\t\t// snap the random line endpoints to a grid 2x3\n\t\tvec2 snaps = vec2(2.0, 3.0);\n\t\tposA = (floor(posA * snaps) + 0.5) / snaps;\t// + 0.5 to center it in a grid cell\n\t\tposB = (floor(posB * snaps) + 0.5) / snaps;\n\t\t//if (distance(posA, posB) < 0.0001) continue;\t// eliminate dots.\n\t\t// Dots (degenerate lines) are not cross-GPU safe without adding 0.001 - divide by 0 error.\n\t\tfinalLine = max(finalLine, ThickLine(uv, posA, posB + 0.001, 20.0));\n\t}\n\treturn finalLine;\n}\n\n\n","inputs":[],"instance":"","name":"Runes","outputs":[{"f":"Rune(vec2($columns, $rows)*$uv)","type":"f"}],"parameters":[{"default":0,"label":"","max":32,"min":2,"name":"columns","step":1,"type":"float","widget":"spinbox"},{"default":0,"label":"","max":32,"min":2,"name":"rows","step":1,"type":"float","widget":"spinbox"}]},"type":"shader"}
|
@ -2,6 +2,7 @@ tool
|
|||||||
extends Control
|
extends Control
|
||||||
class_name MMGradientEditor
|
class_name MMGradientEditor
|
||||||
|
|
||||||
|
|
||||||
class GradientCursor:
|
class GradientCursor:
|
||||||
extends ColorRect
|
extends ColorRect
|
||||||
|
|
||||||
@ -43,6 +44,7 @@ class GradientCursor:
|
|||||||
draw_rect(Rect2(0, 0, rect_size.x, rect_size.y), c, false)
|
draw_rect(Rect2(0, 0, rect_size.x, rect_size.y), c, false)
|
||||||
|
|
||||||
var value = null setget set_value
|
var value = null setget set_value
|
||||||
|
export var embedded : bool = true
|
||||||
|
|
||||||
signal updated(value)
|
signal updated(value)
|
||||||
|
|
||||||
@ -53,7 +55,7 @@ func _ready():
|
|||||||
func set_value(v):
|
func set_value(v):
|
||||||
value = v
|
value = v
|
||||||
for c in get_children():
|
for c in get_children():
|
||||||
if c != $Gradient and c != $Background:
|
if c is GradientCursor:
|
||||||
remove_child(c)
|
remove_child(c)
|
||||||
c.free()
|
c.free()
|
||||||
for p in value.points:
|
for p in value.points:
|
||||||
@ -74,10 +76,19 @@ func add_cursor(x, color):
|
|||||||
cursor.color = color
|
cursor.color = color
|
||||||
|
|
||||||
func _gui_input(ev):
|
func _gui_input(ev):
|
||||||
if ev is InputEventMouseButton && ev.button_index == 1 && ev.doubleclick && ev.position.y > 15:
|
if ev is InputEventMouseButton && ev.button_index == 1 && ev.doubleclick:
|
||||||
var p = max(0, min(ev.position.x, rect_size.x-GradientCursor.WIDTH))
|
if ev.position.y > 15:
|
||||||
add_cursor(p, get_gradient_color(p))
|
var p = max(0, min(ev.position.x, rect_size.x-GradientCursor.WIDTH))
|
||||||
update_value()
|
add_cursor(p, get_gradient_color(p))
|
||||||
|
update_value()
|
||||||
|
elif embedded:
|
||||||
|
var popup = load("res://addons/material_maker/widgets/gradient_popup.tscn").instance()
|
||||||
|
add_child(popup)
|
||||||
|
var popup_size = popup.rect_size
|
||||||
|
popup.popup(Rect2(ev.global_position, Vector2(0, 0)))
|
||||||
|
popup.set_global_position(ev.global_position-Vector2(popup_size.x / 2, popup_size.y))
|
||||||
|
popup.init(value)
|
||||||
|
popup.connect("updated", self, "set_value")
|
||||||
|
|
||||||
# Showing a color picker popup to change a cursor's color
|
# Showing a color picker popup to change a cursor's color
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
code = "shader_type canvas_item;
|
code = "shader_type canvas_item;
|
||||||
|
|
||||||
void fragment() {
|
void fragment() {
|
||||||
COLOR = vec4(vec3(2.0*fract(0.5*(floor(10.0*UV.x)+floor(2.0*UV.y)))), 1.0);
|
COLOR = vec4(vec3(2.0*fract(0.5*(floor(0.12*FRAGCOORD.x)+floor(0.125*FRAGCOORD.y)))), 1.0);
|
||||||
}"
|
}"
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id=2]
|
[sub_resource type="ShaderMaterial" id=2]
|
||||||
@ -37,15 +37,13 @@ script = ExtResource( 1 )
|
|||||||
|
|
||||||
[node name="Background" type="ColorRect" parent="."]
|
[node name="Background" type="ColorRect" parent="."]
|
||||||
material = SubResource( 2 )
|
material = SubResource( 2 )
|
||||||
margin_right = 120.0
|
anchor_right = 1.0
|
||||||
margin_bottom = 20.0
|
|
||||||
rect_min_size = Vector2( 120, 20 )
|
rect_min_size = Vector2( 120, 20 )
|
||||||
mouse_filter = 2
|
mouse_filter = 2
|
||||||
|
|
||||||
[node name="Gradient" type="ColorRect" parent="."]
|
[node name="Gradient" type="ColorRect" parent="."]
|
||||||
material = SubResource( 4 )
|
material = SubResource( 4 )
|
||||||
margin_right = 120.0
|
anchor_right = 1.0
|
||||||
margin_bottom = 20.0
|
|
||||||
rect_min_size = Vector2( 120, 20 )
|
rect_min_size = Vector2( 120, 20 )
|
||||||
mouse_filter = 2
|
mouse_filter = 2
|
||||||
theme = SubResource( 5 )
|
theme = SubResource( 5 )
|
||||||
|
15
addons/material_maker/widgets/gradient_popup.gd
Normal file
15
addons/material_maker/widgets/gradient_popup.gd
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
extends Popup
|
||||||
|
|
||||||
|
signal updated(value)
|
||||||
|
|
||||||
|
func init(value):
|
||||||
|
$Panel/Control.set_value(value)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
func _on_Control_updated(value):
|
||||||
|
emit_signal("updated", value)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_GradientPopup_popup_hide():
|
||||||
|
queue_free()
|
30
addons/material_maker/widgets/gradient_popup.tscn
Normal file
30
addons/material_maker/widgets/gradient_popup.tscn
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://addons/material_maker/widgets/gradient_popup.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://addons/material_maker/widgets/gradient_editor.tscn" type="PackedScene" id=2]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id=2]
|
||||||
|
bg_color = Color( 0, 0, 0.25098, 0.752941 )
|
||||||
|
|
||||||
|
[node name="GradientPopup" type="Popup"]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
margin_right = -648.0
|
||||||
|
margin_bottom = -671.0
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="Panel" type="Panel" parent="."]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
custom_styles/panel = SubResource( 2 )
|
||||||
|
|
||||||
|
[node name="Control" parent="Panel" instance=ExtResource( 2 )]
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
margin_left = 10.0
|
||||||
|
margin_top = 10.0
|
||||||
|
margin_right = -10.0
|
||||||
|
margin_bottom = -10.0
|
||||||
|
embedded = false
|
||||||
|
[connection signal="popup_hide" from="." to="." method="_on_GradientPopup_popup_hide"]
|
||||||
|
[connection signal="updated" from="Panel/Control" to="." method="_on_Control_updated"]
|
Loading…
Reference in New Issue
Block a user