From 1e3fb6d760b0b209ddbde189eab9698015212720 Mon Sep 17 00:00:00 2001 From: Yuri Roubinski Date: Tue, 20 Aug 2019 19:34:09 +0300 Subject: Fix preview for global expressions in visual shaders --- scene/resources/visual_shader.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'scene/resources') 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::Element *E = graph[i].nodes.front(); E; E = E->next()) { + Ref global_expression = Object::cast_to(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::Element *> input_connections; VMap::Element *> output_connections; -- cgit v1.2.3