diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/area_2d.cpp | 34 | ||||
-rw-r--r-- | scene/2d/area_2d.h | 10 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 53 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.h | 12 | ||||
-rw-r--r-- | scene/gui/graph_edit.cpp | 77 | ||||
-rw-r--r-- | scene/gui/graph_edit.h | 9 | ||||
-rw-r--r-- | scene/gui/graph_node.cpp | 31 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 176 | ||||
-rw-r--r-- | scene/resources/curve.cpp | 6 | ||||
-rw-r--r-- | scene/resources/shader.cpp | 7 | ||||
-rw-r--r-- | scene/resources/shader_graph.cpp | 496 | ||||
-rw-r--r-- | scene/resources/shader_graph.h | 12 | ||||
-rw-r--r-- | scene/resources/world_2d.cpp | 4 | ||||
-rw-r--r-- | scene/scene_string_names.cpp | 1 | ||||
-rw-r--r-- | scene/scene_string_names.h | 1 |
15 files changed, 706 insertions, 223 deletions
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index ca2a42026d..fce21f6001 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -73,14 +73,25 @@ real_t Area2D::get_gravity() const{ return gravity; } -void Area2D::set_density(real_t p_density){ +void Area2D::set_linear_damp(real_t p_linear_damp){ - density=p_density; - Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_DENSITY,p_density); + linear_damp=p_linear_damp; + Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_LINEAR_DAMP,p_linear_damp); } -real_t Area2D::get_density() const{ +real_t Area2D::get_linear_damp() const{ - return density; + return linear_damp; +} + +void Area2D::set_angular_damp(real_t p_angular_damp){ + + angular_damp=p_angular_damp; + Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_ANGULAR_DAMP,p_angular_damp); +} + +real_t Area2D::get_angular_damp() const{ + + return angular_damp; } void Area2D::set_priority(real_t p_priority){ @@ -314,8 +325,11 @@ void Area2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_gravity","gravity"),&Area2D::set_gravity); ObjectTypeDB::bind_method(_MD("get_gravity"),&Area2D::get_gravity); - ObjectTypeDB::bind_method(_MD("set_density","density"),&Area2D::set_density); - ObjectTypeDB::bind_method(_MD("get_density"),&Area2D::get_density); + ObjectTypeDB::bind_method(_MD("set_linear_damp","linear_damp"),&Area2D::set_linear_damp); + ObjectTypeDB::bind_method(_MD("get_linear_damp"),&Area2D::get_linear_damp); + + ObjectTypeDB::bind_method(_MD("set_angular_damp","angular_damp"),&Area2D::set_angular_damp); + ObjectTypeDB::bind_method(_MD("get_angular_damp"),&Area2D::get_angular_damp); ObjectTypeDB::bind_method(_MD("set_priority","priority"),&Area2D::set_priority); ObjectTypeDB::bind_method(_MD("get_priority"),&Area2D::get_priority); @@ -337,7 +351,8 @@ void Area2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),_SCS("set_gravity"),_SCS("get_gravity")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"density",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_density"),_SCS("get_density")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"linear_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_linear_damp"),_SCS("get_linear_damp")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_angular_damp"),_SCS("get_angular_damp")); ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"priority",PROPERTY_HINT_RANGE,"0,128,1"),_SCS("set_priority"),_SCS("get_priority")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitoring"),_SCS("set_enable_monitoring"),_SCS("is_monitoring_enabled")); @@ -349,7 +364,8 @@ Area2D::Area2D() : CollisionObject2D(Physics2DServer::get_singleton()->area_crea set_gravity(98);; set_gravity_vector(Vector2(0,1)); gravity_is_point=false; - density=0.1; + linear_damp=0.1; + angular_damp=1; locked=false; priority=0; monitoring=false; diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index 2044cc7db0..f770e88a19 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -49,7 +49,8 @@ private: Vector2 gravity_vec; real_t gravity; bool gravity_is_point; - real_t density; + real_t linear_damp; + real_t angular_damp; int priority; bool monitoring; bool locked; @@ -104,8 +105,11 @@ public: void set_gravity(real_t p_gravity); real_t get_gravity() const; - void set_density(real_t p_density); - real_t get_density() const; + void set_linear_damp(real_t p_linear_damp); + real_t get_linear_damp() const; + + void set_angular_damp(real_t p_angular_damp); + real_t get_angular_damp() const; void set_priority(real_t p_priority); real_t get_priority() const; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 9d10000d2b..2413fbded1 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -496,6 +496,42 @@ real_t RigidBody2D::get_bounce() const{ return bounce; } + +void RigidBody2D::set_gravity_scale(real_t p_gravity_scale){ + + gravity_scale=p_gravity_scale; + Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_GRAVITY_SCALE,gravity_scale); + +} +real_t RigidBody2D::get_gravity_scale() const{ + + return gravity_scale; +} + +void RigidBody2D::set_linear_damp(real_t p_linear_damp){ + + ERR_FAIL_COND(p_linear_damp<-1); + linear_damp=p_linear_damp; + Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_LINEAR_DAMP,linear_damp); + +} +real_t RigidBody2D::get_linear_damp() const{ + + return linear_damp; +} + +void RigidBody2D::set_angular_damp(real_t p_angular_damp){ + + ERR_FAIL_COND(p_angular_damp<-1); + angular_damp=p_angular_damp; + Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_ANGULAR_DAMP,angular_damp); + +} +real_t RigidBody2D::get_angular_damp() const{ + + return angular_damp; +} + void RigidBody2D::set_axis_velocity(const Vector2& p_axis) { Vector2 v = state? state->get_linear_velocity() : linear_velocity; @@ -683,6 +719,15 @@ void RigidBody2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_bounce","bounce"),&RigidBody2D::set_bounce); ObjectTypeDB::bind_method(_MD("get_bounce"),&RigidBody2D::get_bounce); + ObjectTypeDB::bind_method(_MD("set_gravity_scale","gravity_scale"),&RigidBody2D::set_gravity_scale); + ObjectTypeDB::bind_method(_MD("get_gravity_scale"),&RigidBody2D::get_gravity_scale); + + ObjectTypeDB::bind_method(_MD("set_linear_damp","linear_damp"),&RigidBody2D::set_linear_damp); + ObjectTypeDB::bind_method(_MD("get_linear_damp"),&RigidBody2D::get_linear_damp); + + ObjectTypeDB::bind_method(_MD("set_angular_damp","angular_damp"),&RigidBody2D::set_angular_damp); + ObjectTypeDB::bind_method(_MD("get_angular_damp"),&RigidBody2D::get_angular_damp); + ObjectTypeDB::bind_method(_MD("set_linear_velocity","linear_velocity"),&RigidBody2D::set_linear_velocity); ObjectTypeDB::bind_method(_MD("get_linear_velocity"),&RigidBody2D::get_linear_velocity); @@ -726,6 +771,7 @@ void RigidBody2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::REAL,"weight",PROPERTY_HINT_EXP_RANGE,"0.01,65535,0.01",PROPERTY_USAGE_EDITOR),_SCS("set_weight"),_SCS("get_weight")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"friction",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_friction"),_SCS("get_friction")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_bounce"),_SCS("get_bounce")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_scale",PROPERTY_HINT_RANGE,"-128,128,0.01"),_SCS("set_gravity_scale"),_SCS("get_gravity_scale")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"custom_integrator"),_SCS("set_use_custom_integrator"),_SCS("is_using_custom_integrator")); ADD_PROPERTY( PropertyInfo(Variant::INT,"continuous_cd",PROPERTY_HINT_ENUM,"Disabled,Cast Ray,Cast Shape"),_SCS("set_continuous_collision_detection_mode"),_SCS("get_continuous_collision_detection_mode")); ADD_PROPERTY( PropertyInfo(Variant::INT,"contacts_reported"),_SCS("set_max_contacts_reported"),_SCS("get_max_contacts_reported")); @@ -734,6 +780,8 @@ void RigidBody2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"can_sleep"),_SCS("set_can_sleep"),_SCS("is_able_to_sleep")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"velocity/linear"),_SCS("set_linear_velocity"),_SCS("get_linear_velocity")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"velocity/angular"),_SCS("set_angular_velocity"),_SCS("get_angular_velocity")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"damp_override/linear",PROPERTY_HINT_RANGE,"-1,128,0.01"),_SCS("set_linear_damp"),_SCS("get_linear_damp")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"damp_override/angular",PROPERTY_HINT_RANGE,"-1,128,0.01"),_SCS("set_angular_damp"),_SCS("get_angular_damp")); ADD_SIGNAL( MethodInfo("body_enter_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"local_shape"))); ADD_SIGNAL( MethodInfo("body_exit_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"local_shape"))); @@ -758,6 +806,11 @@ RigidBody2D::RigidBody2D() : PhysicsBody2D(Physics2DServer::BODY_MODE_RIGID) { bounce=0; mass=1; friction=1; + + gravity_scale=1; + linear_damp=-1; + angular_damp=-1; + max_contacts_reported=0; state=NULL; diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index ca7b757497..956999ce31 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -119,6 +119,9 @@ private: real_t bounce; real_t mass; real_t friction; + real_t gravity_scale; + real_t linear_damp; + real_t angular_damp; Vector2 linear_velocity; real_t angular_velocity; @@ -198,6 +201,15 @@ public: void set_bounce(real_t p_bounce); real_t get_bounce() const; + void set_gravity_scale(real_t p_gravity_scale); + real_t get_gravity_scale() const; + + void set_linear_damp(real_t p_linear_damp); + real_t get_linear_damp() const; + + void set_angular_damp(real_t p_angular_damp); + real_t get_angular_damp() const; + void set_linear_velocity(const Vector2& p_velocity); Vector2 get_linear_velocity() const; diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 957e63e3ce..3cd0dd3d16 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -1,5 +1,6 @@ #include "graph_edit.h" - +#include "os/input.h" +#include "os/keyboard.h" bool GraphEditFilter::has_point(const Point2& p_point) const { return ge->_filter_input(p_point); @@ -53,7 +54,7 @@ void GraphEdit::disconnect_node(const StringName& p_from, int p_from_port,const } } -void GraphEdit::get_connection_list(List<Connection> *r_connections) { +void GraphEdit::get_connection_list(List<Connection> *r_connections) const { *r_connections=connections; } @@ -88,7 +89,6 @@ void GraphEdit::_update_scroll() { updating=true; Rect2 screen; - screen.size=get_size(); for(int i=0;i<get_child_count();i++) { GraphNode *gn=get_child(i)->cast_to<GraphNode>(); @@ -101,6 +101,10 @@ void GraphEdit::_update_scroll() { screen = screen.merge(r); } + screen.pos-=get_size(); + screen.size+=get_size()*2.0; + + h_scroll->set_min(screen.pos.x); h_scroll->set_max(screen.pos.x+screen.size.x); h_scroll->set_page(get_size().x); @@ -265,6 +269,37 @@ void GraphEdit::_top_layer_input(const InputEvent& p_ev) { Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos(); if (pos.distance_to(mpos)<grab_r) { + + if (right_disconnects) { + //check disconnect + for (List<Connection>::Element*E=connections.front();E;E=E->next()) { + + if (E->get().to==gn->get_name() && E->get().to_port==j) { + + Node*fr = get_node(String(E->get().from)); + if (fr && fr->cast_to<GraphNode>()) { + + connecting_from=E->get().from; + connecting_index=E->get().from_port; + connecting_out=true; + connecting_type=fr->cast_to<GraphNode>()->get_connection_output_type(E->get().from_port); + connecting_color=fr->cast_to<GraphNode>()->get_connection_output_color(E->get().from_port); + connecting_target=false; + connecting_to=pos; + + emit_signal("disconnection_request",E->get().from,E->get().from_port,E->get().to,E->get().to_port); + fr = get_node(String(connecting_from)); //maybe it was erased + if (fr && fr->cast_to<GraphNode>()) { + connecting=true; + } + return; + } + + } + } + } + + connecting=true; connecting_from=gn->get_name(); connecting_index=j; @@ -461,7 +496,7 @@ void GraphEdit::_top_layer_draw() { void GraphEdit::_input_event(const InputEvent& p_ev) { - if (p_ev.type==InputEvent::MOUSE_MOTION && p_ev.mouse_motion.button_mask&BUTTON_MASK_MIDDLE) { + if (p_ev.type==InputEvent::MOUSE_MOTION && (p_ev.mouse_motion.button_mask&BUTTON_MASK_MIDDLE || (p_ev.mouse_motion.button_mask&BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) { h_scroll->set_val( h_scroll->get_val() - p_ev.mouse_motion.relative_x ); v_scroll->set_val( v_scroll->get_val() - p_ev.mouse_motion.relative_y ); } @@ -474,11 +509,41 @@ void GraphEdit::clear_connections() { } +void GraphEdit::set_right_disconnects(bool p_enable) { + + right_disconnects=p_enable; +} + +bool GraphEdit::is_right_disconnects_enabled() const{ + + return right_disconnects; +} + +Array GraphEdit::_get_connection_list() const { + + List<Connection> conns; + get_connection_list(&conns); + Array arr; + for(List<Connection>::Element *E=conns.front();E;E=E->next()) { + Dictionary d; + d["from"]=E->get().from; + d["from_port"]=E->get().from_port; + d["to"]=E->get().to; + d["to_port"]=E->get().to_port; + arr.push_back(d); + } + return arr; +} void GraphEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("connect_node:Error","from","from_port","to","to_port"),&GraphEdit::connect_node); ObjectTypeDB::bind_method(_MD("is_node_connected","from","from_port","to","to_port"),&GraphEdit::is_node_connected); ObjectTypeDB::bind_method(_MD("disconnect_node","from","from_port","to","to_port"),&GraphEdit::disconnect_node); + ObjectTypeDB::bind_method(_MD("get_connection_list"),&GraphEdit::_get_connection_list); + + ObjectTypeDB::bind_method(_MD("set_right_disconnects","enable"),&GraphEdit::set_right_disconnects); + ObjectTypeDB::bind_method(_MD("is_right_disconnects_enabled"),&GraphEdit::is_right_disconnects_enabled); + ObjectTypeDB::bind_method(_MD("_graph_node_moved"),&GraphEdit::_graph_node_moved); ObjectTypeDB::bind_method(_MD("_graph_node_raised"),&GraphEdit::_graph_node_raised); @@ -489,9 +554,12 @@ void GraphEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&GraphEdit::_input_event); ADD_SIGNAL(MethodInfo("connection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); + ADD_SIGNAL(MethodInfo("disconnection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot"))); } + + GraphEdit::GraphEdit() { top_layer=NULL; top_layer=memnew(GraphEditFilter(this)); @@ -511,6 +579,7 @@ GraphEdit::GraphEdit() { top_layer->add_child(v_scroll); updating=false; connecting=false; + right_disconnects=false; h_scroll->connect("value_changed", this,"_scroll_moved"); v_scroll->connect("value_changed", this,"_scroll_moved"); diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index f8a2f3fee7..0a9da73ab6 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -51,6 +51,7 @@ private: + bool right_disconnects; bool updating; List<Connection> connections; @@ -68,6 +69,8 @@ private: void _top_layer_draw(); void _update_scroll_offset(); + Array _get_connection_list() const; + friend class GraphEditFilter; bool _filter_input(const Point2& p_point); protected: @@ -84,7 +87,11 @@ public: void disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port); void clear_connections(); - void get_connection_list(List<Connection> *r_connections); + GraphEditFilter *get_top_layer() const { return top_layer; } + void get_connection_list(List<Connection> *r_connections) const; + + void set_right_disconnects(bool p_enable); + bool is_right_disconnects_enabled() const; GraphEdit(); diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 50ee9abcf8..444b37855f 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -1,4 +1,5 @@ #include "graph_node.h" +#include "method_bind_ext.inc" bool GraphNode::_set(const StringName& p_name, const Variant& p_value) { @@ -38,9 +39,8 @@ bool GraphNode::_set(const StringName& p_name, const Variant& p_value) { bool GraphNode::_get(const StringName& p_name,Variant &r_ret) const{ - print_line("get "+p_name.operator String()); - if (!p_name.operator String().begins_with("slot/")) { - print_line("no begins"); + + if (!p_name.operator String().begins_with("slot/")) { return false; } @@ -68,7 +68,6 @@ bool GraphNode::_get(const StringName& p_name,Variant &r_ret) const{ else return false; - print_line("ask for: "+p_name.operator String()+" get: "+String(r_ret)); return true; } void GraphNode::_get_property_list( List<PropertyInfo> *p_list) const{ @@ -540,6 +539,30 @@ void GraphNode::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_title"),&GraphNode::get_title); ObjectTypeDB::bind_method(_MD("_input_event"),&GraphNode::_input_event); + ObjectTypeDB::bind_method(_MD("set_slot","idx","enable_left","type_left","color_left","enable_right","type_right","color_right"),&GraphNode::set_slot); + ObjectTypeDB::bind_method(_MD("clear_slot","idx"),&GraphNode::clear_slot); + ObjectTypeDB::bind_method(_MD("clear_all_slots","idx"),&GraphNode::clear_all_slots); + ObjectTypeDB::bind_method(_MD("is_slot_enabled_left","idx"),&GraphNode::is_slot_enabled_left); + ObjectTypeDB::bind_method(_MD("get_slot_type_left","idx"),&GraphNode::get_slot_type_left); + ObjectTypeDB::bind_method(_MD("get_slot_color_left","idx"),&GraphNode::get_slot_color_left); + ObjectTypeDB::bind_method(_MD("is_slot_enabled_right","idx"),&GraphNode::is_slot_enabled_right); + ObjectTypeDB::bind_method(_MD("get_slot_type_right","idx"),&GraphNode::get_slot_type_right); + ObjectTypeDB::bind_method(_MD("get_slot_color_right","idx"),&GraphNode::get_slot_color_right); + + ObjectTypeDB::bind_method(_MD("set_offset","offset"),&GraphNode::set_offset); + ObjectTypeDB::bind_method(_MD("get_offset"),&GraphNode::get_offset); + + ObjectTypeDB::bind_method(_MD("get_connection_output_count"),&GraphNode::get_connection_output_count); + ObjectTypeDB::bind_method(_MD("get_connection_input_count"),&GraphNode::get_connection_input_count); + + ObjectTypeDB::bind_method(_MD("get_connection_output_pos","idx"),&GraphNode::get_connection_output_pos); + ObjectTypeDB::bind_method(_MD("get_connection_output_type","idx"),&GraphNode::get_connection_output_type); + ObjectTypeDB::bind_method(_MD("get_connection_output_color","idx"),&GraphNode::get_connection_output_color); + ObjectTypeDB::bind_method(_MD("get_connection_input_pos","idx"),&GraphNode::get_connection_input_pos); + ObjectTypeDB::bind_method(_MD("get_connection_input_type","idx"),&GraphNode::get_connection_input_type); + ObjectTypeDB::bind_method(_MD("get_connection_input_color","idx"),&GraphNode::get_connection_input_color); + + ObjectTypeDB::bind_method(_MD("set_show_close_button","show"),&GraphNode::set_show_close_button); ObjectTypeDB::bind_method(_MD("is_close_button_visible"),&GraphNode::is_close_button_visible); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 50a440e91c..d589b93049 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1293,106 +1293,108 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { break; bool valid=true; - if (k.mod.command || k.mod.alt || k.mod.meta) + if (k.mod.command || k.mod.meta) valid=false; if (valid) { - if (k.scancode==KEY_UP) { - - if (completion_index>0) { - completion_index--; + if (!k.mod.alt) { + if (k.scancode==KEY_UP) { + + if (completion_index>0) { + completion_index--; + completion_current=completion_options[completion_index]; + update(); + } + accept_event(); + return; + } + + + if (k.scancode==KEY_DOWN) { + + if (completion_index<completion_options.size()-1) { + completion_index++; + completion_current=completion_options[completion_index]; + update(); + } + accept_event(); + return; + } + + if (k.scancode==KEY_PAGEUP) { + + completion_index-=get_constant("completion_lines"); + if (completion_index<0) + completion_index=0; completion_current=completion_options[completion_index]; update(); + accept_event(); + return; } - accept_event(); - return; - } - - - if (k.scancode==KEY_DOWN) { - - if (completion_index<completion_options.size()-1) { - completion_index++; + + + if (k.scancode==KEY_PAGEDOWN) { + + completion_index+=get_constant("completion_lines"); + if (completion_index>=completion_options.size()) + completion_index=completion_options.size()-1; completion_current=completion_options[completion_index]; update(); + accept_event(); + return; } - accept_event(); - return; - } - - if (k.scancode==KEY_PAGEUP) { - - completion_index-=get_constant("completion_lines"); - if (completion_index<0) + + if (k.scancode==KEY_HOME) { + completion_index=0; - completion_current=completion_options[completion_index]; - update(); - accept_event(); - return; - } - - - if (k.scancode==KEY_PAGEDOWN) { - - completion_index+=get_constant("completion_lines"); - if (completion_index>=completion_options.size()) + completion_current=completion_options[completion_index]; + update(); + accept_event(); + return; + } + + if (k.scancode==KEY_END) { + completion_index=completion_options.size()-1; - completion_current=completion_options[completion_index]; - update(); - accept_event(); - return; - } - - if (k.scancode==KEY_HOME) { - - completion_index=0; - completion_current=completion_options[completion_index]; - update(); - accept_event(); - return; - } - - if (k.scancode==KEY_END) { - - completion_index=completion_options.size()-1; - completion_current=completion_options[completion_index]; - update(); - accept_event(); - return; - } - - - if (k.scancode==KEY_DOWN) { - - if (completion_index<completion_options.size()-1) { - completion_index++; completion_current=completion_options[completion_index]; update(); + accept_event(); + return; + } + + + if (k.scancode==KEY_DOWN) { + + if (completion_index<completion_options.size()-1) { + completion_index++; + completion_current=completion_options[completion_index]; + update(); + } + accept_event(); + return; + } + + if (k.scancode==KEY_RETURN || k.scancode==KEY_TAB) { + + _confirm_completion(); + accept_event(); + return; + } + + if (k.scancode==KEY_BACKSPACE) { + + backspace_at_cursor(); + _update_completion_candidates(); + accept_event(); + return; + } + + + if (k.scancode==KEY_SHIFT) { + accept_event(); + return; } - accept_event(); - return; - } - - if (k.scancode==KEY_RETURN || k.scancode==KEY_TAB) { - - _confirm_completion(); - accept_event(); - return; - } - - if (k.scancode==KEY_BACKSPACE) { - - backspace_at_cursor(); - _update_completion_candidates(); - accept_event(); - return; - } - - - if (k.scancode==KEY_SHIFT) { - accept_event(); - return; } if (k.unicode>32) { @@ -1972,7 +1974,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } break; case KEY_U:{ - if (!k.mod.command || k.mod.shift || k.mod.alt) { + if (!k.mod.command || k.mod.shift) { scancode_handled=false; break; } @@ -2018,7 +2020,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } } */ - if (!scancode_handled && !k.mod.command && !k.mod.alt) { //for german kbds + if (!scancode_handled && !k.mod.command) { //for german kbds if (k.unicode>=32) { diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index ae2c07ff56..6c27ffc6d9 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -134,7 +134,7 @@ Vector2 Curve2D::interpolate(int p_index, float p_offset) const { Vector2 Curve2D::interpolatef(real_t p_findex) const { - if (p_findex>0) + if (p_findex<0) p_findex=0; else if (p_findex>=points.size()) p_findex=points.size(); @@ -485,7 +485,7 @@ Vector2 Curve2D::interpolate(int p_index, float p_offset) const { Vector2 Curve2D::interpolatef(real_t p_findex) const { - if (p_findex>0) + if (p_findex<0) p_findex=0; else if (p_findex>=points.size()) p_findex=points.size(); @@ -956,7 +956,7 @@ Vector3 Curve3D::interpolate(int p_index, float p_offset) const { Vector3 Curve3D::interpolatef(real_t p_findex) const { - if (p_findex>0) + if (p_findex<0) p_findex=0; else if (p_findex>=points.size()) p_findex=points.size(); diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp index e47b2432f2..f3e625917a 100644 --- a/scene/resources/shader.cpp +++ b/scene/resources/shader.cpp @@ -144,10 +144,13 @@ void Shader::_set_code(const Dictionary& p_string) { void Shader::set_default_texture_param(const StringName& p_param,const Ref<Texture>& p_texture) { - if (p_texture.is_valid()) + if (p_texture.is_valid()) { default_textures[p_param]=p_texture; - else + VS::get_singleton()->shader_set_default_texture_param(shader,p_param,p_texture->get_rid()); + } else { default_textures.erase(p_param); + VS::get_singleton()->shader_set_default_texture_param(shader,p_param,RID()); + } } Ref<Texture> Shader::get_default_texture_param(const StringName& p_param) const{ diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index a06a70be9f..8b2f318ec0 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -27,8 +27,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "shader_graph.h" - - +#include "scene/scene_string_names.h" +//todo +//-RGB ops +//-mostrar error de conexion Array ShaderGraph::_get_node_list(ShaderType p_type) const { @@ -57,6 +59,91 @@ Array ShaderGraph::_get_connections(ShaderType p_type) const { return arr; } +void ShaderGraph::_set_data(const Dictionary &p_data) { + + Dictionary d=p_data; + ERR_FAIL_COND(!d.has("shaders")); + Array sh=d["shaders"]; + ERR_FAIL_COND(sh.size()!=3); + + for(int t=0;t<3;t++) { + Array data=sh[t]; + ERR_FAIL_COND((data.size()%6)!=0); + shader[t].node_map.clear(); + for(int i=0;i<data.size();i+=6) { + + Node n; + n.id=data[i+0]; + n.type=NodeType(int(data[i+1])); + n.pos=data[i+2]; + n.param1=data[i+3]; + n.param2=data[i+4]; + + Array conns=data[i+5]; + ERR_FAIL_COND((conns.size()%3)!=0); + + for(int j=0;j<conns.size();j+=3) { + + SourceSlot ss; + int ls=conns[j+0]; + ss.id=conns[j+1]; + ss.slot=conns[j+2]; + n.connections[ls]=ss; + } + shader[t].node_map[n.id]=n; + + } + } + + _update_shader(); + +} + +Dictionary ShaderGraph::_get_data() const { + + Array sh; + for(int i=0;i<3;i++) { + Array data; + int ec = shader[i].node_map.size(); + data.resize(ec*6); + int idx=0; + for (Map<int,Node>::Element*E=shader[i].node_map.front();E;E=E->next()) { + + data[idx+0]=E->key(); + data[idx+1]=E->get().type; + data[idx+2]=E->get().pos; + data[idx+3]=E->get().param1; + data[idx+4]=E->get().param2; + + Array conns; + conns.resize(E->get().connections.size()*3); + int idx2=0; + for(Map<int,SourceSlot>::Element*F=E->get().connections.front();F;F=F->next()) { + + conns[idx2+0]=F->key(); + conns[idx2+1]=F->get().id; + conns[idx2+2]=F->get().slot; + idx2+=3; + } + data[idx+5]=conns; + idx+=6; + } + sh.push_back(data); + } + + Dictionary data; + data["shaders"]=sh; + return data; +} + + + +ShaderGraph::GraphError ShaderGraph::get_graph_error(ShaderType p_type) const { + + ERR_FAIL_INDEX_V(p_type,3,GRAPH_OK); + return shader[p_type].error; +} + void ShaderGraph::_bind_methods() { ObjectTypeDB::bind_method(_MD("_update_shader"),&ShaderGraph::_update_shader); @@ -100,9 +187,9 @@ void ShaderGraph::_bind_methods() { ObjectTypeDB::bind_method(_MD("vec_scalar_op_node_set_op","shader_type","id","op"),&ShaderGraph::vec_scalar_op_node_set_op); ObjectTypeDB::bind_method(_MD("vec_scalar_op_node_get_op","shader_type","id"),&ShaderGraph::vec_scalar_op_node_get_op); - ObjectTypeDB::bind_method(_MD("rgb_op_node_set_op","shader_type","id","op","c"),&ShaderGraph::rgb_op_node_set_op); + ObjectTypeDB::bind_method(_MD("rgb_op_node_set_op","shader_type","id","op"),&ShaderGraph::rgb_op_node_set_op); ObjectTypeDB::bind_method(_MD("rgb_op_node_get_op","shader_type","id"),&ShaderGraph::rgb_op_node_get_op); - ObjectTypeDB::bind_method(_MD("rgb_op_node_get_c","shader_type","id"),&ShaderGraph::rgb_op_node_get_c); + ObjectTypeDB::bind_method(_MD("xform_vec_mult_node_set_no_translation","shader_type","id","disable"),&ShaderGraph::xform_vec_mult_node_set_no_translation); ObjectTypeDB::bind_method(_MD("xform_vec_mult_node_get_no_translation","shader_type","id"),&ShaderGraph::xform_vec_mult_node_get_no_translation); @@ -147,6 +234,11 @@ void ShaderGraph::_bind_methods() { ObjectTypeDB::bind_method(_MD("node_set_state","shader_type","id","state"),&ShaderGraph::node_set_state); ObjectTypeDB::bind_method(_MD("node_get_state:var","shader_type","id"),&ShaderGraph::node_get_state); + ObjectTypeDB::bind_method(_MD("_set_data"),&ShaderGraph::_set_data); + ObjectTypeDB::bind_method(_MD("_get_data"),&ShaderGraph::_get_data); + + ADD_PROPERTY( PropertyInfo(Variant::DICTIONARY,"_data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_data"),_SCS("_get_data")); + //void get_connections(ShaderType p_which,List<Connection> *p_connections) const; @@ -271,6 +363,8 @@ void ShaderGraph::_bind_methods() { BIND_CONSTANT( VEC_FUNC_HSV2RGB ); BIND_CONSTANT( VEC_MAX_FUNC ); + ADD_SIGNAL(MethodInfo("updated")); + #if 0 ObjectTypeDB::bind_method(_MD("node_add"),&ShaderGraph::node_add ); @@ -347,7 +441,7 @@ void ShaderGraph::_bind_methods() { } -String ShaderGraph::_find_unique_name(ShaderType p_which, const String& p_base) { +String ShaderGraph::_find_unique_name(const String& p_base) { @@ -358,15 +452,19 @@ String ShaderGraph::_find_unique_name(ShaderType p_which, const String& p_base) tocmp+="_"+itos(idx); } bool valid=true; - for (Map<int,Node>::Element *E=shader[p_which].node_map.front();E;E=E->next()) { - if (E->get().type!=NODE_SCALAR_INPUT && E->get().type!=NODE_VEC_INPUT && E->get().type==NODE_RGB_INPUT && E->get().type==NODE_XFORM_INPUT && E->get().type==NODE_TEXTURE_INPUT && E->get().type==NODE_CUBEMAP_INPUT) - continue; - String name = E->get().param1; - if (name==tocmp) { - valid=false; + for(int i=0;i<3;i++) { + if (!valid) break; - } + for (Map<int,Node>::Element *E=shader[i].node_map.front();E;E=E->next()) { + if (E->get().type!=NODE_SCALAR_INPUT && E->get().type!=NODE_VEC_INPUT && E->get().type==NODE_RGB_INPUT && E->get().type==NODE_XFORM_INPUT && E->get().type==NODE_TEXTURE_INPUT && E->get().type==NODE_CUBEMAP_INPUT) + continue; + String name = E->get().param1; + if (name==tocmp) { + valid=false; + break; + } + } } if (!valid) { @@ -424,12 +522,12 @@ void ShaderGraph::node_add(ShaderType p_type, NodeType p_node_type,int p_id) { case NODE_XFORM_TO_VEC: {} break; // 3 scalar input: {} break; 1 vec3 output case NODE_SCALAR_INTERP: {} break; // scalar interpolation (with optional curve) case NODE_VEC_INTERP: {} break; // vec3 interpolation (with optional curve) - case NODE_SCALAR_INPUT: {node.param1=_find_unique_name(p_type,"Scalar"); node.param2=0;} break; // scalar uniform (assignable in material) - case NODE_VEC_INPUT: {node.param1=_find_unique_name(p_type,"Vec3");node.param2=Vector3();} break; // vec3 uniform (assignable in material) - case NODE_RGB_INPUT: {node.param1=_find_unique_name(p_type,"Color");node.param2=Color();} break; // color uniform (assignable in material) - case NODE_XFORM_INPUT: {node.param1=_find_unique_name(p_type,"XForm"); node.param2=Transform();} break; // mat4 uniform (assignable in material) - case NODE_TEXTURE_INPUT: {node.param1=_find_unique_name(p_type,"Tex"); } break; // texture input (assignable in material) - case NODE_CUBEMAP_INPUT: {node.param1=_find_unique_name(p_type,"Cube"); } break; // cubemap input (assignable in material) + case NODE_SCALAR_INPUT: {node.param1=_find_unique_name("Scalar"); node.param2=0;} break; // scalar uniform (assignable in material) + case NODE_VEC_INPUT: {node.param1=_find_unique_name("Vec3");node.param2=Vector3();} break; // vec3 uniform (assignable in material) + case NODE_RGB_INPUT: {node.param1=_find_unique_name("Color");node.param2=Color();} break; // color uniform (assignable in material) + case NODE_XFORM_INPUT: {node.param1=_find_unique_name("XForm"); node.param2=Transform();} break; // mat4 uniform (assignable in material) + case NODE_TEXTURE_INPUT: {node.param1=_find_unique_name("Tex"); } break; // texture input (assignable in material) + case NODE_CUBEMAP_INPUT: {node.param1=_find_unique_name("Cube"); } break; // cubemap input (assignable in material) case NODE_OUTPUT: {} break; // output (shader type dependent) case NODE_COMMENT: {} break; // comment case NODE_TYPE_MAX: {}; @@ -479,7 +577,7 @@ void ShaderGraph::node_remove(ShaderType p_type,int p_id) { } shader[p_type].node_map.erase(p_id); - print_line("erased node, amount left: "+itos(shader[p_type].node_map.size())); + _request_update(); } @@ -545,7 +643,6 @@ bool ShaderGraph::is_node_connected(ShaderType p_type,int p_src_id,int p_src_slo void ShaderGraph::disconnect_node(ShaderType p_type,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) { ERR_FAIL_INDEX(p_type,3); - print_line("** dsisconnect"); SourceSlot ts; ts.id=p_src_id; ts.slot=p_src_slot; @@ -782,14 +879,14 @@ ShaderGraph::VecScalarOp ShaderGraph::vec_scalar_op_node_get_op(ShaderType p_typ } -void ShaderGraph::rgb_op_node_set_op(ShaderType p_type,float p_id,RGBOp p_op,float p_c){ +void ShaderGraph::rgb_op_node_set_op(ShaderType p_type,float p_id,RGBOp p_op){ ERR_FAIL_INDEX(p_type,3); ERR_FAIL_COND(!shader[p_type].node_map.has(p_id)); Node& n = shader[p_type].node_map[p_id]; ERR_FAIL_COND(n.type!=NODE_RGB_OP); n.param1=p_op; - n.param2=p_c; + _request_update(); } @@ -803,15 +900,7 @@ ShaderGraph::RGBOp ShaderGraph::rgb_op_node_get_op(ShaderType p_type,float p_id) return RGBOp(op); } -float ShaderGraph::rgb_op_node_get_c(ShaderType p_type,float p_id) const{ - - ERR_FAIL_INDEX_V(p_type,3,0); - ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),0); - const Node& n = shader[p_type].node_map[p_id]; - ERR_FAIL_COND_V(n.type!=NODE_RGB_OP,0); - return n.param2; -} void ShaderGraph::xform_vec_mult_node_set_no_translation(ShaderType p_type,int p_id,bool p_no_translation){ @@ -839,7 +928,9 @@ void ShaderGraph::scalar_func_node_set_function(ShaderType p_type,int p_id,Scala ERR_FAIL_COND(!shader[p_type].node_map.has(p_id)); Node& n = shader[p_type].node_map[p_id]; ERR_FAIL_COND(n.type!=NODE_SCALAR_FUNC); - n.param1=p_func; + int func = p_func; + ERR_FAIL_INDEX(func,SCALAR_MAX_FUNC); + n.param1=func; _request_update(); } @@ -859,7 +950,9 @@ void ShaderGraph::vec_func_node_set_function(ShaderType p_type,int p_id,VecFunc ERR_FAIL_COND(!shader[p_type].node_map.has(p_id)); Node& n = shader[p_type].node_map[p_id]; ERR_FAIL_COND(n.type!=NODE_VEC_FUNC); - n.param1=p_func; + int func = p_func; + ERR_FAIL_INDEX(func,VEC_MAX_FUNC); + n.param1=func; _request_update(); @@ -881,8 +974,9 @@ void ShaderGraph::input_node_set_name(ShaderType p_type,int p_id,const String& p ERR_FAIL_COND(!p_name.is_valid_identifier()); Node& n = shader[p_type].node_map[p_id]; ERR_FAIL_COND(n.type!=NODE_SCALAR_INPUT && n.type!=NODE_VEC_INPUT && n.type==NODE_RGB_INPUT && n.type==NODE_XFORM_INPUT && n.type==NODE_TEXTURE_INPUT && n.type==NODE_CUBEMAP_INPUT); + n.param1=""; - n.param1=_find_unique_name(p_type,p_name); + n.param1=_find_unique_name(p_name); _request_update(); } @@ -1097,59 +1191,74 @@ ShaderGraph::~ShaderGraph() { const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={ //material vertex in - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Vertex","SRC_VERTEX",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Normal","SRC_NORMAL",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Tangent","SRC_TANGENT",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"BinormalF","SRC_BINORMALF",SLOT_TYPE_SCALAR,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"WorldMatrix","WORLD_MATRIX",SLOT_TYPE_XFORM,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"InvCameraMatrix","INV_CAMERA_MATRIX",SLOT_TYPE_XFORM,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"ProjectionMatrix","PROJECTION_MATRIX",SLOT_TYPE_XFORM,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"ModelviewMatrix","MODELVIEW_MATRIX",SLOT_TYPE_XFORM,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"InstanceID","INSTANCE_ID",SLOT_TYPE_SCALAR,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Time","TIME",SLOT_TYPE_SCALAR,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Vertex","SRC_VERTEX","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Normal","SRC_NORMAL","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Tangent","SRC_TANGENT","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"BinormalF","SRC_BINORMALF","",SLOT_TYPE_SCALAR,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Color","SRC_COLOR","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Alpha","SRC_ALPHA","",SLOT_TYPE_SCALAR,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV","SRC_UV","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV2","SRC_UV2","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"WorldMatrix","WORLD_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"InvCameraMatrix","INV_CAMERA_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"ProjectionMatrix","PROJECTION_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"ModelviewMatrix","MODELVIEW_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"InstanceID","INSTANCE_ID","",SLOT_TYPE_SCALAR,SLOT_IN}, + //material vertex out - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Vertex","VERTEX",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Normal","NORMAL",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Tangent","TANGENT",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Binormal","BINORMAL",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV","UV",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV2","UV2",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Color","COLOR.rgb",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Alpha","COLOR.a",SLOT_TYPE_SCALAR,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Var1","VAR1.rgb",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Var2","VAR2.rgb",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"SpecExp","SPEC_EXP",SLOT_TYPE_SCALAR,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_VERTEX,"PointSize","POINT_SIZE",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Vertex","VERTEX","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Tangent","TANGENT","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Binormal","BINORMAL","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV","UV",".xy",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV2","UV2",".xy",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"SpecExp","SPEC_EXP","",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_VERTEX,"PointSize","POINT_SIZE","",SLOT_TYPE_SCALAR,SLOT_OUT}, //pixel vertex in - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Vertex","VERTEX",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Position","POSITION",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Normal","IN_NORMAL",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Tangent","TANGENT",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Binormal","BINORMAL",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UV","UV",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UV2","UV2",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UVScreen","SCREEN_UV",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"PointCoord","POINT_COORD",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Color","COLOR.rgb",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Alpha","COLOR.a",SLOT_TYPE_SCALAR,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"InvCameraMatrix","INV_CAMERA_MATRIX",SLOT_TYPE_XFORM,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Time","TIME",SLOT_TYPE_SCALAR,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Var1","VAR1.rgb",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Var2","VAR2.rgb",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Vertex","VERTEX","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Position","POSITION.xyz","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Normal","IN_NORMAL","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Tangent","TANGENT","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Binormal","BINORMAL","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UV","vec3(UV,0);","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UV2","UV2","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UVScreen","SCREEN_UV","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"PointCoord","POINT_COORD","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"InvCameraMatrix","INV_CAMERA_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_IN}, //pixel vertex out - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Diffuse","DIFFUSE_OUT",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"DiffuseAlpha","ALPHA_OUT",SLOT_TYPE_SCALAR,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Specular","SPECULAR",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"SpecularExp","SPECULAR",SLOT_TYPE_SCALAR,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Emission","EMISSION",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Glow","GLOW",SLOT_TYPE_SCALAR,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"ShadeParam","SHADE_PARAM",SLOT_TYPE_SCALAR,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Normal","NORMAL",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"NormalMap","NORMALMAP",SLOT_TYPE_VEC,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"NormalMapDepth","NORMALMAP_DEPTH",SLOT_TYPE_SCALAR,SLOT_OUT}, - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Discard","DISCARD",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Diffuse","DIFFUSE_OUT","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"DiffuseAlpha","ALPHA_OUT","",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Specular","SPECULAR","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"SpecularExp","SPECULAR","",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Emission","EMISSION","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Glow","GLOW","",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"ShadeParam","SHADE_PARAM","",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"NormalMap","NORMALMAP","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"NormalMapDepth","NORMALMAP_DEPTH","",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Discard","DISCARD",">0.5",SLOT_TYPE_SCALAR,SLOT_OUT}, + //light in + {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_LIGHT,"LightDir","LIGHT_DIR","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_LIGHT,"LightDiffuse","LIGHT_DIFFUSE","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_LIGHT,"LightSpecular","LIGHT_SPECULAR","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_LIGHT,"EyeVec","EYE_VEC","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Diffuse","DIFFUSE","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Specular","SPECULAR","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_LIGHT,"SpecExp","SPECULAR_EXP","",SLOT_TYPE_SCALAR,SLOT_IN}, + {MODE_MATERIAL,SHADER_TYPE_LIGHT,"ShadeParam","SHADE_PARAM","",SLOT_TYPE_SCALAR,SLOT_IN}, + //light out + {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Light","LIGHT","",SLOT_TYPE_VEC,SLOT_OUT}, //end - {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,NULL,NULL,SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,NULL,NULL,NULL,SLOT_TYPE_SCALAR,SLOT_OUT}, }; @@ -1174,17 +1283,17 @@ const ShaderGraph::NodeSlotInfo ShaderGraph::node_slot_info[]= { {NODE_SCALAR_CONST,{SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, //scalar constant {NODE_VEC_CONST,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, //vec3 constant - {NODE_RGB_CONST,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, //rgb constant (shows a color picker instead) + {NODE_RGB_CONST,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, //rgb constant (shows a color picker instead) {NODE_XFORM_CONST,{SLOT_MAX},{SLOT_TYPE_XFORM,SLOT_MAX}}, // 4x4 matrix constant {NODE_TIME,{SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // time in seconds {NODE_SCREEN_TEX,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // screen texture sampler (takes UV) (only usable in fragment shader) {NODE_SCALAR_OP,{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc) {NODE_VEC_OP,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // scalar vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc) {NODE_VEC_SCALAR_OP,{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc) - {NODE_RGB_OP,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_TYPE_SCALAR},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc) + {NODE_RGB_OP,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc) {NODE_XFORM_MULT,{SLOT_TYPE_XFORM,SLOT_TYPE_XFORM,SLOT_MAX},{SLOT_TYPE_XFORM,SLOT_MAX}}, // mat4 x mat4 {NODE_XFORM_VEC_MULT,{SLOT_TYPE_XFORM,SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // mat4 x vec3 mult (with no-translation option) - {NODE_XFORM_VEC_INV_MULT,{SLOT_TYPE_XFORM,SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // mat4 x vec3 inverse mult (with no-translation option) + {NODE_XFORM_VEC_INV_MULT,{SLOT_TYPE_VEC,SLOT_TYPE_XFORM,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // mat4 x vec3 inverse mult (with no-translation option) {NODE_SCALAR_FUNC,{SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar function (sin,{SLOT_MAX},{SLOT_MAX}}, cos,{SLOT_MAX},{SLOT_MAX}}, etc) {NODE_VEC_FUNC,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vector function (normalize,{SLOT_MAX},{SLOT_MAX}}, negate,{SLOT_MAX},{SLOT_MAX}}, reciprocal,{SLOT_MAX},{SLOT_MAX}}, rgb2hsv,{SLOT_MAX},{SLOT_MAX}}, hsv2rgb,{SLOT_MAX},{SLOT_MAX}}, etc,{SLOT_MAX},{SLOT_MAX}}, etc) {NODE_VEC_LEN,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // vec3 length @@ -1315,6 +1424,7 @@ ShaderGraph::SlotType ShaderGraph::get_node_input_slot_type(Mode p_mode, ShaderT if (nsi->type==p_type) { for(int i=0;i<NodeSlotInfo::MAX_INS;i++) { + if (nsi->ins[i]==SLOT_MAX) break; if (i==p_idx) @@ -1381,6 +1491,14 @@ void ShaderGraph::_update_shader() { String code[3]; + List<StringName> names; + get_default_texture_param_list(&names); + + for (List<StringName>::Element *E=names.front();E;E=E->next()) { + set_default_texture_param(E->get(),Ref<Texture>()); + } + + for(int i=0;i<3;i++) { int idx=0; @@ -1437,11 +1555,13 @@ void ShaderGraph::_update_shader() { bool failed=false; if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL) { - code[i]+="vec3 DIFFUSE_OUT=vec3(0,0,0);"; - code[i]+="float ALPHA_OUT=0;"; + code[i]+="vec3 DIFFUSE_OUT=vec3(0,0,0);\n"; + code[i]+="float ALPHA_OUT=0;\n"; } + Map<String,String> inputs_xlate; + Map<String,String> input_names_xlate; Set<String> inputs_used; for(int j=0;j<order.size();j++) { @@ -1458,6 +1578,7 @@ void ShaderGraph::_update_shader() { String vname=("nd"+itos(n->id)+"sl"+itos(idx)); inputs_xlate[vname]=String(typestr[iop->slot_type])+" "+vname+"="+iop->variable+";\n"; + input_names_xlate[vname]=iop->variable; idx++; } iop++; @@ -1476,7 +1597,7 @@ void ShaderGraph::_update_shader() { String iname=("nd"+itos(n->connections[idx].id)+"sl"+itos(n->connections[idx].slot)); if (node_get_type(ShaderType(i),n->connections[idx].id)==NODE_INPUT) inputs_used.insert(iname); - code[i]+=String(iop->variable)+"="+iname+";\n"; + code[i]+=String(iop->variable)+"="+iname+String(iop->postfix)+";\n"; if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL && String(iop->name)=="DiffuseAlpha") use_alpha=true; } @@ -1488,8 +1609,7 @@ void ShaderGraph::_update_shader() { if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL) { if (use_alpha) { - code[i]+="DIFFUSE_ALPHA.rgb=DIFFUSE_OUT;\n"; - code[i]+="DIFFUSE_ALPHA.a=ALPHA_OUT;\n"; + code[i]+="DIFFUSE_ALPHA=vec4(DIFFUSE_OUT,ALPHA_OUT);\n"; } else { code[i]+="DIFFUSE=DIFFUSE_OUT;\n"; } @@ -1506,13 +1626,19 @@ void ShaderGraph::_update_shader() { } String iname="nd"+itos(n->connections[k].id)+"sl"+itos(n->connections[k].slot); inputs.push_back(iname); - if (node_get_type(ShaderType(i),n->connections[k].id)==NODE_INPUT) + if (node_get_type(ShaderType(i),n->connections[k].id)==NODE_INPUT) { inputs_used.insert(iname); + } } if (failed) break; + + if (n->type==NODE_TEXTURE_INPUT || n->type==NODE_CUBEMAP_INPUT) { + + set_default_texture_param(n->param1,n->param2); + } _add_node_code(ShaderType(i),n,inputs,code[i]); } @@ -1521,13 +1647,33 @@ void ShaderGraph::_update_shader() { if (failed) continue; + for(Set<String>::Element *E=inputs_used.front();E;E=E->next()) { ERR_CONTINUE( !inputs_xlate.has(E->get())); code[i]=inputs_xlate[E->get()]+code[i]; + String name=input_names_xlate[E->get()]; + + if (i==SHADER_TYPE_VERTEX && get_mode()==MODE_MATERIAL) { + if (name==("SRC_COLOR")) + code[i]="vec3 SRC_COLOR=COLOR.rgb;\n"+code[i]; + if (name==("SRC_ALPHA")) + code[i]="float SRC_ALPHA=COLOR.a;\n"+code[i]; + if (name==("SRC_UV")) + code[i]="vec3 SRC_UV=vec3(UV,0);\n"+code[i]; + if (name==("SRC_UV2")) + code[i]="float SRC_UV2=vec3(UV2,0);\n"+code[i]; + } else if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL) { + if (name==("IN_NORMAL")) + code[i]="vec3 IN_NORMAL=NORMAL;\n"+code[i]; + } + } + + + shader[i].error=GRAPH_OK; - print_line("ShADER: "+code[i]); + } bool all_ok=true; @@ -1540,8 +1686,9 @@ void ShaderGraph::_update_shader() { set_code(code[0],code[1],code[2]); } //do shader here - print_line("UPDATING SHADER"); + _pending_update_shader=false; + emit_signal(SceneStringNames::get_singleton()->updated); } void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<String>& p_inputs,String& code) { @@ -1549,6 +1696,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str const char *typestr[4]={"float","vec3","mat4","texture"}; #define OUTNAME(id,slot) (String(typestr[get_node_output_slot_type(get_mode(),p_type,p_node->type,slot)])+" "+("nd"+itos(id)+"sl"+itos(slot))) +#define OUTVAR(id,slot) ("nd"+itos(id)+"sl"+itos(slot)) switch(p_node->type) { @@ -1568,6 +1716,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str case NODE_RGB_CONST: { Color col = p_node->param1; code+=OUTNAME(p_node->id,0)+"=vec3("+rtos(col.r)+","+rtos(col.g)+","+rtos(col.b)+");\n"; + code+=OUTNAME(p_node->id,1)+"="+rtos(col.a)+";\n"; }break; case NODE_XFORM_CONST: { @@ -1626,16 +1775,94 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str int op = p_node->param1; String optxt; switch(op) { - case VEC_OP_MUL: optxt = p_inputs[0]+"*"+p_inputs[1]+";"; break; - case VEC_OP_DIV: optxt = p_inputs[0]+"/"+p_inputs[1]+";"; break; - case VEC_OP_POW: optxt = "pow("+p_inputs[0]+","+p_inputs[1]+");"; break; + case VEC_SCALAR_OP_MUL: optxt = p_inputs[0]+"*"+p_inputs[1]+";"; break; + case VEC_SCALAR_OP_DIV: optxt = p_inputs[0]+"/"+p_inputs[1]+";"; break; + case VEC_SCALAR_OP_POW: optxt = "pow("+p_inputs[0]+","+p_inputs[1]+");"; break; } code+=OUTNAME(p_node->id,0)+"="+optxt+"\n"; }break; case NODE_RGB_OP: { + int op = p_node->param1; + static const char*axisn[3]={"x","y","z"}; + switch(op) { + case RGB_OP_SCREEN: { + + code += OUTNAME(p_node->id,0)+"=vec3(1.0)-(vec3(1.0)-"+p_inputs[0]+")*(vec3(1.0)-"+p_inputs[1]+");\n"; + } break; + case RGB_OP_DIFFERENCE: { + + code += OUTNAME(p_node->id,0)+"=abs("+p_inputs[0]+"-"+p_inputs[1]+");\n"; + + } break; + case RGB_OP_DARKEN: { + + code += OUTNAME(p_node->id,0)+"=min("+p_inputs[0]+","+p_inputs[1]+");\n"; + } break; + case RGB_OP_LIGHTEN: { + + code += OUTNAME(p_node->id,0)+"=max("+p_inputs[0]+","+p_inputs[1]+");\n"; + + } break; + case RGB_OP_OVERLAY: { + + code += OUTNAME(p_node->id,0)+";\n"; + for(int i=0;i<3;i++) { + code += "{\n"; + code += "\tfloat base="+p_inputs[0]+"."+axisn[i]+";\n"; + code += "\tfloat blend="+p_inputs[1]+"."+axisn[i]+";\n"; + code += "\tif (base < 0.5) {\n"; + code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = 2.0 * base * blend;\n"; + code += "\t} else {\n"; + code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base);\n"; + code += "\t}\n"; + code += "}\n"; + } + + } break; + case RGB_OP_DODGE: { + + code += OUTNAME(p_node->id,0)+"=("+p_inputs[0]+")/(vec3(1.0)-"+p_inputs[1]+");\n"; + + } break; + case RGB_OP_BURN: { + + code += OUTNAME(p_node->id,0)+"=vec3(1.0)-(vec3(1.0)-"+p_inputs[0]+")/("+p_inputs[1]+");\n"; + } break; + case RGB_OP_SOFT_LIGHT: { + + code += OUTNAME(p_node->id,0)+";\n"; + for(int i=0;i<3;i++) { + code += "{\n"; + code += "\tfloat base="+p_inputs[0]+"."+axisn[i]+";\n"; + code += "\tfloat blend="+p_inputs[1]+"."+axisn[i]+";\n"; + code += "\tif (base < 0.5) {\n"; + code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = (base * (blend+0.5));\n"; + code += "\t} else {\n"; + code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = (1 - (1-base) * (1-(blend-0.5)));\n"; + code += "\t}\n"; + code += "}\n"; + } + } break; + case RGB_OP_HARD_LIGHT: { + + code += OUTNAME(p_node->id,0)+";\n"; + for(int i=0;i<3;i++) { + code += "{\n"; + code += "\tfloat base="+p_inputs[0]+"."+axisn[i]+";\n"; + code += "\tfloat blend="+p_inputs[1]+"."+axisn[i]+";\n"; + code += "\tif (base < 0.5) {\n"; + code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = (base * (2*blend));\n"; + code += "\t} else {\n"; + code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = (1 - (1-base) * (1-2*(blend-0.5)));\n"; + code += "\t}\n"; + code += "}\n"; + } + + } break; + } }break; case NODE_XFORM_MULT: { @@ -1646,26 +1873,85 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str bool no_translation = p_node->param1; if (no_translation) { - code += OUTNAME(p_node->id,0)+"="+p_inputs[0]+"*vec4("+p_inputs[1]+",0);\n"; + code += OUTNAME(p_node->id,0)+"=("+p_inputs[0]+"*vec4("+p_inputs[1]+",0)).xyz;\n"; } else { - code += OUTNAME(p_node->id,0)+"="+p_inputs[0]+"*vec4("+p_inputs[1]+",1);\n"; + code += OUTNAME(p_node->id,0)+"=("+p_inputs[0]+"*vec4("+p_inputs[1]+",1)).xyz;\n"; } }break; case NODE_XFORM_VEC_INV_MULT: { bool no_translation = p_node->param1; if (no_translation) { - code += OUTNAME(p_node->id,0)+"="+p_inputs[1]+"*vec4("+p_inputs[0]+",0);\n"; + code += OUTNAME(p_node->id,0)+"=("+p_inputs[1]+"*vec4("+p_inputs[0]+",0)).xyz;\n"; } else { - code += OUTNAME(p_node->id,0)+"="+p_inputs[1]+"*vec4("+p_inputs[0]+",1);\n"; + code += OUTNAME(p_node->id,0)+"=("+p_inputs[1]+"*vec4("+p_inputs[0]+",1)).xyz;\n"; } }break; case NODE_SCALAR_FUNC: { - - - }break; + static const char*scalar_func_id[SCALAR_MAX_FUNC]={ + "sin($)", + "cos($)", + "tan($)", + "asin($)", + "acos($)", + "atan($)", + "sinh($)", + "cosh($)", + "tanh($)", + "log($)", + "exp($)", + "sqrt($)", + "abs($)", + "sign($)", + "floor($)", + "round($)", + "ceil($)", + "frac($)", + "min(max($,0),1)", + "-($)", + }; + + int func = p_node->param1; + ERR_FAIL_INDEX(func,SCALAR_MAX_FUNC); + code += OUTNAME(p_node->id,0)+"="+String(scalar_func_id[func]).replace("$",p_inputs[0])+";\n"; + + } break; case NODE_VEC_FUNC: { + static const char*vec_func_id[VEC_MAX_FUNC]={ + "normalize($)", + "max(min($,vec3(1,1,1)),vec3(0,0,0))", + "-($)", + "1.0/($)", + "", + "", + }; + + + int func = p_node->param1; + ERR_FAIL_INDEX(func,VEC_MAX_FUNC); + if (func==VEC_FUNC_RGB2HSV) { + code += OUTNAME(p_node->id,0)+";\n"; + code+="{\n"; + code+="\tvec3 c = "+p_inputs[0]+";\n"; + code+="\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n"; + code+="\tvec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n"; + code+="\tvec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n"; + code+="\tfloat d = q.x - min(q.w, q.y);\n"; + code+="\tfloat e = 1.0e-10;\n"; + code+="\t"+OUTVAR(p_node->id,0)+"=vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n"; + code+="}\n"; + } else if (func==VEC_FUNC_HSV2RGB) { + code += OUTNAME(p_node->id,0)+";\n";; + code+="{\n"; + code+="\tvec3 c = "+p_inputs[0]+";\n"; + code+="\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n"; + code+="\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n"; + code+="\t"+OUTVAR(p_node->id,0)+"=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n"; + code+="}\n"; + } else { + code += OUTNAME(p_node->id,0)+"="+String(vec_func_id[func]).replace("$",p_inputs[0])+";\n"; + } }break; case NODE_VEC_LEN: { @@ -1744,7 +2030,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str }break; case NODE_TEXTURE_INPUT: { String name = p_node->param1; - String rname="_read_tex"+itos(p_node->id); + String rname="rt_read_tex"+itos(p_node->id); code +="uniform texture "+name+";"; code +="vec4 "+rname+"=tex("+name+","+p_inputs[0]+".xy);\n"; code += OUTNAME(p_node->id,0)+"="+rname+".rgb;\n"; @@ -1755,7 +2041,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str String name = p_node->param1; code +="uniform cubemap "+name+";"; - String rname="_read_tex"+itos(p_node->id); + String rname="rt_read_tex"+itos(p_node->id); code +="vec4 "+rname+"=texcube("+name+","+p_inputs[0]+".xy);\n"; code += OUTNAME(p_node->id,0)+"="+rname+".rgb;\n"; code += OUTNAME(p_node->id,1)+"="+rname+".a;\n"; diff --git a/scene/resources/shader_graph.h b/scene/resources/shader_graph.h index c73895db8a..55d09b4c38 100644 --- a/scene/resources/shader_graph.h +++ b/scene/resources/shader_graph.h @@ -115,7 +115,7 @@ public: private: - String _find_unique_name(ShaderType p_which, const String& p_base); + String _find_unique_name(const String& p_base); struct SourceSlot { @@ -151,6 +151,7 @@ private: ShaderType shader_type; const char *name; const char *variable; + const char *postfix; SlotType slot_type; SlotDir dir; }; @@ -175,6 +176,9 @@ private: Array _get_node_list(ShaderType p_type) const; Array _get_connections(ShaderType p_type) const; + + void _set_data(const Dictionary& p_data); + Dictionary _get_data() const; protected: static void _bind_methods(); @@ -263,9 +267,8 @@ public: RGB_MAX_OP }; - void rgb_op_node_set_op(ShaderType p_which,float p_id,RGBOp p_op,float p_c); + void rgb_op_node_set_op(ShaderType p_which,float p_id,RGBOp p_op); RGBOp rgb_op_node_get_op(ShaderType p_which,float p_id) const; - float rgb_op_node_get_c(ShaderType p_which,float p_id) const; void xform_vec_mult_node_set_no_translation(ShaderType p_which,int p_id,bool p_no_translation); bool xform_vec_mult_node_get_no_translation(ShaderType p_which,int p_id) const; @@ -345,6 +348,8 @@ public: Variant node_get_state(ShaderType p_type, int p_node) const; void node_set_state(ShaderType p_type, int p_id, const Variant& p_state); + GraphError get_graph_error(ShaderType p_type) const; + static int get_type_input_count(NodeType p_type); static int get_type_output_count(NodeType p_type); static SlotType get_type_input_type(NodeType p_type,int p_idx); @@ -384,6 +389,7 @@ VARIANT_ENUM_CAST( ShaderGraph::VecScalarOp ); VARIANT_ENUM_CAST( ShaderGraph::RGBOp ); VARIANT_ENUM_CAST( ShaderGraph::ScalarFunc ); VARIANT_ENUM_CAST( ShaderGraph::VecFunc ); +VARIANT_ENUM_CAST( ShaderGraph::GraphError ); class MaterialShaderGraph : public ShaderGraph { diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index aee7ddde00..0dd6a3d5e7 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -364,12 +364,12 @@ World2D::World2D() { Physics2DServer::get_singleton()->space_set_active(space,true); Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_GRAVITY,GLOBAL_DEF("physics_2d/default_gravity",98)); Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_GRAVITY_VECTOR,GLOBAL_DEF("physics_2d/default_gravity_vector",Vector2(0,1))); - Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_DENSITY,GLOBAL_DEF("physics_2d/default_density",0.1)); + Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_LINEAR_DAMP,GLOBAL_DEF("physics_2d/default_density",0.1)); + Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_ANGULAR_DAMP,GLOBAL_DEF("physics_2d/default_density",1)); Physics2DServer::get_singleton()->space_set_param(space,Physics2DServer::SPACE_PARAM_CONTACT_RECYCLE_RADIUS,1.0); Physics2DServer::get_singleton()->space_set_param(space,Physics2DServer::SPACE_PARAM_CONTACT_MAX_SEPARATION,1.5); Physics2DServer::get_singleton()->space_set_param(space,Physics2DServer::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION,0.3); Physics2DServer::get_singleton()->space_set_param(space,Physics2DServer::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_TRESHOLD,2); - Physics2DServer::get_singleton()->space_set_param(space,Physics2DServer::SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO,20); Physics2DServer::get_singleton()->space_set_param(space,Physics2DServer::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS,0.2); indexer = memnew( SpatialIndexer2D ); diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp index 0d66257eda..af5e6d4165 100644 --- a/scene/scene_string_names.cpp +++ b/scene/scene_string_names.cpp @@ -67,6 +67,7 @@ SceneStringNames::SceneStringNames() { idle=StaticCString::create("idle"); iteration=StaticCString::create("iteration"); update=StaticCString::create("update"); + updated=StaticCString::create("updated"); _get_gizmo_geometry=StaticCString::create("_get_gizmo_geometry"); _can_gizmo_scale=StaticCString::create("_can_gizmo_scale"); diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index b0628c86b6..14e5e83b8d 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -63,6 +63,7 @@ public: StringName idle; StringName iteration; StringName update; + StringName updated; StringName line_separation; |