Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
高级后期处理¶
前言¶
本教程描述了一种在 Godot 中进行后期处理的高级方法。值得注意的是,它将解释如何编写使用深度缓冲区的后期处理着色器。你应该已经熟悉后期处理,特别是使用自定义后期处理教程中介绍的方法。
全屏四边形¶
One way to make custom post-processing effects is by using a viewport. However, there are two main drawbacks of using a Viewport:
无法访问深度缓冲区
在编辑器中看不到后期处理着色器的效果
To get around the limitation on using the depth buffer, use a MeshInstance3D with a QuadMesh primitive. This allows us to use a shader and to access the depth texture of the scene. Next, use a vertex shader to make the quad cover the screen at all times so that the post-processing effect will be applied at all times, including in the editor.
First, create a new MeshInstance3D and set its mesh to a QuadMesh. This creates
a quad centered at position (0, 0, 0)
with a width and height of 1
. Set
the width and height to 2
and enable Flip Faces. Right now, the quad
occupies a position in world space at the origin. However, we want it to move
with the camera so that it always covers the entire screen. To do this, we will
bypass the coordinate transforms that translate the vertex positions through the
difference coordinate spaces and treat the vertices as if they were already in
clip space.
The vertex shader expects coordinates to be output in clip space, which are coordinates
ranging from -1
at the left and bottom of the screen to 1
at the top and right
of the screen. This is why the QuadMesh needs to have