From 9f61a4881e018508e1914ddbb4e7740c11f0a272 Mon Sep 17 00:00:00 2001 From: marynate Date: Sun, 18 Jan 2015 02:06:29 +0800 Subject: Fix mingw windows build error --- platform/windows/os_windows.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index ce79133664..4fa061886d 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -57,7 +57,11 @@ static const WORD MAX_CONSOLE_LINES = 1500; extern "C" { +#ifdef _MSC_VER _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; +#else + __attribute__((visibility("default"))) DWORD NvOptimusEnablement = 0x00000001; +#endif } //#define STDOUT_FILE -- cgit v1.2.3 From 6f3c09047ecea651a219c36dd9fa9f96b5f06be4 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 18 Jan 2015 09:51:11 -0300 Subject: -intentional breakage of shader graph to fix issues, existing graphs will be broken, sorry :( --- scene/resources/shader_graph.cpp | 20 +++++++++++++++++++- scene/resources/shader_graph.h | 5 ++++- servers/physics_2d/shape_2d_sw.cpp | 1 + servers/physics_2d/shape_2d_sw.h | 1 - tools/editor/plugins/script_editor_plugin.cpp | 2 +- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index 9703799a48..fcadf60bfe 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -263,12 +263,15 @@ void ShaderGraph::_bind_methods() { BIND_CONSTANT( NODE_XFORM_TO_VEC ); // 3 vec input ); 1 xform output BIND_CONSTANT( NODE_SCALAR_INTERP ); // scalar interpolation (with optional curve) BIND_CONSTANT( NODE_VEC_INTERP ); // vec3 interpolation (with optional curve) + BIND_CONSTANT( NODE_COLOR_RAMP ); + BIND_CONSTANT( NODE_CURVE_MAP ); BIND_CONSTANT( NODE_SCALAR_INPUT ); // scalar uniform (assignable in material) BIND_CONSTANT( NODE_VEC_INPUT ); // vec3 uniform (assignable in material) BIND_CONSTANT( NODE_RGB_INPUT ); // color uniform (assignable in material) BIND_CONSTANT( NODE_XFORM_INPUT ); // mat4 uniform (assignable in material) BIND_CONSTANT( NODE_TEXTURE_INPUT ); // texture input (assignable in material) BIND_CONSTANT( NODE_CUBEMAP_INPUT ); // cubemap input (assignable in material) + BIND_CONSTANT( NODE_DEFAULT_TEXTURE ); BIND_CONSTANT( NODE_OUTPUT ); // output (shader type dependent) BIND_CONSTANT( NODE_COMMENT ); // comment BIND_CONSTANT( NODE_TYPE_MAX ); @@ -519,12 +522,15 @@ 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_COLOR_RAMP: { node.param1=Array();} break; // vec3 interpolation (with optional curve) + case NODE_CURVE_MAP: { node.param1=Array();} break; // vec3 interpolation (with optional curve) 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_CUBEMAP_INPUT: {node.param1=_find_unique_name("Cube"); } break; // cubemap input (assignable in material) + case NODE_DEFAULT_TEXTURE: {}; break; case NODE_OUTPUT: {} break; // output (shader type dependent) case NODE_COMMENT: {} break; // comment case NODE_TYPE_MAX: {}; @@ -1299,6 +1305,8 @@ const ShaderGraph::NodeSlotInfo ShaderGraph::node_slot_info[]= { {NODE_SCALAR_TO_VEC,{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR},{SLOT_TYPE_VEC,SLOT_MAX}}, // 3 scalar input,{SLOT_MAX},{SLOT_MAX}}, 1 vec3 output {NODE_SCALAR_INTERP,{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar interpolation (with optional curve) {NODE_VEC_INTERP,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_TYPE_SCALAR},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 interpolation (with optional curve) + {NODE_COLOR_RAMP,{SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 interpolation (with optional curve) + {NODE_CURVE_MAP,{SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // vec3 interpolation (with optional curve) {NODE_SCALAR_INPUT,{SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar uniform (assignable in material) {NODE_VEC_INPUT,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 uniform (assignable in material) {NODE_RGB_INPUT,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // color uniform (assignable in material) @@ -1987,6 +1995,12 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorid,0)+"=mix("+p_inputs[0]+","+p_inputs[1]+","+p_inputs[2]+");\n"; + }break; + case NODE_COLOR_RAMP: { + + }break; + case NODE_CURVE_MAP: { + }break; case NODE_SCALAR_INPUT: { String name = p_node->param1; @@ -2043,6 +2057,10 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorid,0)+"="+rname+".rgb;\n"; code += OUTNAME(p_node->id,1)+"="+rname+".a;\n"; }break; + case NODE_DEFAULT_TEXTURE: { + + + } break; case NODE_OUTPUT: { diff --git a/scene/resources/shader_graph.h b/scene/resources/shader_graph.h index 55d09b4c38..88818f5615 100644 --- a/scene/resources/shader_graph.h +++ b/scene/resources/shader_graph.h @@ -66,12 +66,15 @@ public: NODE_VEC_TO_XFORM, // 3 vec input, 1 xform output NODE_SCALAR_INTERP, // scalar interpolation (with optional curve) NODE_VEC_INTERP, // vec3 interpolation (with optional curve) - NODE_SCALAR_INPUT, // scalar uniform (assignable in material) + NODE_COLOR_RAMP, //take scalar, output vec3 + NODE_CURVE_MAP, //take scalar, otput scalar + NODE_SCALAR_INPUT, // scalar uniform (assignable in material) NODE_VEC_INPUT, // vec3 uniform (assignable in material) NODE_RGB_INPUT, // color uniform (assignable in material) NODE_XFORM_INPUT, // mat4 uniform (assignable in material) NODE_TEXTURE_INPUT, // texture input (assignable in material) NODE_CUBEMAP_INPUT, // cubemap input (assignable in material) + NODE_DEFAULT_TEXTURE, NODE_OUTPUT, // output (shader type dependent) NODE_COMMENT, // comment NODE_TYPE_MAX diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp index 336eec73b5..ed63870a12 100644 --- a/servers/physics_2d/shape_2d_sw.cpp +++ b/servers/physics_2d/shape_2d_sw.cpp @@ -136,6 +136,7 @@ real_t LineShape2DSW::get_moment_of_inertia(float p_mass, const Vector2 &p_scale return 0; } + void LineShape2DSW::set_data(const Variant& p_data) { ERR_FAIL_COND(p_data.get_type()!=Variant::ARRAY); diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h index 51ece9fc7e..931491efd5 100644 --- a/servers/physics_2d/shape_2d_sw.h +++ b/servers/physics_2d/shape_2d_sw.h @@ -85,7 +85,6 @@ public: virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const=0; virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const=0; - virtual void set_data(const Variant& p_data)=0; virtual Variant get_data() const=0; diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index d90597ddfb..4b7d1cf0e0 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -1607,7 +1607,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { edit_menu->get_popup()->add_item("Clone Down",EDIT_CLONE_DOWN,KEY_MASK_CMD|KEY_B); edit_menu->get_popup()->add_separator(); #ifdef OSX_ENABLED - edit_menu->get_popup()->add_item("Complete Symbol",EDIT_COMPLETE,KEY_MASK_META|KEY_SPACE); + edit_menu->get_popup()->add_item("Complete Symbol",EDIT_COMPLETE,KEY_MASK_CTRL|KEY_SPACE); #else edit_menu->get_popup()->add_item("Complete Symbol",EDIT_COMPLETE,KEY_MASK_CMD|KEY_SPACE); #endif -- cgit v1.2.3 From a0511ed59a0e03232bf3abb49b3c916591453aef Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 19 Jan 2015 02:39:58 -0300 Subject: Color Ramp and Curve Map added to visual shader editing. Added Color Ramp and Curve Map to shader nodes. Fixed an issue that crashed Godot Editor right when opened. --- .gitignore | 1 + drivers/gles2/shaders/canvas.glsl | 9 +- scene/resources/shader_graph.cpp | 323 +++++++- scene/resources/shader_graph.h | 8 + tools/editor/icons/icon_graph_color_ramp.png | Bin 0 -> 290 bytes tools/editor/icons/icon_graph_curve_map.png | Bin 0 -> 619 bytes tools/editor/icons/icon_graph_default_texture.png | Bin 0 -> 326 bytes .../editor/plugins/shader_graph_editor_plugin.cpp | 835 ++++++++++++++++++++- tools/editor/plugins/shader_graph_editor_plugin.h | 74 +- 9 files changed, 1240 insertions(+), 10 deletions(-) create mode 100644 tools/editor/icons/icon_graph_color_ramp.png create mode 100644 tools/editor/icons/icon_graph_curve_map.png create mode 100644 tools/editor/icons/icon_graph_default_texture.png diff --git a/.gitignore b/.gitignore index 4aee83c13f..1e53f3712b 100644 --- a/.gitignore +++ b/.gitignore @@ -258,3 +258,4 @@ Desktop.ini # Recycle Bin used on file shares $RECYCLE.BIN/ logo.h +*.autosave diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index 464cb9e188..5a26f7321e 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -46,14 +46,15 @@ void main() { color_interp = color_attrib; uv_interp = uv_attrib; - highp vec4 outvec = vec4(vertex, 1.0); + highp vec4 outvec = vec4(vertex, 1.0); { - vec2 src_vtx=outvec.xy; + vec2 src_vtx=outvec.xy; VERTEX_SHADER_CODE } - outvec = extra_matrix * outvec; - outvec = modelview_matrix * outvec; + outvec = extra_matrix * outvec; + outvec = modelview_matrix * outvec; + #ifdef USE_PIXEL_SNAP outvec.xy=floor(outvec.xy+0.5); diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index fcadf60bfe..9fc2f99a0a 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -221,6 +221,13 @@ void ShaderGraph::_bind_methods() { ObjectTypeDB::bind_method(_MD("comment_node_set_text","shader_type","id","text"),&ShaderGraph::comment_node_set_text); ObjectTypeDB::bind_method(_MD("comment_node_get_text","shader_type","id"),&ShaderGraph::comment_node_get_text); + ObjectTypeDB::bind_method(_MD("color_ramp_node_set_ramp","shader_type","id","colors","offsets"),&ShaderGraph::color_ramp_node_set_ramp); + ObjectTypeDB::bind_method(_MD("color_ramp_node_get_colors","shader_type","id"),&ShaderGraph::color_ramp_node_get_colors); + ObjectTypeDB::bind_method(_MD("color_ramp_node_get_offsets","shader_type","id"),&ShaderGraph::color_ramp_node_get_offsets); + + ObjectTypeDB::bind_method(_MD("curve_map_node_set_points","shader_type","id","points"),&ShaderGraph::curve_map_node_set_points); + ObjectTypeDB::bind_method(_MD("curve_map_node_get_points","shader_type","id"),&ShaderGraph::curve_map_node_get_points); + ObjectTypeDB::bind_method(_MD("connect_node:Error","shader_type","src_id","src_slot","dst_id","dst_slot"),&ShaderGraph::connect_node); ObjectTypeDB::bind_method(_MD("is_node_connected","shader_type","src_id","src_slot","dst_id","dst_slot"),&ShaderGraph::is_node_connected); ObjectTypeDB::bind_method(_MD("disconnect_node","shader_type","src_id","src_slot","dst_id","dst_slot"),&ShaderGraph::disconnect_node); @@ -522,8 +529,8 @@ 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_COLOR_RAMP: { node.param1=Array();} break; // vec3 interpolation (with optional curve) - case NODE_CURVE_MAP: { node.param1=Array();} break; // vec3 interpolation (with optional curve) + case NODE_COLOR_RAMP: { node.param1=DVector(); node.param2=DVector();} break; // vec3 interpolation (with optional curve) + case NODE_CURVE_MAP: { node.param1=DVector();} break; // vec3 interpolation (with optional curve) 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) @@ -970,6 +977,59 @@ ShaderGraph::VecFunc ShaderGraph::vec_func_node_get_function(ShaderType p_type, return VecFunc(func); } +void ShaderGraph::color_ramp_node_set_ramp(ShaderType p_type,int p_id,const DVector& p_colors, const DVector& p_offsets){ + + ERR_FAIL_INDEX(p_type,3); + ERR_FAIL_COND(!shader[p_type].node_map.has(p_id)); + ERR_FAIL_COND(p_colors.size()!=p_offsets.size()); + Node& n = shader[p_type].node_map[p_id]; + n.param1=p_colors; + n.param2=p_offsets; + _request_update(); + +} + +DVector ShaderGraph::color_ramp_node_get_colors(ShaderType p_type,int p_id) const{ + + ERR_FAIL_INDEX_V(p_type,3,DVector()); + ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),DVector()); + const Node& n = shader[p_type].node_map[p_id]; + return n.param1; + + +} + +DVector ShaderGraph::color_ramp_node_get_offsets(ShaderType p_type,int p_id) const{ + + ERR_FAIL_INDEX_V(p_type,3,DVector()); + ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),DVector()); + const Node& n = shader[p_type].node_map[p_id]; + return n.param2; + +} + + +void ShaderGraph::curve_map_node_set_points(ShaderType p_type,int p_id,const DVector& p_points) { + + 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]; + n.param1=p_points; + _request_update(); + +} + +DVector ShaderGraph::curve_map_node_get_points(ShaderType p_type,int p_id) const{ + + ERR_FAIL_INDEX_V(p_type,3,DVector()); + ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),DVector()); + const Node& n = shader[p_type].node_map[p_id]; + return n.param1; + +} + + + void ShaderGraph::input_node_set_name(ShaderType p_type,int p_id,const String& p_name){ ERR_FAIL_INDEX(p_type,3); @@ -1305,7 +1365,7 @@ const ShaderGraph::NodeSlotInfo ShaderGraph::node_slot_info[]= { {NODE_SCALAR_TO_VEC,{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR},{SLOT_TYPE_VEC,SLOT_MAX}}, // 3 scalar input,{SLOT_MAX},{SLOT_MAX}}, 1 vec3 output {NODE_SCALAR_INTERP,{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar interpolation (with optional curve) {NODE_VEC_INTERP,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_TYPE_SCALAR},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 interpolation (with optional curve) - {NODE_COLOR_RAMP,{SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 interpolation (with optional curve) + {NODE_COLOR_RAMP,{SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // vec3 interpolation (with optional curve) {NODE_CURVE_MAP,{SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // vec3 interpolation (with optional curve) {NODE_SCALAR_INPUT,{SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar uniform (assignable in material) {NODE_VEC_INPUT,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 uniform (assignable in material) @@ -1696,6 +1756,134 @@ void ShaderGraph::_update_shader() { emit_signal(SceneStringNames::get_singleton()->updated); } +void ShaderGraph::_plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector2& p_c,const Vector2& p_d,uint8_t* p_heights,bool *p_useds) { + + float geometry[4][4]; + float tmp1[4][4]; + float tmp2[4][4]; + float deltas[4][4]; + double x, dx, dx2, dx3; + double y, dy, dy2, dy3; + double d, d2, d3; + int lastx, lasty; + int newx, newy; + int ntimes; + int i,j; + + int xmax=255; + int ymax=255; + + /* construct the geometry matrix from the segment */ + for (i = 0; i < 4; i++) { + geometry[i][2] = 0; + geometry[i][3] = 0; + } + + geometry[0][0] = (p_a[0] * xmax); + geometry[1][0] = (p_b[0] * xmax); + geometry[2][0] = (p_c[0] * xmax); + geometry[3][0] = (p_d[0] * xmax); + + geometry[0][1] = (p_a[1] * ymax); + geometry[1][1] = (p_b[1] * ymax); + geometry[2][1] = (p_c[1] * ymax); + geometry[3][1] = (p_d[1] * ymax); + + /* subdivide the curve ntimes (1000) times */ + ntimes = 4 * xmax; + /* ntimes can be adjusted to give a finer or coarser curve */ + d = 1.0 / ntimes; + d2 = d * d; + d3 = d * d * d; + + /* construct a temporary matrix for determining the forward differencing deltas */ + tmp2[0][0] = 0; tmp2[0][1] = 0; tmp2[0][2] = 0; tmp2[0][3] = 1; + tmp2[1][0] = d3; tmp2[1][1] = d2; tmp2[1][2] = d; tmp2[1][3] = 0; + tmp2[2][0] = 6*d3; tmp2[2][1] = 2*d2; tmp2[2][2] = 0; tmp2[2][3] = 0; + tmp2[3][0] = 6*d3; tmp2[3][1] = 0; tmp2[3][2] = 0; tmp2[3][3] = 0; + + /* compose the basis and geometry matrices */ + + static const float CR_basis[4][4] = + { + { -0.5, 1.5, -1.5, 0.5 }, + { 1.0, -2.5, 2.0, -0.5 }, + { -0.5, 0.0, 0.5, 0.0 }, + { 0.0, 1.0, 0.0, 0.0 }, + }; + + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + { + tmp1[i][j] = (CR_basis[i][0] * geometry[0][j] + + CR_basis[i][1] * geometry[1][j] + + CR_basis[i][2] * geometry[2][j] + + CR_basis[i][3] * geometry[3][j]); + } + } + /* compose the above results to get the deltas matrix */ + + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + { + deltas[i][j] = (tmp2[i][0] * tmp1[0][j] + + tmp2[i][1] * tmp1[1][j] + + tmp2[i][2] * tmp1[2][j] + + tmp2[i][3] * tmp1[3][j]); + } + } + + + /* extract the x deltas */ + x = deltas[0][0]; + dx = deltas[1][0]; + dx2 = deltas[2][0]; + dx3 = deltas[3][0]; + + /* extract the y deltas */ + y = deltas[0][1]; + dy = deltas[1][1]; + dy2 = deltas[2][1]; + dy3 = deltas[3][1]; + + + lastx = CLAMP (x, 0, xmax); + lasty = CLAMP (y, 0, ymax); + + p_heights[lastx] = lasty; + p_useds[lastx] = true; + + /* loop over the curve */ + for (i = 0; i < ntimes; i++) + { + /* increment the x values */ + x += dx; + dx += dx2; + dx2 += dx3; + + /* increment the y values */ + y += dy; + dy += dy2; + dy2 += dy3; + + newx = CLAMP ((Math::round (x)), 0, xmax); + newy = CLAMP ((Math::round (y)), 0, ymax); + + /* if this point is different than the last one...then draw it */ + if ((lastx != newx) || (lasty != newy)) + { + p_useds[newx]=true; + p_heights[newx]=newy; + } + + lastx = newx; + lasty = newy; + } +} + + void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector& p_inputs,String& code) { @@ -1998,8 +2186,125 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector cramp; + cramp.resize(color_ramp_len*4); + { + + DVector colors=p_node->param1; + DVector offsets=p_node->param2; + int cc =colors.size(); + DVector::Write crw = cramp.write(); + DVector::Read cr = colors.read(); + DVector::Read ofr = offsets.read(); + + int at=0; + Color color_at(0,0,0,1); + for(int i=0;i<=cc;i++) { + + int pos; + Color to; + if (i==cc) { + if (at==color_ramp_len) + break; + pos=color_ramp_len; + to=Color(1,1,1,1); + } else { + to=cr[i]; + pos= MIN(ofr[i]*color_ramp_len,color_ramp_len); + } + for(int j=at;j it = memnew( ImageTexture ); + it->create_from_image(gradient,Texture::FLAG_FILTER|Texture::FLAG_MIPMAPS); + + String crampname= "cramp_"+itos(p_node->id); + set_default_texture_param(crampname,it); + + code +="uniform texture "+crampname+";\n"; + code +="vec4 "+crampname+"_r=tex("+crampname+",vec2("+p_inputs[0]+",0));\n"; + code += OUTNAME(p_node->id,0)+"="+crampname+"_r.rgb;\n"; + code += OUTNAME(p_node->id,1)+"="+crampname+"_r.a;\n"; + }break; case NODE_CURVE_MAP: { + static const int curve_map_len=256; + bool mapped[256]; + zeromem(mapped,sizeof(mapped)); + DVector cmap; + cmap.resize(curve_map_len); + { + + DVector points=p_node->param1; + int pc =points.size(); + DVector::Write cmw = cmap.write(); + DVector::Read pr = points.read(); + + Vector2 prev=Vector2(0,0); + Vector2 prev2=Vector2(0,0); + + for(int i=-1;i=pc) { + next=Vector2(1,1); + } else { + next=Vector2(pr[i+1].x,pr[i+1].y); + } + + if (i+2>=pc) { + next2=Vector2(1,1); + } else { + next2=Vector2(pr[i+2].x,pr[i+2].y); + } + + /*if (i==-1 && prev.offset==next.offset) { + prev=next; + continue; + }*/ + + _plot_curve(prev2,prev,next,next2,cmw.ptr(),mapped); + + prev2=prev; + prev=next; + } + + uint8_t pp=0; + for(int i=0;i it = memnew( ImageTexture ); + it->create_from_image(gradient,Texture::FLAG_FILTER|Texture::FLAG_MIPMAPS); + + String cmapname= "cmap_"+itos(p_node->id); + set_default_texture_param(cmapname,it); + + code +="uniform texture "+cmapname+";\n"; + code += OUTNAME(p_node->id,0)+"=tex("+cmapname+",vec2("+p_inputs[0]+",0)).r;\n"; }break; case NODE_SCALAR_INPUT: { @@ -2059,7 +2364,19 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorid); + code +="vec4 "+rname+"=tex(TEXTURE,"+p_inputs[0]+".xy);\n"; + code += OUTNAME(p_node->id,0)+"="+rname+".rgb;\n"; + code += OUTNAME(p_node->id,1)+"="+rname+".a;\n"; + + } else { + + code += OUTNAME(p_node->id,0)+"=vec3(0,0,0);\n"; + code += OUTNAME(p_node->id,1)+"=1.0;\n"; + + } } break; case NODE_OUTPUT: { diff --git a/scene/resources/shader_graph.h b/scene/resources/shader_graph.h index 88818f5615..ff2ca68335 100644 --- a/scene/resources/shader_graph.h +++ b/scene/resources/shader_graph.h @@ -175,6 +175,7 @@ private: void _update_shader(); void _request_update(); + void _plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector2& p_c,const Vector2& p_d,uint8_t* p_heights,bool *p_useds); void _add_node_code(ShaderType p_type,Node *p_node,const Vector& p_inputs,String& code); Array _get_node_list(ShaderType p_type) const; @@ -316,6 +317,13 @@ public: void vec_func_node_set_function(ShaderType p_which,int p_id,VecFunc p_func); VecFunc vec_func_node_get_function(ShaderType p_which,int p_id) const; + void color_ramp_node_set_ramp(ShaderType p_which,int p_id,const DVector& p_colors, const DVector& p_offsets); + DVector color_ramp_node_get_colors(ShaderType p_which,int p_id) const; + DVector color_ramp_node_get_offsets(ShaderType p_which,int p_id) const; + + void curve_map_node_set_points(ShaderType p_which, int p_id, const DVector& p_points); + DVector curve_map_node_get_points(ShaderType p_which,int p_id) const; + void input_node_set_name(ShaderType p_which,int p_id,const String& p_name); String input_node_get_name(ShaderType p_which,int p_id); diff --git a/tools/editor/icons/icon_graph_color_ramp.png b/tools/editor/icons/icon_graph_color_ramp.png new file mode 100644 index 0000000000..9031b5ec53 Binary files /dev/null and b/tools/editor/icons/icon_graph_color_ramp.png differ diff --git a/tools/editor/icons/icon_graph_curve_map.png b/tools/editor/icons/icon_graph_curve_map.png new file mode 100644 index 0000000000..de5c32f09e Binary files /dev/null and b/tools/editor/icons/icon_graph_curve_map.png differ diff --git a/tools/editor/icons/icon_graph_default_texture.png b/tools/editor/icons/icon_graph_default_texture.png new file mode 100644 index 0000000000..da77ec9364 Binary files /dev/null and b/tools/editor/icons/icon_graph_default_texture.png differ diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index 0a206c4a45..39508464c1 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -32,6 +32,642 @@ #include "scene/gui/menu_button.h" #include "scene/gui/panel.h" #include "spatial_editor_plugin.h" +#include "os/keyboard.h" + + +void GraphColorRampEdit::_input_event(const InputEvent& p_event) { + + if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { + + points.remove(grabbed); + grabbed=-1; + update(); + emit_signal("ramp_changed"); + accept_event(); + } + + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + + update(); + int x = p_event.mouse_button.x; + int total_w = get_size().width-get_size().height-3; + if (x>total_w+3) { + + if (grabbed==-1) + return; + Size2 ms = Size2(350, picker->get_combined_minimum_size().height+10); + picker->set_color(points[grabbed].color); + popup->set_pos(get_global_pos()-Size2(0,ms.height)); + popup->set_size(ms); + popup->popup(); + return; + } + + + float ofs = CLAMP(x/float(total_w),0,1); + + grabbed=-1; + grabbing=true; + int pos=-1; + for(int i=0;iconnect("color_changed",this,"_color_changed"); + } + if (p_what==NOTIFICATION_DRAW) { + + + Point prev; + prev.offset=0; + prev.color=Color(0,0,0); + int w = get_size().x; + int h = get_size().y; + + int total_w = get_size().width-get_size().height-3; + + for(int i=-1;i points; + Vector colors; + points.push_back(Vector2(prev.offset*total_w,h)); + points.push_back(Vector2(prev.offset*total_w,0)); + points.push_back(Vector2(next.offset*total_w,0)); + points.push_back(Vector2(next.offset*total_w,h)); + colors.push_back(prev.color); + colors.push_back(prev.color); + colors.push_back(next.color); + colors.push_back(next.color); + draw_primitive(points,colors,Vector()); + prev=next; + } + + for(int i=0;i& p_offsets,const Vector& p_colors) { + + ERR_FAIL_COND(p_offsets.size()!=p_colors.size()); + points.clear(); + for(int i=0;i GraphColorRampEdit::get_offsets() const{ + Vector ret; + for(int i=0;i GraphColorRampEdit::get_colors() const{ + + Vector ret; + for(int i=0;iadd_child(picker); + popup->set_child_rect(picker); + add_child(popup); + +} +//////////// + +void GraphCurveMapEdit::_input_event(const InputEvent& p_event) { + + if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { + + points.remove(grabbed); + grabbed=-1; + update(); + emit_signal("curve_changed"); + accept_event(); + } + + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + + update(); + Point2 p = Vector2(p_event.mouse_button.x,p_event.mouse_button.y)/get_size(); + p.y=1.0-p.y; + grabbed=-1; + grabbing=true; + + for(int i=0;icurve[cd->outline][lastx] = lasty; + } + else + { + cd->curve_ptr[cd->outline][lastx] = lasty; + if(gb_debug) printf("bender_plot_curve xmax:%d ymax:%d\n", (int)xmax, (int)ymax); + } +*/ + /* loop over the curve */ + for (i = 0; i < ntimes; i++) + { + /* increment the x values */ + x += dx; + dx += dx2; + dx2 += dx3; + + /* increment the y values */ + y += dy; + dy += dy2; + dy2 += dy3; + + newx = CLAMP ((Math::round (x)), 0, xmax); + newy = CLAMP ((Math::round (y)), 0, ymax); + + /* if this point is different than the last one...then draw it */ + if ((lastx != newx) || (lasty != newy)) + { +#if 0 + /* + if(fix255) + { + /* use fixed array size (for the curve graph) */ + cd->curve[cd->outline][newx] = newy; + } + else + { + /* use dynamic allocated curve_ptr (for the real curve) */ + cd->curve_ptr[cd->outline][newx] = newy; + + if(gb_debug) printf("outline: %d cX: %d cY: %d\n", (int)cd->outline, (int)newx, (int)newy); + } +#endif + draw_line(Vector2(lastx,ymax-lasty),Vector2(newx,ymax-newy),Color(0.8,0.8,0.8,0.8),2.0); + } + + lastx = newx; + lasty = newy; + } +} + + +void GraphCurveMapEdit::_notification(int p_what){ + + if (p_what==NOTIFICATION_DRAW) { + + draw_style_box(get_stylebox("bg","Tree"),Rect2(Point2(),get_size())); + + int w = get_size().x; + int h = get_size().y; + + Vector2 prev=Vector2(0,0); + Vector2 prev2=Vector2(0,0); + + for(int i=-1;i=points.size()) { + next=Vector2(1,1); + } else { + next=Vector2(points[i+1].offset,points[i+1].height); + } + + if (i+2>=points.size()) { + next2=Vector2(1,1); + } else { + next2=Vector2(points[i+2].offset,points[i+2].height); + } + + /*if (i==-1 && prev.offset==next.offset) { + prev=next; + continue; + }*/ + + _plot_curve(prev2,prev,next,next2); + + prev2=prev; + prev=next; + } + + for(int i=0;i& p_points) { + + + points.clear(); + for(int i=0;i GraphCurveMapEdit::get_points() const { + Vector ret; + for(int i=0;icast_to(); + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + + + Vector offsets=cr->get_offsets(); + Vector colors=cr->get_colors(); + + DVector new_offsets; + DVector new_colors; + { + new_offsets.resize(offsets.size()); + new_colors.resize(colors.size()); + DVector::Write ow=new_offsets.write(); + DVector::Write cw=new_colors.write(); + for(int i=0;i old_offsets=graph->color_ramp_node_get_offsets(type,p_id); + DVector old_colors=graph->color_ramp_node_get_colors(type,p_id); + + if (old_offsets.size()!=new_offsets.size()) + ur->create_action("Add/Remove to Color Ramp"); + else + ur->create_action("Modify Color Ramp",true); + + ur->add_do_method(graph.ptr(),"color_ramp_node_set_ramp",type,p_id,new_colors,new_offsets); + ur->add_undo_method(graph.ptr(),"color_ramp_node_set_ramp",type,p_id,old_colors,old_offsets); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; +} + +void ShaderGraphView::_curve_changed(int p_id,Node* p_curve) { + + GraphCurveMapEdit *cr=p_curve->cast_to(); + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + + + Vector points=cr->get_points(); + + DVector new_points; + { + new_points.resize(points.size()); + DVector::Write ow=new_points.write(); + for(int i=0;i old_points=graph->curve_map_node_get_points(type,p_id); + + if (old_points.size()!=new_points.size()) + ur->create_action("Add/Remove to Curve Map"); + else + ur->create_action("Modify Curve Map",true); + + ur->add_do_method(graph.ptr(),"curve_map_node_set_points",type,p_id,new_points); + ur->add_undo_method(graph.ptr(),"curve_map_node_set_points",type,p_id,old_points); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; +} + void ShaderGraphView::_input_name_changed(const String& p_name, int p_id, Node *p_line_edit) { @@ -1026,6 +1740,96 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); } break; // vec3 interpolation (with optional curve) + case ShaderGraph::NODE_COLOR_RAMP: { + + gn->set_title("ColorRamp"); + GraphColorRampEdit * ramp = memnew( GraphColorRampEdit ); + + DVector offsets = graph->color_ramp_node_get_offsets(type,p_id); + DVector colors = graph->color_ramp_node_get_colors(type,p_id); + + int oc = offsets.size(); + + if (oc) { + DVector::Read rofs = offsets.read(); + DVector::Read rcol = colors.read(); + + Vector ofsv; + Vector colorv; + for(int i=0;iset_ramp(ofsv,colorv); + + } + + ramp->connect("ramp_changed",this,"_color_ramp_changed",varray(p_id,ramp)); + ramp->set_custom_minimum_size(Size2(128,1)); + gn->add_child(ramp); + + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("c"))); + hbc->add_spacer(); + Label *l=memnew(Label("rgb")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + l=memnew(Label("alpha")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); + + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,false,ShaderGraph::SLOT_MAX,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // scalar interpolation (with optional curve) + case ShaderGraph::NODE_CURVE_MAP: { + + gn->set_title("CurveMap"); + GraphCurveMapEdit * map = memnew( GraphCurveMapEdit ); + + DVector points = graph->curve_map_node_get_points(type,p_id); + + int oc = points.size(); + + if (oc) { + DVector::Read rofs = points.read(); + + + Vector ofsv; + for(int i=0;iset_points(ofsv); + + } + map->connect("curve_changed",this,"_curve_changed",varray(p_id,map)); + + //map->connect("map_changed",this,"_curve_map_changed",varray(p_id,map)); + map->set_custom_minimum_size(Size2(128,64)); + gn->add_child(map); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("c"))); + hbc->add_spacer(); + Label *l=memnew(Label("cmap")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // scalar interpolation (with optional curve) + case ShaderGraph::NODE_SCALAR_INPUT: { gn->set_title("ScalarUniform"); @@ -1173,6 +1977,28 @@ void ShaderGraphView::_create_node(int p_id) { gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); } break; // cubemap input (assignable in material) + case ShaderGraph::NODE_DEFAULT_TEXTURE: { + + gn->set_title("CanvasItemTex"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + Label *l=memnew(Label("RGB")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child(l); + gn->add_child(hbc); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + 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,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // screen texture sampler (takes UV) (only usable in fragment case Shader) + case ShaderGraph::NODE_OUTPUT: { gn->set_title("Output"); @@ -1360,6 +2186,8 @@ void ShaderGraphView::_bind_methods() { ObjectTypeDB::bind_method("_variant_edited",&ShaderGraphView::_variant_edited); ObjectTypeDB::bind_method("_cube_edited",&ShaderGraphView::_cube_edited); ObjectTypeDB::bind_method("_comment_edited",&ShaderGraphView::_comment_edited); + ObjectTypeDB::bind_method("_color_ramp_changed",&ShaderGraphView::_color_ramp_changed); + ObjectTypeDB::bind_method("_curve_changed",&ShaderGraphView::_curve_changed); ObjectTypeDB::bind_method("_sg_updated",&ShaderGraphView::_sg_updated); } @@ -1455,13 +2283,16 @@ const char* ShaderGraphEditor::node_names[ShaderGraph::NODE_TYPE_MAX]={ "GraphVecsToXform:Vectors -> XForm:", // 3 vec input", 1 xform output "GraphScalarInterp:Scalar Interpolate", // scalar interpolation (with optional curve) "GraphVecInterp:Vector Interpolate:", // vec3 interpolation (with optional curve) - "GraphScalarUniform:Scalar Uniform", // scalar uniform (assignable in material) + "GraphColorRamp:Color Ramp", // vec3 interpolation (with optional curve) + "GraphCurveMap:Curve Remap:", // vec3 interpolation (with optional curve) + "GraphScalarUniform:Scalar Uniform", // scalar uniform (assignable in material) "GraphVectorUniform:Vector Uniform", // vec3 uniform (assignable in material) "GraphRgbUniform:RGB Uniform", // color uniform (assignable in material) "GraphXformUniform:XForm Uniform", // mat4 uniform (assignable in material) "GraphTextureUniform:Texture Uniform", // texture input (assignable in material) "GraphCubeUniform:CubeMap Uniform:", // cubemap input (assignable in material) - "Output", // output (shader type dependent) + "GraphDefaultTexture:CanvasItem Texture:", // cubemap input (assignable in material) + "Output", // output (shader type dependent) "GraphComment:Comment", // comment diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h index bd983c59be..c6fb2f82b1 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.h +++ b/tools/editor/plugins/shader_graph_editor_plugin.h @@ -45,6 +45,77 @@ */ +class GraphColorRampEdit : public Control { + + OBJ_TYPE(GraphColorRampEdit,Control); + + + struct Point { + + float offset; + Color color; + bool operator<(const Point& p_ponit) const { + return offset points; + + void _color_changed(const Color& p_color); + +protected: + void _input_event(const InputEvent& p_event); + void _notification(int p_what); + static void _bind_methods(); +public: + + void set_ramp(const Vector& p_offsets,const Vector& p_colors); + Vector get_offsets() const; + Vector get_colors() const; + virtual Size2 get_minimum_size() const; + GraphColorRampEdit(); +}; + + +class GraphCurveMapEdit : public Control { + + OBJ_TYPE(GraphCurveMapEdit,Control); + + + struct Point { + + float offset; + float height; + bool operator<(const Point& p_ponit) const { + return offset points; + + void _plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector2& p_c,const Vector2& p_d); +protected: + void _input_event(const InputEvent& p_event); + void _notification(int p_what); + static void _bind_methods(); +public: + + void set_points(const Vector& p_points); + Vector get_points() const; + virtual Size2 get_minimum_size() const; + GraphCurveMapEdit(); +}; + class ShaderGraphView : public Node { OBJ_TYPE(ShaderGraphView,Node); @@ -95,7 +166,8 @@ class ShaderGraphView : public Node { void _cube_edited(int p_id,Node* p_button); void _variant_edited(); void _comment_edited(int p_id,Node* p_button); - + void _color_ramp_changed(int p_id,Node* p_ramp); + void _curve_changed(int p_id,Node* p_curve); void _sg_updated(); Map node_map; protected: -- cgit v1.2.3 From 317c496f5c1aa25af4144ea04cef4ba6fe420830 Mon Sep 17 00:00:00 2001 From: sanikoyes Date: Tue, 20 Jan 2015 20:01:02 +0800 Subject: Add InputEvent::ACTION get/set support for variant Add action_press/action_release method bind --- core/os/input.cpp | 2 ++ core/variant_op.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/core/os/input.cpp b/core/os/input.cpp index a827e75896..5d4b3a834d 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -62,6 +62,8 @@ void Input::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_mouse_mode","mode"),&Input::set_mouse_mode); ObjectTypeDB::bind_method(_MD("get_mouse_mode"),&Input::get_mouse_mode); ObjectTypeDB::bind_method(_MD("warp_mouse_pos","to"),&Input::warp_mouse_pos); + ObjectTypeDB::bind_method(_MD("action_press"),&Input::action_press); + ObjectTypeDB::bind_method(_MD("action_release"),&Input::action_release); BIND_CONSTANT( MOUSE_MODE_VISIBLE ); BIND_CONSTANT( MOUSE_MODE_HIDDEN ); diff --git a/core/variant_op.cpp b/core/variant_op.cpp index ec43b1275c..fbb5e2631d 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -1687,6 +1687,19 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid) return; } } + if (ie.type == InputEvent::ACTION) { + + if (str =="action") { + valid=true; + ie.action.action=p_value; + return; + } + else if (str == "pressed") { + valid=true; + ie.action.pressed=p_value; + return; + } + } } break; case DICTIONARY: { @@ -2365,6 +2378,17 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const { return Vector2(ie.screen_drag.speed_x,ie.screen_drag.speed_y); } } + if (ie.type == InputEvent::ACTION) { + + if (str =="action") { + valid=true; + return ie.action.action; + } + else if (str == "pressed") { + valid=true; + ie.action.pressed; + } + } } break; case DICTIONARY: { -- cgit v1.2.3 From 11c1756257368f3cd41702016c3303c0d22e3b59 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 20 Jan 2015 20:25:19 -0300 Subject: Visual Shader Editing for 2D Editing 2D shaders with visual editor seems to work now. --- drivers/gles2/rasterizer_gles2.cpp | 48 ++++++++++++++------- drivers/gles2/shader_compiler_gles2.cpp | 7 ++++ drivers/gles2/shader_compiler_gles2.h | 3 ++ drivers/gles2/shaders/canvas.glsl | 8 ++-- scene/2d/canvas_item.cpp | 2 +- scene/register_scene_types.cpp | 1 + scene/resources/shader_graph.cpp | 49 +++++++++++++++++++++- scene/resources/shader_graph.h | 14 ++++++- servers/visual/shader_language.cpp | 1 + tools/editor/editor_node.cpp | 3 +- .../editor/plugins/shader_graph_editor_plugin.cpp | 26 +++++++++--- tools/editor/plugins/shader_graph_editor_plugin.h | 6 ++- 12 files changed, 138 insertions(+), 30 deletions(-) diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 9375532f07..4990e81f42 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -4588,6 +4588,9 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const { enablers.push_back("#define USE_TEXPIXEL_SIZE\n"); } + if (fragment_flags.uses_worldvec) { + enablers.push_back("#define USE_WORLD_VEC\n"); + } canvas_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, light_code, fragment_globals,uniform_names,enablers); //postprocess_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, fragment_globals,uniform_names); @@ -8362,24 +8365,39 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) { int idx=0; for(Map::Element *E=shader->uniforms.front();E;E=E->next()) { - Map::Element *F=shader_owner->shader_param.find(E->key()); - Variant &v=F?F->get():E->get().default_value; - if (v.get_type()==Variant::_RID || v.get_type()==Variant::OBJECT) { - int loc = canvas_shader.get_custom_uniform_location(idx); //should be automatic.. - - glActiveTexture(GL_TEXTURE0+tex_id); - RID tex = v; - Texture *t=texture_owner.get(tex); - if (!t) - glBindTexture(GL_TEXTURE_2D,white_tex); - else - glBindTexture(t->target,t->tex_id); - glUniform1i(loc,tex_id); - tex_id++; + if ((E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP)) { + RID rid; + if (F) { + rid=F->get(); + } + + if (!rid.is_valid()) { + + Map::Element *DT=shader->default_textures.find(E->key()); + if (DT) { + rid=DT->get(); + } + } + + if (rid.is_valid()) { + + int loc = canvas_shader.get_custom_uniform_location(idx); //should be automatic.. + + glActiveTexture(GL_TEXTURE0+tex_id); + Texture *t=texture_owner.get(rid); + if (!t) + glBindTexture(GL_TEXTURE_2D,white_tex); + else + glBindTexture(t->target,t->tex_id); + + glUniform1i(loc,tex_id); + tex_id++; + } } else { + Variant &v=F?F->get():E->get().default_value; canvas_shader.set_custom_uniform(idx,v); } @@ -8403,7 +8421,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) { #endif glCopyTexSubImage2D(GL_TEXTURE_2D,0,x,y,x,y,viewport.width,viewport.height); if (current_clip) { - print_line(" a clip "); + // print_line(" a clip "); } canvas_texscreen_used=true; diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp index f1ddcf8009..9662ea0fa6 100644 --- a/drivers/gles2/shader_compiler_gles2.cpp +++ b/drivers/gles2/shader_compiler_gles2.cpp @@ -239,6 +239,9 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a if (vnode->name==vname_normal) { uses_normal=true; } + if (vnode->name==vname_world_vec) { + uses_worldvec=true; + } if (vnode->name==vname_screen_uv) { uses_screen_uv=true; @@ -599,6 +602,7 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT uses_normalmap=false; uses_normal=false; uses_texpixel_size=false; + uses_worldvec=false; vertex_code_writes_vertex=false; uniforms=r_uniforms; flags=&r_flags; @@ -634,6 +638,7 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT r_flags.uses_normalmap=uses_normalmap; r_flags.uses_normal=uses_normalmap; r_flags.uses_texpixel_size=uses_texpixel_size; + r_flags.uses_worldvec=uses_worldvec; r_code_line=code; r_globals_line=global_code; @@ -774,6 +779,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() { mode_replace_table[3]["SRC_VERTEX"]="src_vtx"; mode_replace_table[3]["VERTEX"]="outvec.xy"; + mode_replace_table[3]["WORLD_VERTEX"]="outvec.xy"; mode_replace_table[3]["UV"]="uv_interp"; mode_replace_table[3]["COLOR"]="color_interp"; mode_replace_table[3]["VAR1"]="var1_interp"; @@ -830,5 +836,6 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() { vname_normalmap="NORMALMAP"; vname_normal="NORMAL"; vname_texpixel_size="TEXTURE_PIXEL_SIZE"; + vname_world_vec="WORLD_VERTEX"; } diff --git a/drivers/gles2/shader_compiler_gles2.h b/drivers/gles2/shader_compiler_gles2.h index a10fa6dfe0..87722602fd 100644 --- a/drivers/gles2/shader_compiler_gles2.h +++ b/drivers/gles2/shader_compiler_gles2.h @@ -53,6 +53,7 @@ private: bool uses_normalmap; bool uses_normal; bool uses_texpixel_size; + bool uses_worldvec; bool vertex_code_writes_vertex; Flags *flags; @@ -72,6 +73,7 @@ private: StringName vname_normalmap; StringName vname_normal; StringName vname_texpixel_size; + StringName vname_world_vec; Map *uniforms; @@ -107,6 +109,7 @@ public: bool uses_time; bool uses_normal; bool uses_texpixel_size; + bool uses_worldvec; }; Error compile(const String& p_code, ShaderLanguage::ShaderType p_type, String& r_code_line, String& r_globals_line, Flags& r_flags, Map *r_uniforms=NULL); diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index 5a26f7321e..dc0af017d0 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -52,8 +52,10 @@ void main() { VERTEX_SHADER_CODE } +#if !defined(USE_WORLD_VEC) outvec = extra_matrix * outvec; outvec = modelview_matrix * outvec; +#endif #ifdef USE_PIXEL_SNAP @@ -61,15 +63,15 @@ VERTEX_SHADER_CODE #endif + gl_Position = projection_matrix * outvec; + #ifdef USE_LIGHTING - light_tex_pos.xy = light_matrix * outvec; + light_tex_pos.xy = light_matrix * gl_Position; light_tex_pos.zw=outvec.xy - light_matrix[4].xy; //likely wrong #endif - - gl_Position = projection_matrix * outvec; } [fragment] diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index ae857bbce9..6b892839bb 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -969,7 +969,7 @@ CanvasItem::CanvasItem() : xform_change(this) { block_transform_notify=false; // viewport=NULL; canvas_layer=NULL; - use_parent_shader; + use_parent_shader=false; global_invalid=true; C=NULL; diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 998e0b2044..9d907391ec 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -499,6 +499,7 @@ void register_scene_types() { ObjectTypeDB::register_virtual_type(); ObjectTypeDB::register_virtual_type(); ObjectTypeDB::register_type(); + ObjectTypeDB::register_type(); #ifndef _3D_DISABLED ObjectTypeDB::register_type(); diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index 9fc2f99a0a..73812a7ae5 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -1320,6 +1320,43 @@ const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={ {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}, + //canvas item vertex in + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Vertex","vec3(SRC_VERTEX,0)","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"UV","SRC_UV","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Color","SRC_COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Alpha","SRC_COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"WorldMatrix","WORLD_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"ExtraMatrix","EXTRA_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"ProjectionMatrix","PROJECTION_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN}, + //canvas item vertex out + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Vertex","VERTEX",".xy",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"UV","UV",".xy",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"PointSize","POINT_SIZE","",SLOT_TYPE_SCALAR,SLOT_OUT}, + //canvas item fragment in + {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Color","SRC_COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Alpha","SRC_COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"UV","vec3(UV,0)","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"UVScreen","vec3(SCREEN_UV,0)","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"TexPixelSize","vec3(TEXTURE_PIXEL_SIZE,0)","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"PointCoord","POINT_COORD","",SLOT_TYPE_VEC,SLOT_IN}, + //canvas item fragment out + {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_OUT}, + {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_OUT}, + //canvas item light in + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightDist","LIGHT_DISTANCE","",SLOT_TYPE_SCALAR,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightDir","vec3(LIGHT_DIR,0)","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"PointCoord","POINT_COORD","",SLOT_TYPE_VEC,SLOT_IN}, + //canvas item light out + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Light","LIGHT","",SLOT_TYPE_VEC,SLOT_OUT}, //end {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,NULL,NULL,NULL,SLOT_TYPE_SCALAR,SLOT_OUT}, @@ -1373,6 +1410,7 @@ const ShaderGraph::NodeSlotInfo ShaderGraph::node_slot_info[]= { {NODE_XFORM_INPUT,{SLOT_MAX},{SLOT_TYPE_XFORM,SLOT_MAX}}, // mat4 uniform (assignable in material) {NODE_TEXTURE_INPUT,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // texture input (assignable in material) {NODE_CUBEMAP_INPUT,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // cubemap input (assignable in material) + {NODE_DEFAULT_TEXTURE,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // cubemap input (assignable in material) {NODE_COMMENT,{SLOT_MAX},{SLOT_MAX}}, // comment {NODE_TYPE_MAX,{SLOT_MAX},{SLOT_MAX}} }; @@ -1731,6 +1769,11 @@ void ShaderGraph::_update_shader() { } else if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL) { if (name==("IN_NORMAL")) code[i]="vec3 IN_NORMAL=NORMAL;\n"+code[i]; + } else if (i==SHADER_TYPE_VERTEX && get_mode()==MODE_CANVAS_ITEM) { + if (name==("SRC_COLOR")) + code[i]="vec3 SRC_COLOR=COLOR.rgb;\n"+code[i]; + if (name==("SRC_UV")) + code[i]="vec3 SRC_UV=vec3(UV,0);\n"+code[i]; } } @@ -1747,6 +1790,10 @@ void ShaderGraph::_update_shader() { all_ok=false; } +/* print_line("VERTEX: \n"+code[0]); + print_line("FRAGMENT: \n"+code[1]); + print_line("LIGHT: \n"+code[2]);*/ + if (all_ok) { set_code(code[0],code[1],code[2]); } @@ -2372,7 +2419,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorid,1)+"="+rname+".a;\n"; } else { - + //not supported code += OUTNAME(p_node->id,0)+"=vec3(0,0,0);\n"; code += OUTNAME(p_node->id,1)+"=1.0;\n"; diff --git a/scene/resources/shader_graph.h b/scene/resources/shader_graph.h index ff2ca68335..5c34bedadd 100644 --- a/scene/resources/shader_graph.h +++ b/scene/resources/shader_graph.h @@ -406,7 +406,6 @@ VARIANT_ENUM_CAST( ShaderGraph::GraphError ); class MaterialShaderGraph : public ShaderGraph { OBJ_TYPE( MaterialShaderGraph, ShaderGraph ); - RES_BASE_EXTENSION("sgp"); public: @@ -416,4 +415,17 @@ public: } }; +class CanvasItemShaderGraph : public ShaderGraph { + + OBJ_TYPE( CanvasItemShaderGraph, ShaderGraph ); + +public: + + + CanvasItemShaderGraph() : ShaderGraph(MODE_CANVAS_ITEM) { + + } +}; + + #endif // SHADER_GRAPH_H diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 9a76a009a9..dfa0172e82 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -1112,6 +1112,7 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_vertex_builtins_defs[]={ { "SRC_VERTEX", TYPE_VEC2}, { "VERTEX", TYPE_VEC2}, + { "WORLD_VERTEX", TYPE_VEC2}, { "UV", TYPE_VEC2}, { "COLOR", TYPE_VEC4}, { "VAR1", TYPE_VEC4}, diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 005bb0958f..6ff16e661c 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -4035,7 +4035,8 @@ EditorNode::EditorNode() { add_editor_plugin( memnew( ScriptEditorPlugin(this) ) ); add_editor_plugin( memnew( EditorHelpPlugin(this) ) ); add_editor_plugin( memnew( AnimationPlayerEditorPlugin(this) ) ); - add_editor_plugin( memnew( ShaderGraphEditorPlugin(this) ) ); + add_editor_plugin( memnew( ShaderGraphEditorPlugin(this,true) ) ); + add_editor_plugin( memnew( ShaderGraphEditorPlugin(this,false) ) ); add_editor_plugin( memnew( ShaderEditorPlugin(this,true) ) ); add_editor_plugin( memnew( ShaderEditorPlugin(this,false) ) ); add_editor_plugin( memnew( CameraEditorPlugin(this) ) ); diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index 39508464c1..508e8b4cba 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -33,7 +33,7 @@ #include "scene/gui/panel.h" #include "spatial_editor_plugin.h" #include "os/keyboard.h" - +#include "canvas_item_editor_plugin.h" void GraphColorRampEdit::_input_event(const InputEvent& p_event) { @@ -2234,6 +2234,9 @@ void ShaderGraphEditor::_notification(int p_what) { if (i==ShaderGraph::NODE_OUTPUT) continue; + if (!_2d && i==ShaderGraph::NODE_DEFAULT_TEXTURE) + continue; + String nn = node_names[i]; String ic = nn.get_slice(":",0); String v = nn.get_slice(":",1); @@ -2297,7 +2300,8 @@ const char* ShaderGraphEditor::node_names[ShaderGraph::NODE_TYPE_MAX]={ }; -ShaderGraphEditor::ShaderGraphEditor() { +ShaderGraphEditor::ShaderGraphEditor(bool p_2d) { + _2d=p_2d; HBoxContainer *hbc = memnew( HBoxContainer ); menu = memnew( MenuButton ); @@ -2339,7 +2343,13 @@ void ShaderGraphEditorPlugin::edit(Object *p_object) { bool ShaderGraphEditorPlugin::handles(Object *p_object) const { - return p_object->is_type("ShaderGraph"); + ShaderGraph *shader=p_object->cast_to(); + if (!shader) + return false; + if (_2d) + return shader->get_mode()==Shader::MODE_CANVAS_ITEM; + else + return shader->get_mode()==Shader::MODE_MATERIAL; } void ShaderGraphEditorPlugin::make_visible(bool p_visible) { @@ -2353,12 +2363,16 @@ void ShaderGraphEditorPlugin::make_visible(bool p_visible) { } -ShaderGraphEditorPlugin::ShaderGraphEditorPlugin(EditorNode *p_node) { +ShaderGraphEditorPlugin::ShaderGraphEditorPlugin(EditorNode *p_node, bool p_2d) { + _2d=p_2d; editor=p_node; - shader_editor = memnew( ShaderGraphEditor ); + shader_editor = memnew( ShaderGraphEditor(p_2d) ); shader_editor->hide(); - SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor); + if (p_2d) + CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(shader_editor); + else + SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor); // editor->get_viewport()->add_child(shader_editor); diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h index c6fb2f82b1..1726302e90 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.h +++ b/tools/editor/plugins/shader_graph_editor_plugin.h @@ -191,6 +191,7 @@ class ShaderGraphEditor : public VBoxContainer { ShaderGraphView *graph_edits[ShaderGraph::SHADER_TYPE_MAX]; static const char* node_names[ShaderGraph::NODE_TYPE_MAX]; + bool _2d; void _add_node(int p_type); protected: void _notification(int p_what); @@ -198,13 +199,14 @@ protected: public: void edit(Ref p_shader); - ShaderGraphEditor(); + ShaderGraphEditor(bool p_2d); }; class ShaderGraphEditorPlugin : public EditorPlugin { OBJ_TYPE( ShaderGraphEditorPlugin, EditorPlugin ); + bool _2d; ShaderGraphEditor *shader_editor; EditorNode *editor; @@ -216,7 +218,7 @@ public: virtual bool handles(Object *p_node) const; virtual void make_visible(bool p_visible); - ShaderGraphEditorPlugin(EditorNode *p_node); + ShaderGraphEditorPlugin(EditorNode *p_node,bool p_2d); ~ShaderGraphEditorPlugin(); }; -- cgit v1.2.3 From da0d4e4dea021c1fc10549cd5374d1baca2e4006 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 20 Jan 2015 22:31:32 -0300 Subject: Fixes to texscreen, fixes to white testcube --- drivers/gles2/rasterizer_gles2.cpp | 19 +++++++++++++++---- scene/resources/shader_graph.cpp | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 4990e81f42..43bd45ae80 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -4957,12 +4957,22 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_ Material::UniformData ud; bool keep=true; //keep material value - bool has_old = old_mparams.has(E->key()); + + Map::Element *OLD=old_mparams.find(E->key()); + bool has_old = OLD; bool old_inuse=has_old && old_mparams[E->key()].inuse; if (!has_old || !old_inuse) keep=false; - else if (old_mparams[E->key()].value.get_type()!=E->value().default_value.get_type()) { + else if (OLD->get().value.get_type()!=E->value().default_value.get_type()) { + + if (OLD->get().value.get_type()==Variant::INT && E->get().type==ShaderLanguage::TYPE_FLOAT) { + //handle common mistake using shaders (feeding ints instead of float) + OLD->get().value=float(OLD->get().value); + keep=true; + } else if (E->value().default_value.get_type()!=Variant::NIL) { + keep=false; + } //type changed between old and new /* if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) { if (E->value().default_value.get_type()!=Variant::_RID) //hackfor textures @@ -4971,8 +4981,7 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_ keep=false;*/ //value is invalid because type differs and default is not null - if (E->value().default_value.get_type()!=Variant::NIL) - keep=false; + ; } ud.istexture=(E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP); @@ -5099,8 +5108,10 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material int texcoord=0; for (Map::Element *E=p_material->shader_params.front();E;E=E->next()) { + if (E->get().index<0) continue; +// print_line(String(E->key())+": "+E->get().value); if (E->get().istexture) { //clearly a texture.. RID rid = E->get().value; diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index 73812a7ae5..2630bc5bad 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -1790,7 +1790,7 @@ void ShaderGraph::_update_shader() { all_ok=false; } -/* print_line("VERTEX: \n"+code[0]); + /*print_line("VERTEX: \n"+code[0]); print_line("FRAGMENT: \n"+code[1]); print_line("LIGHT: \n"+code[2]);*/ @@ -1973,7 +1973,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vectorid,0)+"=TIME;\n"; }break; case NODE_SCREEN_TEX: { - code+=OUTNAME(p_node->id,0)+"=texscreen("+p_inputs[0]+");\n"; + code+=OUTNAME(p_node->id,0)+"=texscreen("+p_inputs[0]+".xy);\n"; }break; case NODE_SCALAR_OP: { int op = p_node->param1; -- cgit v1.2.3 From 14ade5500f091cd3d4e3668631fac49b1a4c546d Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 20 Jan 2015 23:58:47 -0300 Subject: Fixed bug in 3D material textures that failed to load should now load again properly --- drivers/gles2/rasterizer_gles2.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 43bd45ae80..2993fcfb58 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -4962,15 +4962,19 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_ bool has_old = OLD; bool old_inuse=has_old && old_mparams[E->key()].inuse; - if (!has_old || !old_inuse) + ud.istexture=(E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP); + + if (!has_old || !old_inuse) { keep=false; + } else if (OLD->get().value.get_type()!=E->value().default_value.get_type()) { if (OLD->get().value.get_type()==Variant::INT && E->get().type==ShaderLanguage::TYPE_FLOAT) { //handle common mistake using shaders (feeding ints instead of float) OLD->get().value=float(OLD->get().value); keep=true; - } else if (E->value().default_value.get_type()!=Variant::NIL) { + } else if (!ud.istexture && E->value().default_value.get_type()!=Variant::NIL) { + keep=false; } //type changed between old and new @@ -4984,7 +4988,6 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_ ; } - ud.istexture=(E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP); if (keep) { ud.value=old_mparams[E->key()].value; -- cgit v1.2.3 From c6eabbbec5a9fec7a0d473fe67a544af3454c3d2 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 21 Jan 2015 00:57:37 -0300 Subject: fixed world vertex issues in canvas item shader --- drivers/gles2/rasterizer_gles2.cpp | 2 +- drivers/gles2/shader_compiler_gles2.cpp | 14 +++++++------- tools/editor/plugins/shader_editor_plugin.cpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 2993fcfb58..5903be9d81 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -4588,7 +4588,7 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const { enablers.push_back("#define USE_TEXPIXEL_SIZE\n"); } - if (fragment_flags.uses_worldvec) { + if (vertex_flags.uses_worldvec) { enablers.push_back("#define USE_WORLD_VEC\n"); } canvas_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, light_code, fragment_globals,uniform_names,enablers); diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp index 9662ea0fa6..d8841d407e 100644 --- a/drivers/gles2/shader_compiler_gles2.cpp +++ b/drivers/gles2/shader_compiler_gles2.cpp @@ -226,6 +226,9 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a if (vnode->name==vname_var2_interp) { flags->use_var2_interp=true; } + if (vnode->name==vname_world_vec) { + uses_worldvec=true; + } } @@ -239,9 +242,6 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a if (vnode->name==vname_normal) { uses_normal=true; } - if (vnode->name==vname_world_vec) { - uses_worldvec=true; - } if (vnode->name==vname_screen_uv) { uses_screen_uv=true; @@ -310,13 +310,13 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a String mul_l=dump_node_code(onode->arguments[0],p_level,true); String mul_r=dump_node_code(onode->arguments[1],p_level); - code=mul_l+"=(vec4("+mul_l+",1.0,1.0)*("+mul_r+")).xy"; + code=mul_l+"=(vec4("+mul_l+",0.0,1.0)*("+mul_r+")).xy"; break; } else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT4 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC2) { String mul_l=dump_node_code(onode->arguments[0],p_level,true); String mul_r=dump_node_code(onode->arguments[1],p_level); - code=mul_l+"=(("+mul_l+")*vec4("+mul_r+",1.0,1.0)).xy"; + code=mul_l+"=(("+mul_l+")*vec4("+mul_r+",0.0,1.0)).xy"; break; } else if (onode->arguments[0]->get_datatype()==SL::TYPE_VEC2 && onode->arguments[1]->get_datatype()==SL::TYPE_MAT3) { String mul_l=dump_node_code(onode->arguments[0],p_level,true); @@ -346,11 +346,11 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a break; } else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT4 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC2) { - code="("+dump_node_code(onode->arguments[0],p_level)+"*vec4("+dump_node_code(onode->arguments[1],p_level)+",1.0,1.0)).xyz"; + code="("+dump_node_code(onode->arguments[0],p_level)+"*vec4("+dump_node_code(onode->arguments[1],p_level)+",0.0,1.0)).xy"; break; } else if (onode->arguments[0]->get_datatype()==SL::TYPE_VEC2 && onode->arguments[1]->get_datatype()==SL::TYPE_MAT4) { - code="(vec4("+dump_node_code(onode->arguments[0],p_level)+",1.0,1.0)*"+dump_node_code(onode->arguments[1],p_level)+").xyz"; + code="(vec4("+dump_node_code(onode->arguments[0],p_level)+",0.0,1.0)*"+dump_node_code(onode->arguments[1],p_level)+").xy"; break; } else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT3 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC2) { diff --git a/tools/editor/plugins/shader_editor_plugin.cpp b/tools/editor/plugins/shader_editor_plugin.cpp index 81b5cd8f78..2fcd4e8cd1 100644 --- a/tools/editor/plugins/shader_editor_plugin.cpp +++ b/tools/editor/plugins/shader_editor_plugin.cpp @@ -396,7 +396,7 @@ void ShaderEditor::edit(const Ref& p_shader) { light_editor->set_edited_shader(shader,ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT); } - vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX); + //vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX); // see if already has it -- cgit v1.2.3