mirror of
https://github.com/Relintai/material-maker.git
synced 2024-11-13 06:27:18 +01:00
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:
parent
dffc6fc790
commit
4c75ca8565
@ -18,6 +18,9 @@ func initialize_properties(object_list):
|
||||
elif o is SpinBox:
|
||||
set(o.name, o.value)
|
||||
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:
|
||||
set(o.name, o.color)
|
||||
o.connect("color_changed", self, "_on_color_changed", [ o.name ])
|
||||
|
@ -1,17 +1,24 @@
|
||||
tool
|
||||
extends "res://addons/procedural_material/node_base.gd"
|
||||
|
||||
var blend_type = 0
|
||||
var amount = 0.0
|
||||
|
||||
const blend_types = [
|
||||
{ name="Normal", shortname="normal" }
|
||||
const BLEND_TYPES = [
|
||||
{ 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():
|
||||
initialize_properties([ $HBoxContainer/amount ])
|
||||
|
||||
func color_to_string(c):
|
||||
return "vec3("+str(c.r)+","+str(c.g)+","+str(c.b)+")"
|
||||
$blend_type.clear()
|
||||
for i in range(BLEND_TYPES.size()):
|
||||
$blend_type.add_item(BLEND_TYPES[i].name, i)
|
||||
initialize_properties([ $blend_type, $HBoxContainer/amount ])
|
||||
|
||||
func _get_shader_code(uv):
|
||||
var rv = { defs="", code="" }
|
||||
@ -34,8 +41,8 @@ func _get_shader_code(uv):
|
||||
variant_index = generated_variants.size()
|
||||
generated_variants.append(uv)
|
||||
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.rgb = name+"_"+str(variant_index)+"_rgb"
|
||||
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 = "%s_%d_rgb" % [ name, variant_index ]
|
||||
return rv
|
||||
|
||||
func _get_state_variables():
|
||||
|
@ -55,7 +55,7 @@ slot/3/right_color = Color( 0.5, 0.5, 1, 1 )
|
||||
script = ExtResource( 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_top = 0.0
|
||||
|
@ -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/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/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]
|
||||
|
||||
@ -514,7 +514,7 @@ _sections_unfolded = [ "GUI", "Render Target" ]
|
||||
|
||||
[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" ]
|
||||
|
||||
[node name="Cube" type="MeshInstance" parent="Preview/Preview/MaterialPreview/Objects" index="0"]
|
||||
|
@ -15,6 +15,7 @@ func _ready():
|
||||
$MaterialPreview/Objects/Cube.set_surface_material(0, preview_material)
|
||||
$MaterialPreview/Objects/Cylinder.set_surface_material(0, preview_material)
|
||||
$ObjectRotate.play("rotate")
|
||||
_on_Environment_item_selected($Environment.selected)
|
||||
|
||||
func _on_SelectedPreview_gui_input(ev):
|
||||
if ev is InputEventMouseButton && ev.button_index == 1 && ev.doubleclick:
|
||||
|
@ -13,8 +13,72 @@ 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;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -13,7 +13,7 @@ class GradientCursor:
|
||||
func _gui_input(ev):
|
||||
if ev is InputEventMouseButton && ev.doubleclick:
|
||||
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:
|
||||
var parent = get_parent()
|
||||
parent.remove_child(self)
|
||||
@ -59,9 +59,10 @@ func _gui_input(ev):
|
||||
|
||||
var active_cursor
|
||||
|
||||
func select_color(cursor):
|
||||
func select_color(cursor, position):
|
||||
active_cursor = cursor
|
||||
$Gradient/Popup/ColorPicker.connect("color_changed", cursor, "set_color")
|
||||
$Gradient/Popup.rect_position = position
|
||||
$Gradient/Popup.popup()
|
||||
|
||||
func _on_Popup_popup_hide():
|
||||
|
@ -86,8 +86,8 @@ anchor_right = 0.0
|
||||
anchor_bottom = 0.0
|
||||
margin_left = 4.0
|
||||
margin_top = 4.0
|
||||
margin_right = 4.0
|
||||
margin_bottom = 4.0
|
||||
margin_right = 302.0
|
||||
margin_bottom = 438.0
|
||||
rect_scale = Vector2( 0.75, 0.75 )
|
||||
rect_pivot_offset = Vector2( 0, 0 )
|
||||
rect_clip_content = false
|
||||
|
BIN
doc/bricks.png
Normal file
BIN
doc/bricks.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
BIN
doc/perlin.png
Normal file
BIN
doc/perlin.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
BIN
doc/sine.png
Normal file
BIN
doc/sine.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 820 B |
BIN
doc/voronoi.png
Normal file
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 |
@ -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
|
Loading…
Reference in New Issue
Block a user