godotengine / godot-proposals

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

Add a shader type for compositor effects #10465

Open HexagonNico opened 2 months ago

HexagonNico commented 2 months ago

Describe the project you are working on

A 2D game that makes use of post-processing effects.

Describe the problem or limitation you are having in your project

Currently, the new Compositor feature allows users to add post-processing effects through a WorldEnvironment node, but applying a post-processing effect using a shader requires some additional configuration and precautions, as explained in The compositor tutorial.

This makes the new feature less convenient to use than the previously used approach of adding a ColorRect under a CanvasLayer that covers the entire screen (see the custom post-processing tutorial).

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

Add a post_processing shader type that can be used to create post-processing shaders that will be used in a ShaderCompositorEffect. This will allow users to add post-processing effect without needing a script to manipulate shader code.

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

Users will be able to create shaders dedicated to post processing with shader_type post_processing.

Example:

shader_type post_processing;

void main() {
    float gray = COLOR.r * 0.2125 + COLOR.g * 0.7154 + COLOR.b * 0.0721;
    COLOR.rgb = vec3(gray);
}

This type of shaders will be used in a ShaderCompositorEffect that can be used in a compositor. The user will then be able to assign a shader to the compositor effect.

compositor_proposal

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

It is possible to create compositors that use shaders, but it requires some additional steps and some boilerplate shader code. See https://docs.godotengine.org/en/stable/tutorials/rendering/compositor.html

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

This will allow shaders to be used as post processing effects out of the box.

Calinou commented 2 months ago