Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.6k views
in Technique[技术] by (71.8m points)

Godot visual shader copy code from fragment to vertex

Exactly what the title says. I don't even know if it's possible, cause I looked all over the internet for an answer.enter image description here

this is the image of the code I need to copy from fragment to vertex. Thanks in advance for answers, I don't want to rewrite it from scratch.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Before you mess with this, make sure you have saved a copy of your shader.


Option 1: A workaround completely inside Godot:

  1. Identify what input and output you need. Write that down.
  2. Open the resulting shading code (the last item in the toolbox).
  3. Copy the relevant code (If you don't know what part to cppy, consider to remove everything else, copy the fragment shader, then undo).
  4. Go to the vertex shader and add an expression node.
  5. Configure the node with the inputs and outputs you need…
  6. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...