diff options
author | Yuri Roubinsky <chaosus89@gmail.com> | 2019-08-20 21:11:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-20 21:11:28 +0300 |
commit | 093798c976373a664a8e274ae31774e8dcf2238a (patch) | |
tree | 2c63a1eca8fa45ac4c022962fdcabd5ff3e64fab /scene/resources | |
parent | 8d5b9694283e94a61dbce4d908d56b72fde79cb6 (diff) | |
parent | 1e3fb6d760b0b209ddbde189eab9698015212720 (diff) |
Fix preview for global expressions in visual shaders (#31505)
Fix preview for global expressions in visual shaders
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/visual_shader.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index f7d7c2d1bc..08ce47692c 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -612,6 +612,25 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port global_code += String() + "shader_type canvas_item;\n"; + String global_expressions; + for (int i = 0, index = 0; i < TYPE_MAX; i++) { + 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); + expr = expr.replace("\n", "\n\t"); + expr += "\n"; + global_expressions += expr; + } + } + } + + global_code += "\n"; + global_code += global_expressions; + //make it faster to go around through shader VMap<ConnectionKey, const List<Connection>::Element *> input_connections; VMap<ConnectionKey, const List<Connection>::Element *> output_connections; |