Added blend modes + minor fixed

Added blend modes (Dissolve, Multiply, Screen, Overlay, Hard Light, Soft Light).
Fixed color popup position in the GradientEditor.
Fixed initial panoram shown in preview.
This commit is contained in:
RodZill4 2018-07-29 11:55:17 +02:00
parent dffc6fc790
commit 4c75ca8565
14 changed files with 92 additions and 45 deletions

View File

@ -18,6 +18,9 @@ func initialize_properties(object_list):
elif o is SpinBox: elif o is SpinBox:
set(o.name, o.value) set(o.name, o.value)
o.connect("value_changed", self, "_on_value_changed", [ o.name ]) o.connect("value_changed", self, "_on_value_changed", [ o.name ])
elif o is OptionButton:
set(o.name, o.selected)
o.connect("item_selected", self, "_on_value_changed", [ o.name ])
elif o is ColorPickerButton: elif o is ColorPickerButton:
set(o.name, o.color) set(o.name, o.color)
o.connect("color_changed", self, "_on_color_changed", [ o.name ]) o.connect("color_changed", self, "_on_color_changed", [ o.name ])

View File

@ -1,17 +1,24 @@
tool tool
extends "res://addons/procedural_material/node_base.gd" extends "res://addons/procedural_material/node_base.gd"
var blend_type = 0
var amount = 0.0 var amount = 0.0
const blend_types = [ const BLEND_TYPES = [
{ name="Normal", shortname="normal" } { name="Normal", shortname="normal" },
{ name="Dissolve", shortname="dissolve" },
{ name="Multiply", shortname="multiply" },
{ name="Screen", shortname="screen" },
{ name="Overlay", shortname="overlay" },
{ name="Hard Light", shortname="hard_light" },
{ name="Soft Light", shortname="soft_light" }
] ]
func _ready(): func _ready():
initialize_properties([ $HBoxContainer/amount ]) $blend_type.clear()
for i in range(BLEND_TYPES.size()):
func color_to_string(c): $blend_type.add_item(BLEND_TYPES[i].name, i)
return "vec3("+str(c.r)+","+str(c.g)+","+str(c.b)+")" initialize_properties([ $blend_type, $HBoxContainer/amount ])
func _get_shader_code(uv): func _get_shader_code(uv):
var rv = { defs="", code="" } var rv = { defs="", code="" }
@ -34,8 +41,8 @@ func _get_shader_code(uv):
variant_index = generated_variants.size() variant_index = generated_variants.size()
generated_variants.append(uv) generated_variants.append(uv)
rv.code = src0_code.code+src1_code.code+src2_code.code rv.code = src0_code.code+src1_code.code+src2_code.code
rv.code += "vec3 "+name+"_"+str(variant_index)+"_rgb = mix("+get_source_rgb(src0_code)+", "+get_source_rgb(src1_code)+", "+amount_str+");\n" rv.code += "vec3 %s_%d_rgb = blend_%s(%s, %s, %s, %s);\n" % [ name, variant_index, BLEND_TYPES[blend_type].shortname, uv, src0_code.rgb, src1_code.rgb, amount_str ]
rv.rgb = name+"_"+str(variant_index)+"_rgb" rv.rgb = "%s_%d_rgb" % [ name, variant_index ]
return rv return rv
func _get_state_variables(): func _get_state_variables():

View File

@ -55,7 +55,7 @@ slot/3/right_color = Color( 0.5, 0.5, 1, 1 )
script = ExtResource( 1 ) script = ExtResource( 1 )
_sections_unfolded = [ "Theme", "slot", "slot/1" ] _sections_unfolded = [ "Theme", "slot", "slot/1" ]
[node name="OptionButton" type="OptionButton" parent="." index="0"] [node name="blend_type" type="OptionButton" parent="." index="0"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0

View File

@ -4,7 +4,7 @@
[ext_resource path="res://addons/procedural_material/graph_edit.gd" type="Script" id=2] [ext_resource path="res://addons/procedural_material/graph_edit.gd" type="Script" id=2]
[ext_resource path="res://addons/procedural_material/nodes/material.tscn" type="PackedScene" id=3] [ext_resource path="res://addons/procedural_material/nodes/material.tscn" type="PackedScene" id=3]
[ext_resource path="res://addons/procedural_material/preview.gd" type="Script" id=4] [ext_resource path="res://addons/procedural_material/preview.gd" type="Script" id=4]
[ext_resource path="res://addons/procedural_material/panoramas/experiment.hdr" type="Texture" id=5] [ext_resource path="res://addons/procedural_material/panoramas/night.hdr" type="Texture" id=5]
[sub_resource type="Animation" id=1] [sub_resource type="Animation" id=1]
@ -514,7 +514,7 @@ _sections_unfolded = [ "GUI", "Render Target" ]
[node name="Objects" type="Spatial" parent="Preview/Preview/MaterialPreview" index="0"] [node name="Objects" type="Spatial" parent="Preview/Preview/MaterialPreview" index="0"]
transform = Transform( -0.0548036, 0, 0.998495, 0, 1, 0, -0.998495, 0, -0.0548036, 0, 0, 0 ) transform = Transform( 0.277021, 0, -0.960862, 0, 1, 0, 0.960862, 0, 0.277021, 0, 0, 0 )
_sections_unfolded = [ "Transform" ] _sections_unfolded = [ "Transform" ]
[node name="Cube" type="MeshInstance" parent="Preview/Preview/MaterialPreview/Objects" index="0"] [node name="Cube" type="MeshInstance" parent="Preview/Preview/MaterialPreview/Objects" index="0"]

View File

@ -15,6 +15,7 @@ func _ready():
$MaterialPreview/Objects/Cube.set_surface_material(0, preview_material) $MaterialPreview/Objects/Cube.set_surface_material(0, preview_material)
$MaterialPreview/Objects/Cylinder.set_surface_material(0, preview_material) $MaterialPreview/Objects/Cylinder.set_surface_material(0, preview_material)
$ObjectRotate.play("rotate") $ObjectRotate.play("rotate")
_on_Environment_item_selected($Environment.selected)
func _on_SelectedPreview_gui_input(ev): func _on_SelectedPreview_gui_input(ev):
if ev is InputEventMouseButton && ev.button_index == 1 && ev.doubleclick: if ev is InputEventMouseButton && ev.button_index == 1 && ev.doubleclick:

View File

@ -13,8 +13,72 @@ vec3 rand3(vec2 x) {
dot(x, vec2(13.254, 5.867)))) * 43758.5453); 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;
}
float sine(vec2 uv, float count, float sharpness) { float sine(vec2 uv, float count, float sharpness) {
return max(0.0, min(1.0, (0.5+sharpness*0.5*sin(count*3.1415928*2.0*uv.x)))); return clamp(0.5+sharpness*0.5*sin(count*3.1415928*2.0*uv.x), 0.0, 1.0);
} }
vec2 transform(vec2 uv, float rotate, float scale) { vec2 transform(vec2 uv, float rotate, float scale) {

View File

@ -13,7 +13,7 @@ class GradientCursor:
func _gui_input(ev): func _gui_input(ev):
if ev is InputEventMouseButton && ev.doubleclick: if ev is InputEventMouseButton && ev.doubleclick:
if ev.button_index == 1: if ev.button_index == 1:
get_parent().select_color(self) get_parent().select_color(self, ev.global_position)
elif ev.button_index == 2 && get_parent().get_sorted_cursors().size() > 2: elif ev.button_index == 2 && get_parent().get_sorted_cursors().size() > 2:
var parent = get_parent() var parent = get_parent()
parent.remove_child(self) parent.remove_child(self)
@ -59,9 +59,10 @@ func _gui_input(ev):
var active_cursor var active_cursor
func select_color(cursor): func select_color(cursor, position):
active_cursor = cursor active_cursor = cursor
$Gradient/Popup/ColorPicker.connect("color_changed", cursor, "set_color") $Gradient/Popup/ColorPicker.connect("color_changed", cursor, "set_color")
$Gradient/Popup.rect_position = position
$Gradient/Popup.popup() $Gradient/Popup.popup()
func _on_Popup_popup_hide(): func _on_Popup_popup_hide():

View File

@ -86,8 +86,8 @@ anchor_right = 0.0
anchor_bottom = 0.0 anchor_bottom = 0.0
margin_left = 4.0 margin_left = 4.0
margin_top = 4.0 margin_top = 4.0
margin_right = 4.0 margin_right = 302.0
margin_bottom = 4.0 margin_bottom = 438.0
rect_scale = Vector2( 0.75, 0.75 ) rect_scale = Vector2( 0.75, 0.75 )
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false rect_clip_content = false

BIN
doc/bricks.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
doc/perlin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
doc/sine.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 820 B

BIN
doc/voronoi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,29 +0,0 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/generated_image.png-791fdae0ab5829f929b4d82eecbe4bc3.stex"
[deps]
source_file="res://generated_image.png"
dest_files=[ "res://.import/generated_image.png-791fdae0ab5829f929b4d82eecbe4bc3.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0