diff options
Diffstat (limited to 'scene/resources/visual_shader.cpp')
-rw-r--r-- | scene/resources/visual_shader.cpp | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 5637aaec9a..31d0fc2c9d 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -39,12 +39,10 @@ bool VisualShaderNode::is_simple_decl() const { } void VisualShaderNode::set_output_port_for_preview(int p_index) { - port_preview = p_index; } int VisualShaderNode::get_output_port_for_preview() const { - return port_preview; } @@ -85,7 +83,6 @@ Vector<StringName> VisualShaderNode::get_editable_properties() const { } Array VisualShaderNode::get_default_input_values() const { - Array ret; for (Map<int, Variant>::Element *E = default_input_values.front(); E; E = E->next()) { ret.push_back(E->key()); @@ -94,7 +91,6 @@ Array VisualShaderNode::get_default_input_values() const { return ret; } void VisualShaderNode::set_default_input_values(const Array &p_values) { - if (p_values.size() % 2 == 0) { for (int i = 0; i < p_values.size(); i += 2) { default_input_values[p_values[i + 0]] = p_values[i + 1]; @@ -113,7 +109,6 @@ String VisualShaderNode::get_input_port_default_hint(int p_port) const { } void VisualShaderNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_output_port_for_preview", "port"), &VisualShaderNode::set_output_port_for_preview); ClassDB::bind_method(D_METHOD("get_output_port_for_preview"), &VisualShaderNode::get_output_port_for_preview); @@ -225,7 +220,6 @@ String VisualShaderNodeCustom::get_output_port_name(int p_port) const { } String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - ERR_FAIL_COND_V(!get_script_instance(), ""); ERR_FAIL_COND_V(!get_script_instance()->has_method("_get_code"), ""); Array input_vars; @@ -264,7 +258,6 @@ String VisualShaderNodeCustom::generate_global_per_node(Shader::Mode p_mode, Vis } void VisualShaderNodeCustom::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_name")); BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_description")); BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_category")); @@ -445,7 +438,6 @@ bool VisualShader::is_node_connection(Type p_type, int p_from_node, int p_from_p const Graph *g = &graph[p_type]; for (const List<Connection>::Element *E = g->connections.front(); E; E = E->next()) { - if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) { return true; } @@ -460,7 +452,6 @@ bool VisualShader::is_nodes_connected_relatively(const Graph *p_graph, int p_nod const VisualShader::Node &node = p_graph->nodes[p_node]; for (const List<int>::Element *E = node.prev_connected_nodes.front(); E; E = E->next()) { - if (E->get() == p_target) { return true; } @@ -474,7 +465,6 @@ bool VisualShader::is_nodes_connected_relatively(const Graph *p_graph, int p_nod } bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) const { - ERR_FAIL_INDEX_V(p_type, TYPE_MAX, false); const Graph *g = &graph[p_type]; @@ -501,7 +491,6 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po } for (const List<Connection>::Element *E = g->connections.front(); E; E = E->next()) { - if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) { return false; } @@ -546,7 +535,6 @@ Error VisualShader::connect_nodes(Type p_type, int p_from_node, int p_from_port, ERR_FAIL_COND_V_MSG(!is_port_types_compatible(from_port_type, to_port_type), ERR_INVALID_PARAMETER, "Incompatible port types (scalar/vec/bool) with transform."); for (List<Connection>::Element *E = g->connections.front(); E; E = E->next()) { - if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) { ERR_FAIL_V(ERR_ALREADY_EXISTS); } @@ -569,7 +557,6 @@ void VisualShader::disconnect_nodes(Type p_type, int p_from_node, int p_from_por Graph *g = &graph[p_type]; for (List<Connection>::Element *E = g->connections.front(); E; E = E->next()) { - if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) { g->connections.erase(E); g->nodes[p_to_node].prev_connected_nodes.erase(p_from_node); @@ -615,9 +602,7 @@ void VisualShader::set_mode(Mode p_mode) { flags.clear(); shader_mode = p_mode; for (int i = 0; i < TYPE_MAX; i++) { - for (Map<int, Node>::Element *E = graph[i].nodes.front(); E; E = E->next()) { - Ref<VisualShaderNodeInput> input = E->get().node; if (input.is_valid()) { input->shader_mode = shader_mode; @@ -630,7 +615,6 @@ void VisualShader::set_mode(Mode p_mode) { // clear connections since they are no longer valid for (List<Connection>::Element *E = graph[i].connections.front(); E;) { - bool keep = true; List<Connection>::Element *N = E->next(); @@ -684,7 +668,6 @@ bool VisualShader::is_text_shader() const { } String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port, Vector<DefaultTextureParam> &default_tex_params) const { - Ref<VisualShaderNode> node = get_node(p_type, p_node); ERR_FAIL_COND_V(!node.is_valid(), String()); ERR_FAIL_COND_V(p_port < 0 || p_port >= node->get_output_port_count(), String()); @@ -703,7 +686,6 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port for (Map<int, Node>::Element *E = graph[i].nodes.front(); E; E = E->next()) { Ref<VisualShaderNodeGlobalExpression> global_expression = Object::cast_to<VisualShaderNodeGlobalExpression>(E->get().node.ptr()); if (global_expression.is_valid()) { - String expr = ""; expr += "// " + global_expression->get_caption() + ":" + itos(index++) + "\n"; expr += global_expression->generate_global(get_mode(), Type(i), -1); @@ -772,7 +754,6 @@ String VisualShader::validate_port_name(const String &p_name, const List<String> } if (name != String()) { - String valid_name; for (int i = 0; i < name.length(); i++) { @@ -813,13 +794,11 @@ String VisualShader::validate_port_name(const String &p_name, const List<String> } String VisualShader::validate_uniform_name(const String &p_name, const Ref<VisualShaderNodeUniform> &p_uniform) const { - String name = p_name; //validate name first while (name.length() && !IS_INITIAL_CHAR(name[0])) { name = name.substr(1, name.length() - 1); } if (name != String()) { - String valid_name; for (int i = 0; i < name.length(); i++) { @@ -840,7 +819,6 @@ String VisualShader::validate_uniform_name(const String &p_name, const Ref<Visua int attempt = 1; while (true) { - bool exists = false; for (int i = 0; i < TYPE_MAX; i++) { for (const Map<int, Node>::Element *E = graph[i].nodes.front(); E; E = E->next()) { @@ -890,7 +868,6 @@ static const char *type_string[VisualShader::TYPE_MAX] = { "light" }; bool VisualShader::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name; if (name == "mode") { set_mode(Shader::Mode(int(p_value))); @@ -927,7 +904,6 @@ bool VisualShader::_set(const StringName &p_name, const Variant &p_value) { String index = name.get_slicec('/', 2); if (index == "connections") { - Vector<int> conns = p_value; if (conns.size() % 4 == 0) { for (int i = 0; i < conns.size(); i += 4) { @@ -964,7 +940,6 @@ bool VisualShader::_set(const StringName &p_name, const Variant &p_value) { } bool VisualShader::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name; if (name == "mode") { r_ret = get_mode(); @@ -993,7 +968,6 @@ bool VisualShader::_get(const StringName &p_name, Variant &r_ret) const { String index = name.get_slicec('/', 2); if (index == "connections") { - Vector<int> conns; for (const List<Connection>::Element *E = graph[type].connections.front(); E; E = E->next()) { conns.push_back(E->get().from_node); @@ -1074,13 +1048,11 @@ void VisualShader::_get_property_list(List<PropertyInfo> *p_list) const { for (int i = 0; i < TYPE_MAX; i++) { for (Map<int, Node>::Element *E = graph[i].nodes.front(); E; E = E->next()) { - String prop_name = "nodes/"; prop_name += type_string[i]; prop_name += "/" + itos(E->key()); if (E->key() != NODE_ID_OUTPUT) { - p_list->push_back(PropertyInfo(Variant::OBJECT, prop_name + "/node", PROPERTY_HINT_RESOURCE_TYPE, "VisualShaderNode", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE)); } p_list->push_back(PropertyInfo(Variant::VECTOR2, prop_name + "/position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); @@ -1099,7 +1071,6 @@ void VisualShader::_get_property_list(List<PropertyInfo> *p_list) const { } Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBuilder &global_code_per_node, Map<Type, StringBuilder> &global_code_per_func, StringBuilder &code, Vector<VisualShader::DefaultTextureParam> &def_tex_params, const VMap<ConnectionKey, const List<Connection>::Element *> &input_connections, const VMap<ConnectionKey, const List<Connection>::Element *> &output_connections, int node, Set<int> &processed, bool for_preview, Set<StringName> &r_classes) const { - const Ref<VisualShaderNode> vsnode = graph[type].nodes[node].node; //check inputs recursively first @@ -1181,7 +1152,6 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui inputs[i] = "int(" + src_var + ")"; } } else { - Variant defval = vsnode->get_input_port_default_value(i); if (defval.get_type() == Variant::FLOAT) { float val = defval; @@ -1283,7 +1253,6 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui bool skip_global = input.is_valid() && for_preview; if (!skip_global) { - global_code += vsnode->generate_global(get_mode(), type, node); String class_name = vsnode->get_class_name(); @@ -1330,11 +1299,8 @@ void VisualShader::_update_shader() const { //fill render mode enums int idx = 0; while (render_mode_enums[idx].string) { - if (shader_mode == render_mode_enums[idx].mode) { - if (modes.has(render_mode_enums[idx].string)) { - int which = modes[render_mode_enums[idx].string]; int count = 0; for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode)).size(); i++) { @@ -1357,7 +1323,6 @@ void VisualShader::_update_shader() const { //fill render mode flags for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode)).size(); i++) { - String mode = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode))[i]; if (flags.has(mode)) { if (render_mode != String()) { @@ -1369,7 +1334,6 @@ void VisualShader::_update_shader() const { } if (render_mode != String()) { - global_code += "render_mode " + render_mode + ";\n\n"; } @@ -1377,7 +1341,6 @@ void VisualShader::_update_shader() const { String global_expressions; for (int i = 0, index = 0; i < TYPE_MAX; i++) { - if (!ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader_mode)).has(func_name[i])) { continue; } @@ -1385,7 +1348,6 @@ void VisualShader::_update_shader() const { for (Map<int, Node>::Element *E = graph[i].nodes.front(); E; E = E->next()) { Ref<VisualShaderNodeGlobalExpression> global_expression = Object::cast_to<VisualShaderNodeGlobalExpression>(E->get().node.ptr()); if (global_expression.is_valid()) { - String expr = ""; expr += "// " + global_expression->get_caption() + ":" + itos(index++) + "\n"; expr += global_expression->generate_global(get_mode(), Type(i), -1); @@ -1397,7 +1359,6 @@ void VisualShader::_update_shader() const { } for (int i = 0; i < TYPE_MAX; i++) { - if (!ShaderTypes::get_singleton()->get_functions(RenderingServer::ShaderMode(shader_mode)).has(func_name[i])) { continue; } @@ -1483,7 +1444,6 @@ void VisualShader::rebuild() { } void VisualShader::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mode", "mode"), &VisualShader::set_mode); ClassDB::bind_method(D_METHOD("add_node", "type", "node", "position", "id"), &VisualShader::add_node); @@ -1762,24 +1722,19 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::preview_ports[] = { }; int VisualShaderNodeInput::get_input_port_count() const { - return 0; } VisualShaderNodeInput::PortType VisualShaderNodeInput::get_input_port_type(int p_port) const { - return PORT_TYPE_SCALAR; } String VisualShaderNodeInput::get_input_port_name(int p_port) const { - return ""; } int VisualShaderNodeInput::get_output_port_count() const { - return 1; } VisualShaderNodeInput::PortType VisualShaderNodeInput::get_output_port_type(int p_port) const { - return get_input_type_by_name(input_name); } String VisualShaderNodeInput::get_output_port_name(int p_port) const { @@ -1791,7 +1746,6 @@ String VisualShaderNodeInput::get_caption() const { } String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - if (get_output_port_type(0) == PORT_TYPE_SAMPLER) { return ""; } @@ -1868,7 +1822,6 @@ String VisualShaderNodeInput::get_input_name() const { } String VisualShaderNodeInput::get_input_real_name() const { - int idx = 0; while (ports[idx].mode != Shader::MODE_MAX) { @@ -1882,7 +1835,6 @@ String VisualShaderNodeInput::get_input_real_name() const { } VisualShaderNodeInput::PortType VisualShaderNodeInput::get_input_type_by_name(String p_name) const { - int idx = 0; while (ports[idx].mode != Shader::MODE_MAX) { @@ -1944,7 +1896,6 @@ String VisualShaderNodeInput::get_input_index_name(int p_index) const { } void VisualShaderNodeInput::_validate_property(PropertyInfo &property) const { - if (property.name == "input_name") { String port_list; @@ -1974,7 +1925,6 @@ Vector<StringName> VisualShaderNodeInput::get_editable_properties() const { } void VisualShaderNodeInput::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_input_name", "name"), &VisualShaderNodeInput::set_input_name); ClassDB::bind_method(D_METHOD("get_input_name"), &VisualShaderNodeInput::get_input_name); ClassDB::bind_method(D_METHOD("get_input_real_name"), &VisualShaderNodeInput::get_input_real_name); @@ -2060,7 +2010,6 @@ const VisualShaderNodeOutput::Port VisualShaderNodeOutput::ports[] = { }; int VisualShaderNodeOutput::get_input_port_count() const { - int idx = 0; int count = 0; @@ -2075,7 +2024,6 @@ int VisualShaderNodeOutput::get_input_port_count() const { } VisualShaderNodeOutput::PortType VisualShaderNodeOutput::get_input_port_type(int p_port) const { - int idx = 0; int count = 0; @@ -2093,7 +2041,6 @@ VisualShaderNodeOutput::PortType VisualShaderNodeOutput::get_input_port_type(int } String VisualShaderNodeOutput::get_input_port_name(int p_port) const { - int idx = 0; int count = 0; @@ -2115,7 +2062,6 @@ Variant VisualShaderNodeOutput::get_input_port_default_value(int p_port) const { } int VisualShaderNodeOutput::get_output_port_count() const { - return 0; } VisualShaderNodeOutput::PortType VisualShaderNodeOutput::get_output_port_type(int p_port) const { @@ -2126,7 +2072,6 @@ String VisualShaderNodeOutput::get_output_port_name(int p_port) const { } bool VisualShaderNodeOutput::is_port_separator(int p_index) const { - if (shader_mode == Shader::MODE_SPATIAL && shader_type == VisualShader::TYPE_FRAGMENT) { String name = get_input_port_name(p_index); return (name == "Normal" || name == "Rim" || name == "Alpha Scissor"); @@ -2139,14 +2084,12 @@ String VisualShaderNodeOutput::get_caption() const { } String VisualShaderNodeOutput::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - int idx = 0; int count = 0; String code; while (ports[idx].mode != Shader::MODE_MAX) { if (ports[idx].mode == shader_mode && ports[idx].shader_type == shader_type) { - if (p_input_vars[count] != String()) { String s = ports[idx].string; if (s.find(":") != -1) { @@ -2188,7 +2131,6 @@ VisualShaderNodeUniform::Qualifier VisualShaderNodeUniform::get_qualifier() cons } void VisualShaderNodeUniform::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_uniform_name", "name"), &VisualShaderNodeUniform::set_uniform_name); ClassDB::bind_method(D_METHOD("get_uniform_name"), &VisualShaderNodeUniform::get_uniform_name); @@ -2218,7 +2160,6 @@ String VisualShaderNodeUniform::_get_qual_str() const { } String VisualShaderNodeUniform::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const { - List<String> keyword_list; ShaderLanguage::get_keyword_list(&keyword_list); if (keyword_list.find(uniform_name)) { @@ -2256,7 +2197,6 @@ Vector2 VisualShaderNodeGroupBase::get_size() const { } void VisualShaderNodeGroupBase::set_inputs(const String &p_inputs) { - if (inputs == p_inputs) return; @@ -2269,7 +2209,6 @@ void VisualShaderNodeGroupBase::set_inputs(const String &p_inputs) { int input_port_count = input_strings.size(); for (int i = 0; i < input_port_count; i++) { - Vector<String> arr = input_strings[i].split(","); ERR_FAIL_COND(arr.size() != 3); @@ -2289,7 +2228,6 @@ String VisualShaderNodeGroupBase::get_inputs() const { } void VisualShaderNodeGroupBase::set_outputs(const String &p_outputs) { - if (outputs == p_outputs) return; @@ -2302,7 +2240,6 @@ void VisualShaderNodeGroupBase::set_outputs(const String &p_outputs) { int output_port_count = output_strings.size(); for (int i = 0; i < output_port_count; i++) { - Vector<String> arr = output_strings[i].split(","); ERR_FAIL_COND(arr.size() != 3); @@ -2339,7 +2276,6 @@ bool VisualShaderNodeGroupBase::is_valid_port_name(const String &p_name) const { } void VisualShaderNodeGroupBase::add_input_port(int p_id, int p_type, const String &p_name) { - String str = itos(p_id) + "," + itos(p_type) + "," + p_name + ";"; Vector<String> inputs_strings = inputs.split(";", false); int index = 0; @@ -2376,7 +2312,6 @@ void VisualShaderNodeGroupBase::add_input_port(int p_id, int p_type, const Strin } void VisualShaderNodeGroupBase::remove_input_port(int p_id) { - ERR_FAIL_COND(!has_input_port(p_id)); Vector<String> inputs_strings = inputs.split(";", false); @@ -2409,7 +2344,6 @@ bool VisualShaderNodeGroupBase::has_input_port(int p_id) const { } void VisualShaderNodeGroupBase::add_output_port(int p_id, int p_type, const String &p_name) { - String str = itos(p_id) + "," + itos(p_type) + "," + p_name + ";"; Vector<String> outputs_strings = outputs.split(";", false); int index = 0; @@ -2446,7 +2380,6 @@ void VisualShaderNodeGroupBase::add_output_port(int p_id, int p_type, const Stri } void VisualShaderNodeGroupBase::remove_output_port(int p_id) { - ERR_FAIL_COND(!has_output_port(p_id)); Vector<String> outputs_strings = outputs.split(";", false); @@ -2487,7 +2420,6 @@ void VisualShaderNodeGroupBase::clear_output_ports() { } void VisualShaderNodeGroupBase::set_input_port_type(int p_id, int p_type) { - ERR_FAIL_COND(!has_input_port(p_id)); ERR_FAIL_COND(p_type < 0 || p_type >= PORT_TYPE_MAX); @@ -2522,7 +2454,6 @@ VisualShaderNodeGroupBase::PortType VisualShaderNodeGroupBase::get_input_port_ty } void VisualShaderNodeGroupBase::set_input_port_name(int p_id, const String &p_name) { - ERR_FAIL_COND(!has_input_port(p_id)); ERR_FAIL_COND(!is_valid_port_name(p_name)); @@ -2557,7 +2488,6 @@ String VisualShaderNodeGroupBase::get_input_port_name(int p_id) const { } void VisualShaderNodeGroupBase::set_output_port_type(int p_id, int p_type) { - ERR_FAIL_COND(!has_output_port(p_id)); ERR_FAIL_COND(p_type < 0 || p_type >= PORT_TYPE_MAX); @@ -2592,7 +2522,6 @@ VisualShaderNodeGroupBase::PortType VisualShaderNodeGroupBase::get_output_port_t } void VisualShaderNodeGroupBase::set_output_port_name(int p_id, const String &p_name) { - ERR_FAIL_COND(!has_output_port(p_id)); ERR_FAIL_COND(!is_valid_port_name(p_name)); @@ -2644,7 +2573,6 @@ Control *VisualShaderNodeGroupBase::get_control(int p_index) { } void VisualShaderNodeGroupBase::_apply_port_changes() { - Vector<String> inputs_strings = inputs.split(";", false); Vector<String> outputs_strings = outputs.split(";", false); @@ -2680,7 +2608,6 @@ bool VisualShaderNodeGroupBase::is_editable() const { } void VisualShaderNodeGroupBase::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_size", "size"), &VisualShaderNodeGroupBase::set_size); ClassDB::bind_method(D_METHOD("get_size"), &VisualShaderNodeGroupBase::get_size); @@ -2742,7 +2669,6 @@ String VisualShaderNodeExpression::get_expression() const { } String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - String _expression = expression; _expression = _expression.insert(0, "\n"); @@ -2842,7 +2768,6 @@ String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShad } void VisualShaderNodeExpression::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_expression", "expression"), &VisualShaderNodeExpression::set_expression); ClassDB::bind_method(D_METHOD("get_expression"), &VisualShaderNodeExpression::get_expression); |