Before you mess with this, make sure you have saved a copy of your shader.
Option 1: A workaround completely inside Godot:
- Identify what input and output you need. Write that down.
- Open the resulting shading code (the last item in the toolbox).
- Copy the relevant code (If you don't know what part to cppy, consider to remove everything else, copy the fragment shader, then undo).
- Go to the vertex shader and add an expression node.
- Configure the node with the inputs and outputs you need…
- Paste your code there.
Option 2: A workaround outside Godot:
Save your visual shader as a ".tres" file. These are text resources (hence the extension). And you can open them with a text editor.
The .tres file looks like an INI file. Each category (defined with a title in brackets) is a resource. The first one defines the shader file, leave that alone.
After then first line you will find categories that say "sub_resource", each is a node. You don't need to touch those either.
Finally you find a category that says "resource". At the end you will find values that look like this:
nodes/frament/3/node = SubResource( 4 )
nodes/frament/3/position = Vector2( 356, 417.037 )
That is telling you that the fragment shader has a node with id 3
is at position ( 356, 417.037 )
in the graph (the information of the node is in the category with id 4
near the start of the file).
You want to replace "fragment" for "vertex". However, make sure to give them a different id to those already in vertex, or you will have an error when re-importing in Godot, and lost what you did. Remember that Godot re-imports automatically when you switch windows to it.
You will also find a line that looks something like this:
nodes/fragment/connections = PoolIntArray( 3, 0, 0, 1, 4, 1, 0, 0 )
Those are the links between nodes. Each 4 numbers are a link. So here we have two links. The numbers for a link are as follows:
- Source Node id
- Output index of the source node (0 is the first output)
- Target Node id (if it is 0, it means it connects to the output node of the shader)
- Input index of the target node (0 is the first input)
For example, 4, 1, 0, 0
means I am connecting the second output (1
) of the node with id 4
, to the first output of the shader (being a fragment shader, that is Albedo).
You will have to carefully edit those links (because remember that you also had to modify the ids to avoid conflict with whatever you had in the vertex shader). Consider not bothering to write the new links, and instead connect the nodes in Godot after re-importing.
I won't be surprised if this result in being more work than actually creating the nodes again in the vertex shader.
Option 3: Change the circumstances of the problem
Convert the visual shader to a regular shader, then you can simply copy the code (the option is at the end of the drop down of the Shader property of the ShaderMaterial in the inspector panel - which is on the right by default). Although, be aware that there is no conversion going back to a visual shader.
Option 4: Wait for Godot
You may consider writing a proposal for Godot on Github. All going well, it will be picked by the developers to add to a new version of Godot. Then you wait.