godotpost-processinggodot-shader-language

How to combine world environment post processing with custom post processing shader in a 3D world, Godot 4.0


I am trying to use the in-built post processing effects attached to a Camera3D while also applying a custom post processing effect to run in combination with the other effects.

I have read tutorials on how to create custom post processing effects, like the one found on the official docs. It tells me to create a MeshInstance with a QuadMesh (well, in Godot 4.0, it is actually now a PlaneMesh) and transform it into clip space.

For one, the transformation explained in the docs did not work, the quad just disappeared when I applied the following vertex shader and applied a large value to extra_cull_margin:

shader_type spatial;
render_mode cull_disabled, unshaded;

void vertex() {
    POSITION = vec4(VERTEX, 1.0); 
}

Then, I managed to work around this by actually manually rotating the plane such that it faces the camera and with a Z offset of something small but larger than the camera near field. Quad and Camera Camera view

The issue is that with this plane in front, none of the world environment post processing effects work. Now, I think it might work better if I get the transform working of the quad to clip space, but it doesn't work for me.

Has anyone tried this yet for Godot 4.0 beta 1?


Solution

  • Okay, so reading up on how to do this in general, I stumbled upon this question.

    Based on the answer from derhass, I wrote the following vertex shader code:

    shader_type spatial;
    render_mode cull_disabled, unshaded;
    
    const vec2 vertices[3] = {vec2(-1,-1), vec2(3,-1), vec2(-1, 3)};
    
    void vertex() {
        POSITION = vec4(vertices[VERTEX_ID],0.0,1.0);
    }
    

    This draws a triangle and it also transforms it successfully into clip space.

    Now the world environment effects are working together with the custom post processing shader:

    With shader

    Without shader