mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
Added support for alpha channel in colorize node
This commit is contained in:
parent
ade213921c
commit
c624e0f6ee
@ -16,8 +16,8 @@ func _get_shader_code(uv):
|
|||||||
if variant_index == -1:
|
if variant_index == -1:
|
||||||
variant_index = generated_variants.size()
|
variant_index = generated_variants.size()
|
||||||
generated_variants.append(uv)
|
generated_variants.append(uv)
|
||||||
rv.code = src_code.code+"vec3 %s_%d_rgb = %s_gradient(%s);\n" % [ name, variant_index, name, src_code.f ]
|
rv.code = src_code.code+"vec4 %s_%d_rgba = %s_gradient(%s);\n" % [ name, variant_index, name, src_code.f ]
|
||||||
rv.rgb = "%s_%d_rgb" % [ name, variant_index ]
|
rv.rgba = "%s_%d_rgba" % [ name, variant_index ]
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
func _on_Control_updated(v):
|
func _on_Control_updated(v):
|
||||||
|
@ -3,11 +3,10 @@
|
|||||||
[ext_resource path="res://addons/material_maker/nodes/colorize/colorize.gd" type="Script" id=1]
|
[ext_resource path="res://addons/material_maker/nodes/colorize/colorize.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://addons/material_maker/widgets/gradient_editor.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://addons/material_maker/widgets/gradient_editor.tscn" type="PackedScene" id=2]
|
||||||
|
|
||||||
|
|
||||||
[sub_resource type="Theme" id=1]
|
[sub_resource type="Theme" id=1]
|
||||||
|
|
||||||
|
|
||||||
[node name="Colorize" type="GraphNode"]
|
[node name="Colorize" type="GraphNode" index="0"]
|
||||||
|
|
||||||
anchor_left = 0.0
|
anchor_left = 0.0
|
||||||
anchor_top = 0.0
|
anchor_top = 0.0
|
||||||
@ -36,7 +35,7 @@ slot/0/left_type = 0
|
|||||||
slot/0/left_color = Color( 0.756863, 0.756863, 0.756863, 1 )
|
slot/0/left_color = Color( 0.756863, 0.756863, 0.756863, 1 )
|
||||||
slot/0/right_enabled = true
|
slot/0/right_enabled = true
|
||||||
slot/0/right_type = 0
|
slot/0/right_type = 0
|
||||||
slot/0/right_color = Color( 0.5, 0.5, 1, 1 )
|
slot/0/right_color = Color( 0, 1, 0, 0.502745 )
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
_sections_unfolded = [ "Theme", "slot", "slot/0" ]
|
_sections_unfolded = [ "Theme", "slot", "slot/0" ]
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ class CustomSorter:
|
|||||||
static func compare(a, b):
|
static func compare(a, b):
|
||||||
return a.v < b.v
|
return a.v < b.v
|
||||||
|
|
||||||
var points = [ { v=0.0, c=Color(0.0, 0.0, 0.0) }, { v=1.0, c=Color(1.0, 1.0, 1.0) } ]
|
var points = [ { v=0.0, c=Color(0.0, 0.0, 0.0, 0.0) }, { v=1.0, c=Color(1.0, 1.0, 1.0, 1.0) } ]
|
||||||
var sorted = true
|
var sorted = true
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
@ -46,12 +46,12 @@ func get_color(x):
|
|||||||
|
|
||||||
# get_color_in_shader
|
# get_color_in_shader
|
||||||
func gcis(color):
|
func gcis(color):
|
||||||
return "vec3(%.9f,%.9f,%.9f)" % [color.r, color.g, color.b]
|
return "vec4(%.9f,%.9f,%.9f,%.9f)" % [color.r, color.g, color.b, color.a]
|
||||||
|
|
||||||
func get_shader(name):
|
func get_shader(name):
|
||||||
sort()
|
sort()
|
||||||
var shader
|
var shader
|
||||||
shader = "vec3 "+name+"(float x) {\n"
|
shader = "vec4 "+name+"(float x) {\n"
|
||||||
shader += " if (x < %.9f) {\n" % points[0].v
|
shader += " if (x < %.9f) {\n" % points[0].v
|
||||||
shader += " return "+gcis(points[0].c)+";\n"
|
shader += " return "+gcis(points[0].c)+";\n"
|
||||||
var s = points.size()-1
|
var s = points.size()-1
|
||||||
@ -72,7 +72,7 @@ func serialize():
|
|||||||
sort()
|
sort()
|
||||||
var rv = []
|
var rv = []
|
||||||
for p in points:
|
for p in points:
|
||||||
rv.append({ pos=p.v, r=p.c.r, g=p.c.g, b=p.c.b })
|
rv.append({ pos=p.v, r=p.c.r, g=p.c.g, b=p.c.b, a=p.c.a })
|
||||||
rv = { type="Gradient", points=rv }
|
rv = { type="Gradient", points=rv }
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
@ -80,7 +80,9 @@ func deserialize(v):
|
|||||||
clear()
|
clear()
|
||||||
if typeof(v) == TYPE_ARRAY:
|
if typeof(v) == TYPE_ARRAY:
|
||||||
for i in v:
|
for i in v:
|
||||||
add_point(i.pos, Color(i.r, i.g, i.b))
|
if !i.has("a"): i.a = 1.0
|
||||||
|
add_point(i.pos, Color(i.r, i.g, i.b, i.a))
|
||||||
elif typeof(v) == TYPE_DICTIONARY && v.has("type") && v.type == "Gradient":
|
elif typeof(v) == TYPE_DICTIONARY && v.has("type") && v.type == "Gradient":
|
||||||
for i in v.points:
|
for i in v.points:
|
||||||
add_point(i.pos, Color(i.r, i.g, i.b))
|
if !i.has("a"): i.a = 1.0
|
||||||
|
add_point(i.pos, Color(i.r, i.g, i.b, i.a))
|
||||||
|
@ -9,7 +9,7 @@ class GradientCursor:
|
|||||||
func _ready():
|
func _ready():
|
||||||
rect_position = Vector2(0, 15)
|
rect_position = Vector2(0, 15)
|
||||||
rect_size = Vector2(WIDTH, 15)
|
rect_size = Vector2(WIDTH, 15)
|
||||||
|
|
||||||
func _gui_input(ev):
|
func _gui_input(ev):
|
||||||
if ev is InputEventMouseButton:
|
if ev is InputEventMouseButton:
|
||||||
if ev.button_index == BUTTON_LEFT && ev.doubleclick:
|
if ev.button_index == BUTTON_LEFT && ev.doubleclick:
|
||||||
@ -30,11 +30,16 @@ class GradientCursor:
|
|||||||
func set_color(c):
|
func set_color(c):
|
||||||
color = c
|
color = c
|
||||||
get_parent().update_value()
|
get_parent().update_value()
|
||||||
|
|
||||||
static func sort(a, b):
|
static func sort(a, b):
|
||||||
if a.get_position() < b.get_position():
|
if a.get_position() < b.get_position():
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
func _draw():
|
||||||
|
var c = color
|
||||||
|
c.a = 1.0
|
||||||
|
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
|
||||||
|
|
||||||
@ -49,7 +54,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:
|
if c != $Gradient && c != $Background:
|
||||||
remove_child(c)
|
remove_child(c)
|
||||||
c.free()
|
c.free()
|
||||||
for p in value.points:
|
for p in value.points:
|
||||||
@ -59,7 +64,7 @@ func set_value(v):
|
|||||||
func update_value():
|
func update_value():
|
||||||
value.clear()
|
value.clear()
|
||||||
for p in get_children():
|
for p in get_children():
|
||||||
if p != $Gradient:
|
if p != $Gradient && p != $Background:
|
||||||
value.add_point(p.rect_position.x/(rect_size.x-GradientCursor.WIDTH), p.color)
|
value.add_point(p.rect_position.x/(rect_size.x-GradientCursor.WIDTH), p.color)
|
||||||
update_shader()
|
update_shader()
|
||||||
|
|
||||||
@ -94,6 +99,7 @@ func _on_Popup_popup_hide():
|
|||||||
func get_sorted_cursors():
|
func get_sorted_cursors():
|
||||||
var array = get_children()
|
var array = get_children()
|
||||||
array.erase($Gradient)
|
array.erase($Gradient)
|
||||||
|
array.erase($Background)
|
||||||
array.sort_custom(GradientCursor, "sort")
|
array.sort_custom(GradientCursor, "sort")
|
||||||
return array
|
return array
|
||||||
|
|
||||||
@ -104,6 +110,6 @@ func update_shader():
|
|||||||
var shader
|
var shader
|
||||||
shader = "shader_type canvas_item;\n"
|
shader = "shader_type canvas_item;\n"
|
||||||
shader += value.get_shader("gradient")
|
shader += value.get_shader("gradient")
|
||||||
shader += "void fragment() { COLOR = vec4(gradient(UV.x), 1.0); }"
|
shader += "void fragment() { COLOR = gradient(UV.x); }"
|
||||||
$Gradient.material.shader.set_code(shader)
|
$Gradient.material.shader.set_code(shader)
|
||||||
emit_signal("updated", value)
|
emit_signal("updated", value)
|
||||||
|
@ -1,26 +1,42 @@
|
|||||||
[gd_scene load_steps=4 format=2]
|
[gd_scene load_steps=7 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://addons/material_maker/widgets/gradient_editor.gd" type="Script" id=1]
|
[ext_resource path="res://addons/material_maker/widgets/gradient_editor.gd" type="Script" id=1]
|
||||||
|
|
||||||
|
[sub_resource type="Shader" id=3]
|
||||||
|
|
||||||
|
code = "shader_type canvas_item;
|
||||||
|
|
||||||
|
void fragment() {
|
||||||
|
COLOR = vec4(vec3(2.0*fract(0.5*(floor(10.0*UV.x)+floor(2.0*UV.y)))), 1.0);
|
||||||
|
}"
|
||||||
|
|
||||||
|
[sub_resource type="ShaderMaterial" id=4]
|
||||||
|
|
||||||
|
render_priority = 0
|
||||||
|
shader = SubResource( 3 )
|
||||||
|
|
||||||
[sub_resource type="Shader" id=1]
|
[sub_resource type="Shader" id=1]
|
||||||
|
|
||||||
code = "shader_type canvas_item;
|
code = "shader_type canvas_item;
|
||||||
vec3 gradient(float x) {
|
vec4 gradient(float x) {
|
||||||
if (x < 0.000000000) {
|
if (x < 0.000000000) {
|
||||||
return vec3(0.000000000,0.000000000,0.000000000);
|
return vec4(0.000000000,0.000000000,0.000000000,0.000000000);
|
||||||
} else if (x < 1.000000000) {
|
} else if (x < 1.000000000) {
|
||||||
return vec3(0.000000000,0.000000000,0.000000000)+x*vec3(1.000000000,1.000000000,1.000000000);
|
return vec4(0.000000000,0.000000000,0.000000000,0.000000000)+x*vec4(1.000000000,1.000000000,1.000000000,1.000000000);
|
||||||
}
|
}
|
||||||
return vec3(1.000000000,1.000000000,1.000000000);
|
return vec4(1.000000000,1.000000000,1.000000000,1.000000000);
|
||||||
}
|
}
|
||||||
void fragment() { COLOR = vec4(gradient((UV.x-0.041666667)*1.090909091), 1.0); }"
|
void fragment() { COLOR = gradient(UV.x); }"
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id=2]
|
[sub_resource type="ShaderMaterial" id=2]
|
||||||
|
|
||||||
render_priority = 0
|
render_priority = 0
|
||||||
shader = SubResource( 1 )
|
shader = SubResource( 1 )
|
||||||
|
|
||||||
[node name="Control" type="Control" index="0"]
|
[sub_resource type="Theme" id=5]
|
||||||
|
|
||||||
|
|
||||||
|
[node name="Control" type="Control"]
|
||||||
|
|
||||||
anchor_left = 0.0
|
anchor_left = 0.0
|
||||||
anchor_top = 0.0
|
anchor_top = 0.0
|
||||||
@ -38,9 +54,9 @@ size_flags_vertical = 1
|
|||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
_sections_unfolded = [ "Rect" ]
|
_sections_unfolded = [ "Rect" ]
|
||||||
|
|
||||||
[node name="Gradient" type="ColorRect" parent="." index="0"]
|
[node name="Background" type="ColorRect" parent="." index="0"]
|
||||||
|
|
||||||
material = SubResource( 2 )
|
material = SubResource( 4 )
|
||||||
anchor_left = 0.0
|
anchor_left = 0.0
|
||||||
anchor_top = 0.0
|
anchor_top = 0.0
|
||||||
anchor_right = 0.0
|
anchor_right = 0.0
|
||||||
@ -57,6 +73,26 @@ size_flags_vertical = 1
|
|||||||
color = Color( 1, 1, 1, 1 )
|
color = Color( 1, 1, 1, 1 )
|
||||||
_sections_unfolded = [ "Material", "Rect" ]
|
_sections_unfolded = [ "Material", "Rect" ]
|
||||||
|
|
||||||
|
[node name="Gradient" type="ColorRect" parent="." index="1"]
|
||||||
|
|
||||||
|
material = SubResource( 2 )
|
||||||
|
anchor_left = 0.0
|
||||||
|
anchor_top = 0.0
|
||||||
|
anchor_right = 0.0
|
||||||
|
anchor_bottom = 0.0
|
||||||
|
margin_right = 120.0
|
||||||
|
margin_bottom = 20.0
|
||||||
|
rect_min_size = Vector2( 120, 20 )
|
||||||
|
rect_pivot_offset = Vector2( 0, 0 )
|
||||||
|
rect_clip_content = false
|
||||||
|
mouse_filter = 0
|
||||||
|
mouse_default_cursor_shape = 0
|
||||||
|
size_flags_horizontal = 1
|
||||||
|
size_flags_vertical = 1
|
||||||
|
theme = SubResource( 5 )
|
||||||
|
color = Color( 1, 1, 1, 1 )
|
||||||
|
_sections_unfolded = [ "Material", "Theme" ]
|
||||||
|
|
||||||
[node name="Popup" type="Popup" parent="Gradient" index="0"]
|
[node name="Popup" type="Popup" parent="Gradient" index="0"]
|
||||||
|
|
||||||
visible = false
|
visible = false
|
||||||
@ -95,7 +131,7 @@ size_flags_horizontal = 1
|
|||||||
size_flags_vertical = 1
|
size_flags_vertical = 1
|
||||||
alignment = 0
|
alignment = 0
|
||||||
color = Color( 1, 1, 1, 1 )
|
color = Color( 1, 1, 1, 1 )
|
||||||
edit_alpha = false
|
edit_alpha = true
|
||||||
raw_mode = false
|
raw_mode = false
|
||||||
_sections_unfolded = [ "Rect" ]
|
_sections_unfolded = [ "Rect" ]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user