godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Add Vertex Position as an output option in the Visual Shader Editor for Spatial shaders #10868

Open KingKrouch opened 1 month ago

KingKrouch commented 1 month ago

Describe the project you are working on

A 3D game where I'd like to have post-processing effects on the camera including inside of the editor.

Describe the problem or limitation you are having in your project

The Visual Shader editor's vertex shader view lacks a Position output. This makes it difficult to follow along with tutorials for advanced post-processing, as shown here: https://docs.godotengine.org/en/stable/tutorials/shaders/advanced_postprocessing.html#full-screen-quad

Someone advised me to attempt a workaround by using the TransformVectorMult node (plugged into the vertex output) with the inv_projection_matrix input as A, and the vertex input as B, but the issue with this method is that it causes strange clipping issues when meshes are too close to the post-processing plane.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add the position output to the vertex shader portion of the Visual Shader editor.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

The output section of the visual shader editor should have a position output, and if I did something like a Vector4Construct with vertex.x, vertex.y, 1.0f, 1.0f as inputs, it would be similar to what you can do with text-based shaders.

If this enhancement will not be used often, can it be worked around with a few lines of script?

As mentioned earlier, the only current workaround has some glaring problems with clipping issues.

Is there a reason why this should be core and not an add-on in the asset library?

This is a slight tweak to the core of the Visual Shader editor that will make Visual Shaders more in parity with text based shaders.

KingKrouch commented 1 month ago

Someone was able to help me find a workaround for this for the time being: image

tetrapod00 commented 1 month ago

I agree that POSITION and the other "advanced" outputs should be accessible somehow.

As for current workarounds, I recommend something like this instead. It compiles into equivalent code that actually writes to POSITION directly. For the passthrough variable, just pick any of the inout built-ins listed in the spatial shader built-in table (like UV, VERTEX, etc). As far as I know, you need the passthrough variable so that the contents of the expression node actually gets added to the final shader.

This example is equivalent to the snippet in Advanced Post-processing: Godot_v4 3-stable_win64_LhikO4RxNx