godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.78k stars 20.13k forks source link

Error in Visual Shader imported from Godot 3.5.1 to Godot4 with Texture->Texture2D Node when using Alpha-parameter #73397

Open opgjoh opened 1 year ago

opgjoh commented 1 year ago

Godot version

4.0rc2

System information

Windows 10

Issue description

It appears that under certain conditions, the import of a Visual Shader attached to a node in a Godot 3.5.1 project causes an error when opening the converted scene in Godot 4. The scene loads, but the resulting shader looks off:

It seems that the issue lies with the fact that in Godot 3, Texture offered both a "Color" and "Alpha" output, whereas in Godot 4, the latter is considered a component of the former (which makes perfect sense). Because of this, any connection from the "Alpha" output is now lost and, worse, there seems to be an error (see below). The error message suggests that it tries to connect the second (index=1) port, which was "Alpha" beforehand, which no longer exists.

  scene/resources/visual_shader.cpp:723 - Condition "g->nodes.has(p_id)" is true.
  scene/resources/visual_shader.cpp:723 - Condition "g->nodes.has(p_id)" is true.
  scene/resources/visual_shader.cpp:723 - Condition "g->nodes.has(p_id)" is true.
  scene/resources/visual_shader.cpp:723 - Condition "g->nodes.has(p_id)" is true.
  scene/resources/visual_shader.cpp:970 - Index p_from_port = 1 is out of bounds (g->nodes[p_from_node].node->get_expanded_output_port_count() = 1).

Here are screenshots of the Visual Shaders as they appear in my Demo-project. In the Godot 4-screenshot, I have moved the Nodes slightly to ensure they fit the screenshot, their positions were as imported (just their size is now different)

Look in Godot 3.5.1: VS_G3 VS in Godot 4.0 RC 2: VS_G4

Note that the whole Vector composing/Decomposing is not necessary for the bug to appear. I just forgot to remove that part before uploading my projects. I have tested it without them, and I still see the error.

Steps to reproduce

In Godot 3.5

In Godot 4.0

Minimal reproduction project

Here is the Godot 3.5.1 Project. When importing it in Godot 4, and then opening the scene "Demo.tscn", the error can be observed. VisualShaderImportToG4Bug.zip

In case the above link does not work for some reason, I have created a small public repository with the Godot 3.5 and Godot 4.0 Project ready :)

esaytee2 commented 1 year ago

Hi, I have similar problem and I found that for some reason, the curves which connect nodes are duplicated several times and the tres file of the shader bloats from 250KB to 120MB in my case.

I have this problem in 3.5.1

Sadly I was not able to figure out conditions to replicate. Btw here is the shader, if somebody wants to try it out. waterDepth_visualShader.zip