Updated generic layout and implemented blend generator

Preview is now resized with a single click.
This commit is contained in:
RodZill4 2019-09-11 23:13:10 +02:00
parent 82f83ca482
commit 59dced1c09
6 changed files with 16 additions and 78 deletions

View File

@ -13,74 +13,6 @@ vec3 rand3(vec2 x) {
dot(x, vec2(13.254, 5.867)))) * 43758.5453);
}
vec3 blend_normal(vec2 uv, vec3 c1, vec3 c2, float opacity) {
return opacity*c1 + (1.0-opacity)*c2;
}
vec3 blend_dissolve(vec2 uv, vec3 c1, vec3 c2, float opacity) {
if (rand(uv) < opacity) {
return c1;
} else {
return c2;
}
}
vec3 blend_multiply(vec2 uv, vec3 c1, vec3 c2, float opacity) {
return opacity*c1*c2 + (1.0-opacity)*c2;
}
vec3 blend_screen(vec2 uv, vec3 c1, vec3 c2, float opacity) {
return opacity*(1.0-(1.0-c1)*(1.0-c2)) + (1.0-opacity)*c2;
}
float blend_overlay_f(float c1, float c2) {
return (c1 < 0.5) ? (2.0*c1*c2) : (1.0-2.0*(1.0-c1)*(1.0-c2));
}
vec3 blend_overlay(vec2 uv, vec3 c1, vec3 c2, float opacity) {
return opacity*vec3(blend_overlay_f(c1.x, c2.x), blend_overlay_f(c1.y, c2.y), blend_overlay_f(c1.z, c2.z)) + (1.0-opacity)*c2;
}
vec3 blend_hard_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {
return opacity*0.5*(c1*c2+blend_overlay(uv, c1, c2, 1.0)) + (1.0-opacity)*c2;
}
float blend_soft_light_f(float c1, float c2) {
return (c2 < 0.5) ? (2.0*c1*c2+c1*c1*(1.0-2.0*c2)) : 2.0*c1*(1.0-c2)+sqrt(c1)*(2.0*c2-1.0);
}
vec3 blend_soft_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {
return opacity*vec3(blend_soft_light_f(c1.x, c2.x), blend_soft_light_f(c1.y, c2.y), blend_soft_light_f(c1.z, c2.z)) + (1.0-opacity)*c2;
}
float blend_burn_f(float c1, float c2) {
return (c1==0.0)?c1:max((1.0-((1.0-c2)/c1)),0.0);
}
vec3 blend_burn(vec2 uv, vec3 c1, vec3 c2, float opacity) {
return opacity*vec3(blend_burn_f(c1.x, c2.x), blend_burn_f(c1.y, c2.y), blend_burn_f(c1.z, c2.z)) + (1.0-opacity)*c2;
}
float blend_dodge_f(float c1, float c2) {
return (c1==1.0)?c1:min(c2/(1.0-c1),1.0);
}
vec3 blend_dodge(vec2 uv, vec3 c1, vec3 c2, float opacity) {
return opacity*vec3(blend_dodge_f(c1.x, c2.x), blend_dodge_f(c1.y, c2.y), blend_dodge_f(c1.z, c2.z)) + (1.0-opacity)*c2;
}
vec3 blend_lighten(vec2 uv, vec3 c1, vec3 c2, float opacity) {
return opacity*max(c1, c2) + (1.0-opacity)*c2;
}
vec3 blend_darken(vec2 uv, vec3 c1, vec3 c2, float opacity) {
return opacity*min(c1, c2) + (1.0-opacity)*c2;
}
vec3 blend_difference(vec2 uv, vec3 c1, vec3 c2, float opacity) {
return opacity*clamp(c2-c1, vec3(0.0), vec3(1.0)) + (1.0-opacity)*c2;
}
vec2 transform(vec2 uv, vec2 translate, float rotate, vec2 scale) {
vec2 rv;
uv -= vec2(0.5);

View File

@ -0,0 +1 @@
{"name":"blend","node_position":{"x":0,"y":0},"parameters":{"amount":1,"blend_type":6},"shader_model":{"global":"vec3 blend_normal(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*c1 + (1.0-opacity)*c2;\n}\n\nvec3 blend_dissolve(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\tif (rand(uv) < opacity) {\n\t\treturn c1;\n\t} else {\n\t\treturn c2;\n\t}\n}\n\nvec3 blend_multiply(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*c1*c2 + (1.0-opacity)*c2;\n}\n\nvec3 blend_screen(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*(1.0-(1.0-c1)*(1.0-c2)) + (1.0-opacity)*c2;\n}\n\nfloat blend_overlay_f(float c1, float c2) {\n\treturn (c1 < 0.5) ? (2.0*c1*c2) : (1.0-2.0*(1.0-c1)*(1.0-c2));\n}\n\nvec3 blend_overlay(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_overlay_f(c1.x, c2.x), blend_overlay_f(c1.y, c2.y), blend_overlay_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nvec3 blend_hard_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*0.5*(c1*c2+blend_overlay(uv, c1, c2, 1.0)) + (1.0-opacity)*c2;\n}\n\nfloat blend_soft_light_f(float c1, float c2) {\n\treturn (c2 < 0.5) ? (2.0*c1*c2+c1*c1*(1.0-2.0*c2)) : 2.0*c1*(1.0-c2)+sqrt(c1)*(2.0*c2-1.0);\n}\n\nvec3 blend_soft_light(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_soft_light_f(c1.x, c2.x), blend_soft_light_f(c1.y, c2.y), blend_soft_light_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nfloat blend_burn_f(float c1, float c2) {\n\treturn (c1==0.0)?c1:max((1.0-((1.0-c2)/c1)),0.0);\n}\n\nvec3 blend_burn(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_burn_f(c1.x, c2.x), blend_burn_f(c1.y, c2.y), blend_burn_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nfloat blend_dodge_f(float c1, float c2) {\n\treturn (c1==1.0)?c1:min(c2/(1.0-c1),1.0);\n}\n\nvec3 blend_dodge(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*vec3(blend_dodge_f(c1.x, c2.x), blend_dodge_f(c1.y, c2.y), blend_dodge_f(c1.z, c2.z)) + (1.0-opacity)*c2;\n}\n\nvec3 blend_lighten(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*max(c1, c2) + (1.0-opacity)*c2;\n}\n\nvec3 blend_darken(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*min(c1, c2) + (1.0-opacity)*c2;\n}\n\nvec3 blend_difference(vec2 uv, vec3 c1, vec3 c2, float opacity) {\n\treturn opacity*clamp(c2-c1, vec3(0.0), vec3(1.0)) + (1.0-opacity)*c2;\n}\n","inputs":[{"default":"vec4($uv.x, 1.0, 1.0, 1.0)","label":"Source1","name":"s1","type":"rgba"},{"default":"vec4(1.0, $uv.y, 1.0, 1.0)","label":"Source2","name":"s2","type":"rgba"},{"default":"$amount","label":"Opacity","name":"a","type":"f"}],"instance":"","name":"Blend","outputs":[{"rgba":"vec4(blend_$blend_type($uv, $s1($uv).rgb, $s2($uv).rgb, $a($uv)*$s1($uv).a), min(1.0, $s2($uv).a+$a($uv)*$s1($uv).a))","type":"rgba"}],"parameters":[{"default":0,"label":"","name":"blend_type","type":"enum","values":[{"name":"Normal","value":"normal"},{"name":"Dissolve","value":"dissolve"},{"name":"Multiply","value":"multiply"},{"name":"Screen","value":"screen"},{"name":"Overlay","value":"overlay"},{"name":"Hard Light","value":"hard_light"},{"name":"Soft Light","value":"soft_light"},{"name":"Burn","value":"burn"},{"name":"Dodge","value":"dodge"},{"name":"Lighten","value":"lighten"},{"name":"Darken","value":"darken"},{"name":"Difference","value":"difference"}]},{"default":0.5,"label":"3:","max":1,"min":0,"name":"amount","step":0,"type":"float"}]}}

View File

@ -117,6 +117,8 @@ func update_node():
# Parameters
controls = []
var index = -1
var regex = RegEx.new()
regex.compile("^(\\d+):(.*)")
for p in generator.get_parameter_defs():
if !p.has("name") or !p.has("type"):
continue
@ -156,19 +158,22 @@ func update_node():
controls.append(control)
if p.has("label"):
label = p.label
if index == -1 or label != "nonewline":
var result = regex.search(label)
if result:
index = result.get_string(1).to_int()-1
label = result.get_string(2)
else:
index += 1
var hsizer : HBoxContainer
if index >= get_child_count():
while index >= get_child_count():
hsizer = HBoxContainer.new()
hsizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
var empty_control : Control = Control.new()
empty_control.rect_min_size.x = input_names_width
hsizer.add_child(empty_control)
add_child(hsizer)
else:
hsizer = get_child(index)
if label != "" and label != "nonewline":
hsizer = get_child(index)
if label != "":
var label_widget = Label.new()
label_widget.text = label
label_widget.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL
@ -207,7 +212,7 @@ func edit_generator():
edit_window.popup_centered()
func update_generator(shader_model):
generator.shader_model = shader_model
generator.set_shader_model(shader_model)
update_node()
func load_generator():

View File

@ -1 +1 @@
{"name":"pattern","node_position":{"x":0,"y":0},"parameters":{"mix":0,"x_scale":4,"x_wave":0,"y_scale":4,"y_wave":0},"shader_model":{"global":"float wave_constant(float x) {\n\treturn 1.0;\n}\n\nfloat wave_sine(float x) {\n\treturn 0.5-0.5*cos(3.14159265359*2.0*x);\n}\n\nfloat wave_triangle(float x) {\n\tx = fract(x);\n\treturn min(2.0*x, 2.0-2.0*x);\n}\n\nfloat wave_sawtooth(float x) {\n\treturn fract(x);\n}\n\nfloat wave_square(float x) {\n\treturn (fract(x) < 0.5) ? 0.0 : 1.0;\n}\n\nfloat mix_mul(float x, float y) {\n\treturn x*y;\n}\n\nfloat mix_add(float x, float y) {\n\treturn min(x+y, 1.0);\n}\n\nfloat mix_max(float x, float y) {\n\treturn max(x, y);\n}\n\nfloat mix_min(float x, float y) {\n\treturn min(x, y);\n}\n\nfloat mix_xor(float x, float y) {\n\treturn min(x+y, 2.0-x-y);\n}\n\nfloat mix_pow(float x, float y) {\n\treturn pow(x, y);\n}","instance":"float $(name)_fct(vec2 uv) {\n\treturn mix_$(mix)(wave_$(x_wave)($(x_scale)*uv.x), wave_$(y_wave)($(y_scale)*uv.y));\n}","name":"Pattern","outputs":[{"f":"$(name)_fct($(uv))"}],"parameters":[{"default":0,"label":"Combiner","name":"mix","type":"enum","values":[{"name":"Multiply","value":"mul"},{"name":"Add","value":"add"},{"name":"Max","value":"max"},{"name":"Min","value":"min"},{"name":"Xor","value":"xor"},{"name":"Pow","value":"pow"}]},{"default":0,"label":"X","name":"x_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"x_scale","step":1,"type":"float","widget":"spinbox"},{"default":0,"label":"Y","name":"y_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"nonewline","max":32,"min":0,"name":"y_scale","step":1,"type":"float","widget":"spinbox"}]}}
{"name":"pattern","node_position":{"x":0,"y":0},"parameters":{"mix":0,"x_scale":4,"x_wave":0,"y_scale":4,"y_wave":0},"shader_model":{"global":"float wave_constant(float x) {\n\treturn 1.0;\n}\n\nfloat wave_sine(float x) {\n\treturn 0.5-0.5*cos(3.14159265359*2.0*x);\n}\n\nfloat wave_triangle(float x) {\n\tx = fract(x);\n\treturn min(2.0*x, 2.0-2.0*x);\n}\n\nfloat wave_sawtooth(float x) {\n\treturn fract(x);\n}\n\nfloat wave_square(float x) {\n\treturn (fract(x) < 0.5) ? 0.0 : 1.0;\n}\n\nfloat mix_mul(float x, float y) {\n\treturn x*y;\n}\n\nfloat mix_add(float x, float y) {\n\treturn min(x+y, 1.0);\n}\n\nfloat mix_max(float x, float y) {\n\treturn max(x, y);\n}\n\nfloat mix_min(float x, float y) {\n\treturn min(x, y);\n}\n\nfloat mix_xor(float x, float y) {\n\treturn min(x+y, 2.0-x-y);\n}\n\nfloat mix_pow(float x, float y) {\n\treturn pow(x, y);\n}","inputs":[],"instance":"float $(name)_fct(vec2 uv) {\n\treturn mix_$(mix)(wave_$(x_wave)($(x_scale)*uv.x), wave_$(y_wave)($(y_scale)*uv.y));\n}","name":"Pattern","outputs":[{"f":"$(name)_fct($(uv))","type":"f"}],"parameters":[{"default":0,"label":"Combiner","name":"mix","type":"enum","values":[{"name":"Multiply","value":"mul"},{"name":"Add","value":"add"},{"name":"Max","value":"max"},{"name":"Min","value":"min"},{"name":"Xor","value":"xor"},{"name":"Pow","value":"pow"}]},{"default":0,"label":"X","name":"x_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"2:","max":32,"min":0,"name":"x_scale","step":1,"type":"float","widget":"spinbox"},{"default":0,"label":"Y","name":"y_wave","type":"enum","values":[{"name":"Sine","value":"sine"},{"name":"Triangle","value":"triangle"},{"name":"Square","value":"square"},{"name":"Sawtooth","value":"sawtooth"},{"name":"Constant","value":"constant"}]},{"default":4,"label":"3:","max":32,"min":0,"name":"y_scale","step":1,"type":"float","widget":"spinbox"}]}}

View File

@ -42,8 +42,8 @@ func _on_Preview_resized():
$Preview2D.rect_position = Vector2(0, rect_size.y-64)
$Preview2D.rect_size = Vector2(64, 64)
func _on_Preview2D_gui_input(ev):
if ev is InputEventMouseButton && ev.button_index == 1 && ev.doubleclick:
func _on_Preview2D_gui_input(ev : InputEvent):
if ev is InputEventMouseButton && ev.button_index == 1 && ev.pressed:
preview_maximized = !preview_maximized
_on_Preview_resized()

View File

@ -127,7 +127,7 @@ render_target_clear_mode = 1
render_target_update_mode = 3
[node name="Objects" type="Spatial" parent="MaterialPreview"]
transform = Transform( 0.979431, 0, -0.201756, 0, 1, 0, 0.201756, 0, 0.979431, 0, 0, 0 )
transform = Transform( -0.482492, 0, 0.875895, 0, 1, 0, -0.875895, 0, -0.482492, 0, 0, 0 )
[node name="Cube" type="MeshInstance" parent="MaterialPreview/Objects"]
mesh = SubResource( 2 )