diff options
author | Mariano Javier Suligoy <marianognu.easyrpg@gmail.com> | 2015-08-29 21:09:11 -0300 |
---|---|---|
committer | Mariano Javier Suligoy <marianognu.easyrpg@gmail.com> | 2015-08-29 21:09:11 -0300 |
commit | ea448cb779c9268f6213a8e741cfc793704ca2fe (patch) | |
tree | bb73102684f2281d5488fc904605e6477a19d7eb /tools/editor/plugins | |
parent | cbf05355ed7e05285f7036bb4211e190c903a665 (diff) |
Edit default values. WARNING!!!
Do not merge these changes, default values are not compiled into shaders yet!
Diffstat (limited to 'tools/editor/plugins')
-rw-r--r-- | tools/editor/plugins/shader_graph_editor_plugin.cpp | 437 | ||||
-rw-r--r-- | tools/editor/plugins/shader_graph_editor_plugin.h | 6 |
2 files changed, 394 insertions, 49 deletions
diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index b2de10ca20..12a9dce6b7 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -29,6 +29,7 @@ #include "shader_graph_editor_plugin.h" +#include "scene/gui/check_box.h" #include "scene/gui/menu_button.h" #include "scene/gui/panel.h" #include "spatial_editor_plugin.h" @@ -840,6 +841,7 @@ void ShaderGraphView::_xform_input_changed(int p_id, Node *p_button){ ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; + edited_def=-1; ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_input_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); ped_popup->popup(); @@ -850,6 +852,7 @@ void ShaderGraphView::_xform_const_changed(int p_id, Node *p_button){ ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; + edited_def=-1; ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_const_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); ped_popup->popup(); @@ -879,6 +882,35 @@ void ShaderGraphView::_cube_input_change(int p_id){ void ShaderGraphView::_variant_edited() { + if (edited_def != -1) { + + Variant v = ped_popup->get_variant(); + Variant v2 = graph->default_get_value(type,edited_id,edited_def); + if (v2.get_type() == Variant::NIL) + switch (v.get_type()) { + case Variant::VECTOR3: + v2=Vector3(); + break; + case Variant::REAL: + v2=0.0; + break; + case Variant::TRANSFORM: + v2=Transform(); + break; + case Variant::COLOR: + v2=Color(); + break; + } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change default value"); + ur->add_do_method(graph.ptr(),"default_set_value",type,edited_id,edited_def, v); + ur->add_undo_method(graph.ptr(),"default_set_value",type,edited_id,edited_def, v2); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + return; + } + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_CONST) { UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); @@ -1043,6 +1075,7 @@ void ShaderGraphView::_tex_edited(int p_id,Node* p_button) { ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; + edited_def=-1; ped_popup->edit(NULL,"",Variant::OBJECT,graph->texture_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"Texture"); } @@ -1052,6 +1085,7 @@ void ShaderGraphView::_cube_edited(int p_id,Node* p_button) { ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); ped_popup->set_size(tb->get_size()); edited_id=p_id; + edited_def=-1; ped_popup->edit(NULL,"",Variant::OBJECT,graph->cubemap_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"CubeMap"); } @@ -1260,6 +1294,97 @@ void ShaderGraphView::_delete_nodes_request() } +void ShaderGraphView::_default_changed(int p_id, Node *p_button, int p_param, int v_type, String p_hint) +{ + ToolButton *tb = p_button->cast_to<ToolButton>(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + edited_def=p_param; + Variant::Type vt = (Variant::Type)v_type; + Variant v = graph->default_get_value(type,p_id,edited_def); + int h=PROPERTY_HINT_NONE; + if (v.get_type() == Variant::NIL) + switch (vt) { + case Variant::VECTOR3: + v=Vector3(); + break; + case Variant::REAL: + h=PROPERTY_HINT_RANGE; + v=0.0; + break; + case Variant::TRANSFORM: + v=Transform(); + break; + case Variant::COLOR: + h=PROPERTY_HINT_COLOR_NO_ALPHA; + v=Color(); + break; + } + + ped_popup->edit(NULL,"",vt,v,h,p_hint); + + ped_popup->popup(); +} + +ToolButton *ShaderGraphView::make_label(String text, Variant::Type v_type) { + ToolButton *l = memnew( ToolButton ); + l->set_text(text); + l->set_text_align(ToolButton::ALIGN_LEFT); + l->add_style_override("hover", l->get_stylebox("normal", "ToolButton")); + l->add_style_override("pressed", l->get_stylebox("normal", "ToolButton")); + l->add_style_override("focus", l->get_stylebox("normal", "ToolButton")); + switch (v_type) { + case Variant::REAL: + l->set_icon(ped_popup->get_icon("Real", "EditorIcons")); + break; + case Variant::VECTOR3: + l->set_icon(ped_popup->get_icon("Vector", "EditorIcons")); + break; + case Variant::TRANSFORM: + l->set_icon(ped_popup->get_icon("Matrix", "EditorIcons")); + break; + case Variant::COLOR: + l->set_icon(ped_popup->get_icon("Color", "EditorIcons")); + } + return l; +} + +ToolButton *ShaderGraphView::make_editor(String text,GraphNode* gn,int p_id,int param,Variant::Type v_type, String p_hint) { + ToolButton *edit = memnew( ToolButton ); + edit->set_text(text); + edit->set_text_align(ToolButton::ALIGN_LEFT); + edit->set_flat(false); + edit->add_style_override("normal", gn->get_stylebox("defaultframe", "GraphNode")); + edit->add_style_override("hover", gn->get_stylebox("defaultframe", "GraphNode")); + edit->add_style_override("pressed", gn->get_stylebox("defaultframe", "GraphNode")); + edit->add_style_override("focus", gn->get_stylebox("defaultfocus", "GraphNode")); + edit->connect("pressed",this,"_default_changed",varray(p_id,edit,param,v_type,p_hint)); + + switch (v_type) { + case Variant::REAL: + edit->set_icon(ped_popup->get_icon("Real", "EditorIcons")); + break; + case Variant::VECTOR3: + edit->set_icon(ped_popup->get_icon("Vector", "EditorIcons")); + break; + case Variant::TRANSFORM: + edit->set_icon(ped_popup->get_icon("Matrix", "EditorIcons")); + break; + case Variant::COLOR: + Image icon_color = Image(15,15,false,Image::FORMAT_RGB); + Color c = graph->default_get_value(type,p_id,param); + for (int x=1;x<14;x++) + for (int y=1;y<14;y++) + icon_color.put_pixel(x,y,c); + Ref<ImageTexture> t; + t.instance(); + t->create_from_image(icon_color); + edit->set_icon(t); + break; + } + return edit; +} void ShaderGraphView::_create_node(int p_id) { @@ -1273,6 +1398,9 @@ void ShaderGraphView::_create_node(int p_id) { Color(0,1,1) }; + const String hint_spin = "-65536,65535,0.001"; + const String hint_slider = "0.0,1.0,0.01,slider"; + switch(graph->node_get_type(type,p_id)) { @@ -1377,7 +1505,12 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("ScreenTex"); HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); + if (!graph->is_slot_connected(type,p_id,0)) { + Vector3 v = graph->default_get_value(type, p_id, 0); + hbc->add_child(make_editor("UV: " + v,gn,p_id,0,Variant::VECTOR3)); + } else { + hbc->add_child(make_label("UV",Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("RGB"))); gn->add_child(hbc); @@ -1411,11 +1544,21 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a",Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("a: ")+Variant(v),gn,p_id,0,Variant::REAL,hint_spin)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b",Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("b: ")+Variant(v),gn,p_id,1,Variant::REAL,hint_spin)); + } gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); @@ -1449,11 +1592,21 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a",Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("a: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b",Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("b: ")+v,gn,p_id,1,Variant::VECTOR3)); + } gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); @@ -1481,12 +1634,22 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a",Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("a: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b",Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("b: ")+Variant(v),gn,p_id,1,Variant::REAL,hint_spin)); + } gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); @@ -1519,11 +1682,19 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a",Variant::COLOR)); + } else { + hbc->add_child(make_editor(String("a: "),gn,p_id,0,Variant::COLOR)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b",Variant::COLOR)); + } else { + gn->add_child(make_editor(String("b: "),gn,p_id,1,Variant::COLOR)); + } gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); @@ -1533,11 +1704,19 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("XFMult"); HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a",Variant::TRANSFORM)); + } else { + hbc->add_child(make_editor(String("a: edit..."),gn,p_id,0,Variant::TRANSFORM)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b",Variant::TRANSFORM)); + } else { + gn->add_child(make_editor(String("b: edit..."),gn,p_id,1,Variant::TRANSFORM)); + } gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],false,0,Color()); @@ -1548,8 +1727,7 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("XFVecMult"); - Button *button = memnew( Button("RotOnly")); - button->set_toggle_mode(true); + CheckBox *button = memnew (CheckBox("RotOnly")); button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); @@ -1557,13 +1735,22 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("xf"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("xf",Variant::TRANSFORM)); + } else { + hbc->add_child(make_editor(String("xf: edit..."),gn,p_id,0,Variant::TRANSFORM)); + } hbc->add_spacer(); Label *l = memnew(Label("out")); l->set_align(Label::ALIGN_RIGHT); hbc->add_child( l); gn->add_child(hbc); - gn->add_child( memnew(Label("vec"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("a",Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("a: ")+v,gn,p_id,1,Variant::VECTOR3)); + } gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); @@ -1574,17 +1761,25 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("XFVecInvMult"); - Button *button = memnew( Button("RotOnly")); - button->set_toggle_mode(true); + CheckBox *button = memnew( CheckBox("RotOnly")); button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); gn->add_child(button); - gn->add_child( memnew(Label("vec"))); + if (graph->is_slot_connected(type, p_id, 0)) { + gn->add_child(make_label("a",Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + gn->add_child(make_editor(String("a: ")+v,gn,p_id,0,Variant::VECTOR3)); + } HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("xf"))); + if (graph->is_slot_connected(type, p_id, 1)) { + hbc->add_child(make_label("xf", Variant::TRANSFORM)); + } else { + hbc->add_child(make_editor(String("xf: edit..."),gn,p_id,1,Variant::TRANSFORM)); + } hbc->add_spacer(); Label *l = memnew(Label("out")); l->set_align(Label::ALIGN_RIGHT); @@ -1633,7 +1828,12 @@ void ShaderGraphView::_create_node(int p_id) { gn->add_child(ob); HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("in"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("in", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("in: ")+Variant(v),gn,p_id,0,Variant::REAL,hint_spin)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); @@ -1668,7 +1868,12 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("in"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("in", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("in: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("out"))); gn->add_child(hbc); @@ -1679,7 +1884,12 @@ void ShaderGraphView::_create_node(int p_id) { case ShaderGraph::NODE_VEC_LEN: { gn->set_title("VecLength"); HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("in"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("in", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("in: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("len"))); gn->add_child(hbc); @@ -1692,11 +1902,21 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("DotProduct"); HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("a: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("dp"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("b: ")+v,gn,p_id,1,Variant::VECTOR3)); + } gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); @@ -1707,7 +1927,12 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("Vec2Scalar"); HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("vec"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("vec", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("vec: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); Label *l=memnew(Label("x")); l->set_align(Label::ALIGN_RIGHT); @@ -1732,12 +1957,27 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("Scalar2Vec"); HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("x"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("x", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("x: ")+Variant(v),gn,p_id,0,Variant::REAL)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("vec"))); gn->add_child(hbc); - gn->add_child( memnew(Label("y"))); - gn->add_child( memnew(Label("z"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("y", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("y: ")+Variant(v),gn,p_id,1,Variant::REAL)); + } + if (graph->is_slot_connected(type, p_id, 2)) { + gn->add_child(make_label("in", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,2); + gn->add_child(make_editor(String("in: ")+Variant(v),gn,p_id,2,Variant::REAL)); + } gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); @@ -1749,13 +1989,33 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("Vec2XForm"); HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("x"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("x", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("x: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("xf"))); gn->add_child(hbc); - gn->add_child( memnew(Label("y"))); - gn->add_child( memnew(Label("z"))); - gn->add_child( memnew(Label("ofs"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("y", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("y: ")+v,gn,p_id,1,Variant::VECTOR3)); + } + if (graph->is_slot_connected(type, p_id, 2)) { + gn->add_child(make_label("z", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,2); + gn->add_child(make_editor(String("z: ")+v,gn,p_id,2,Variant::VECTOR3)); + } + if (graph->is_slot_connected(type, p_id, 3)) { + gn->add_child(make_label("ofs", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,3); + gn->add_child(make_editor(String("ofs: ")+v,gn,p_id,3,Variant::VECTOR3)); + } gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); @@ -1769,7 +2029,11 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("xf"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("fx", Variant::TRANSFORM)); + } else { + hbc->add_child(make_editor(String("fx: edit..."),gn,p_id,0,Variant::TRANSFORM)); + } hbc->add_spacer(); Label *l=memnew(Label("x")); l->set_align(Label::ALIGN_RIGHT); @@ -1796,12 +2060,27 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("ScalarInterp"); HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("a: ")+Variant(v),gn,p_id,0,Variant::REAL,hint_spin)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("interp"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - gn->add_child( memnew(Label("c"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("b: ")+Variant(v),gn,p_id,1,Variant::REAL,hint_spin)); + } + if (graph->is_slot_connected(type, p_id, 2)) { + gn->add_child(make_label("c", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,2); + gn->add_child(make_editor(String("c: ")+Variant(v),gn,p_id,2,Variant::REAL,hint_slider)); + } gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); @@ -1813,12 +2092,27 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("VecInterp"); HBoxContainer *hbc = memnew( HBoxContainer ); - hbc->add_child( memnew(Label("a"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("a", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("a: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); hbc->add_child( memnew(Label("interp"))); gn->add_child(hbc); - gn->add_child( memnew(Label("b"))); - gn->add_child( memnew(Label("c"))); + if (graph->is_slot_connected(type, p_id, 1)) { + gn->add_child(make_label("b", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,1); + gn->add_child(make_editor(String("b: ")+v,gn,p_id,1,Variant::VECTOR3)); + } + if (graph->is_slot_connected(type, p_id, 2)) { + gn->add_child(make_label("c", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,2); + gn->add_child(make_editor(String("c: ")+Variant(v),gn,p_id,2,Variant::REAL,hint_slider)); + } gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); @@ -1857,7 +2151,12 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("c"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("c", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("c: ")+Variant(v),gn,p_id,0,Variant::REAL,hint_slider)); + } hbc->add_spacer(); Label *l=memnew(Label("rgb")); l->set_align(Label::ALIGN_RIGHT); @@ -1902,7 +2201,12 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("c"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("c", Variant::REAL)); + } else { + float v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("c: ")+Variant(v),gn,p_id,0,Variant::REAL,hint_slider)); + } hbc->add_spacer(); Label *l=memnew(Label("cmap")); l->set_align(Label::ALIGN_RIGHT); @@ -2016,7 +2320,12 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("UV", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("UV: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); Label *l=memnew(Label("RGB")); l->set_align(Label::ALIGN_RIGHT); @@ -2047,7 +2356,12 @@ void ShaderGraphView::_create_node(int p_id) { HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("UV", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("UV: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); Label *l=memnew(Label("RGB")); l->set_align(Label::ALIGN_RIGHT); @@ -2067,7 +2381,12 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_title("CanvasItemTex"); HBoxContainer *hbc = memnew( HBoxContainer ); hbc->add_constant_override("separation",0); - hbc->add_child( memnew(Label("UV"))); + if (graph->is_slot_connected(type, p_id, 0)) { + hbc->add_child(make_label("UV", Variant::VECTOR3)); + } else { + Vector3 v = graph->default_get_value(type,p_id,0); + hbc->add_child(make_editor(String("UV: ")+v,gn,p_id,0,Variant::VECTOR3)); + } hbc->add_spacer(); Label *l=memnew(Label("RGB")); l->set_align(Label::ALIGN_RIGHT); @@ -2091,15 +2410,34 @@ void ShaderGraphView::_create_node(int p_id) { List<ShaderGraph::SlotInfo> si; ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si); + Array colors; + colors.push_back("Color"); + colors.push_back("LightColor"); + Array reals; + reals.push_back("Alpha"); + reals.push_back("NormapMapDepth"); + reals.push_back("LightAlpha"); + reals.push_back("PointSize"); + Array vectors; + vectors.push_back("Normal"); + vectors.push_back("NormalMap"); + vectors.push_back("Vertex"); + vectors.push_back("UV"); + vectors.push_back("Var1"); + vectors.push_back("Var2"); + int idx=0; for (List<ShaderGraph::SlotInfo>::Element *E=si.front();E;E=E->next()) { ShaderGraph::SlotInfo& s=E->get(); if (s.dir==ShaderGraph::SLOT_OUT) { - - Label *l= memnew( Label ); - l->set_text(s.name); - l->set_align(Label::ALIGN_LEFT); - gn->add_child(l); + Variant::Type v; + if (colors.find(s.name)>=0) + v=Variant::COLOR; + else if (reals.find(s.name)>=0) + v=Variant::REAL; + else if (vectors.find(s.name)>=0) + v=Variant::VECTOR3; + gn->add_child(make_label(s.name, v)); gn->set_slot(idx,true,s.type,typecol[s.type],false,0,Color()); idx++; } @@ -2256,6 +2594,7 @@ void ShaderGraphView::_bind_methods() { ObjectTypeDB::bind_method("_duplicate_nodes", &ShaderGraphView::_duplicate_nodes); ObjectTypeDB::bind_method("_delete_nodes_request", &ShaderGraphView::_delete_nodes_request); + ObjectTypeDB::bind_method("_default_changed",&ShaderGraphView::_default_changed); ObjectTypeDB::bind_method("_scalar_const_changed",&ShaderGraphView::_scalar_const_changed); ObjectTypeDB::bind_method("_vec_const_changed",&ShaderGraphView::_vec_const_changed); ObjectTypeDB::bind_method("_rgb_const_changed",&ShaderGraphView::_rgb_const_changed); diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h index 36443efeb0..800fdf1fea 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.h +++ b/tools/editor/plugins/shader_graph_editor_plugin.h @@ -129,6 +129,7 @@ class ShaderGraphView : public Node { GraphEdit *graph_edit; Ref<ShaderGraph> graph; int edited_id; + int edited_def; ShaderGraph::ShaderType type; @@ -136,6 +137,8 @@ class ShaderGraphView : public Node { void _create_node(int p_id); + ToolButton *make_label(String text, Variant::Type v_type = Variant::NIL); + ToolButton *make_editor(String text, GraphNode* gn, int p_id, int param, Variant::Type type, String p_hint=""); void _connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); void _disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); @@ -149,6 +152,9 @@ class ShaderGraphView : public Node { void _duplicate_nodes(Array &p_nodes); void _delete_nodes_request(); + + void _default_changed(int p_id, Node* p_button, int p_param, int v_type, String p_hint); + void _scalar_const_changed(double p_value,int p_id); void _vec_const_changed(double p_value, int p_id, Array p_arr); void _rgb_const_changed(const Color& p_color, int p_id); |