summaryrefslogtreecommitdiff
path: root/scene/resources/visual_shader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/visual_shader.cpp')
-rw-r--r--scene/resources/visual_shader.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index 18bb0ff01d..a1a23124a3 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -910,6 +910,48 @@ void VisualShader::replace_node(Type p_type, int p_id, const StringName &p_new_c
return;
}
VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instantiate(p_new_class));
+ VisualShaderNode *prev_vsn = g->nodes[p_id].node.ptr();
+
+ // Update connection data.
+ for (int i = 0; i < vsn->get_output_port_count(); i++) {
+ if (i < prev_vsn->get_output_port_count()) {
+ if (prev_vsn->is_output_port_connected(i)) {
+ vsn->set_output_port_connected(i, true);
+ }
+
+ if (prev_vsn->is_output_port_expandable(i) && prev_vsn->_is_output_port_expanded(i) && vsn->is_output_port_expandable(i)) {
+ vsn->_set_output_port_expanded(i, true);
+
+ int component_count = 0;
+ switch (prev_vsn->get_output_port_type(i)) {
+ case VisualShaderNode::PORT_TYPE_VECTOR_2D:
+ component_count = 2;
+ break;
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D:
+ component_count = 3;
+ break;
+ case VisualShaderNode::PORT_TYPE_VECTOR_4D:
+ component_count = 4;
+ break;
+ default:
+ break;
+ }
+
+ for (int j = 0; j < component_count; j++) {
+ int sub_port = i + 1 + j;
+
+ if (prev_vsn->is_output_port_connected(sub_port)) {
+ vsn->set_output_port_connected(sub_port, true);
+ }
+ }
+
+ i += component_count;
+ }
+ } else {
+ break;
+ }
+ }
+
vsn->connect("changed", callable_mp(this, &VisualShader::_queue_update));
g->nodes[p_id].node = Ref<VisualShaderNode>(vsn);
@@ -2884,6 +2926,7 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_4D, "quarter_res_color", "QUARTER_RES_COLOR" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SAMPLER, "radiance", "RADIANCE" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_2D, "screen_uv", "SCREEN_UV" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_4D, "fragcoord", "FRAGCOORD" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_2D, "sky_coords", "SKY_COORDS" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },