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.

霧著色器

Fog shaders are used to define how fog is added to (or subtracted from) a scene in a given area. Fog shaders are always used together with FogVolumes and volumetric fog. Fog shaders only have one processing function, the fog() function.

霧著色器的解析度取決於體積霧 froxel 網格的解析度。因此,霧著色器所能增加的細節層級會根據 FogVolume 與攝影機的距離而變化。

Fog shaders are a special form of compute shader that is called once for every froxel that is touched by an axis-aligned bounding box of the associated FogVolume. This means that froxels that just barely touch a given FogVolume will still be used.

內建變數

標記為 in 的值為唯讀。標記為 out 的值可寫入,但不一定有合理初始值。取樣器(sampler)無法寫入,因此未標記。

全域內建變數

全域內建變數可於任何地方使用,包括自訂函式中。

內建變數

說明

in float TIME

Global time since the engine has started, in seconds. It repeats after every 3,600 seconds (which can be changed with the rollover setting). It's affected by time_scale but not by pausing. If you need a TIME variable that is not affected by time scale, add your own global shader uniform and update it each frame.

in float PI

A PI constant (3.141592). The ratio of a circle's circumference to its diameter and the number of radians in a half turn.

in float TAU

A TAU constant (6.283185). Equivalent to PI * 2 and the number of radians in a full turn.

in float E

An E constant (2.718281). Euler's number, the base of the natural logarithm.

霧內建變數

所有霧體積(fog volume)的輸出值會彼此重疊。這使得 FogVolumes 能夠高效繪製,因為它們可以同時處理。

內建變數

說明

in vec3 WORLD_POSITION

目前 froxel 單元在世界座標中的位置。

in vec3 OBJECT_POSITION

目前 FogVolume 在世界座標中的中心位置。

in vec3 UVW

三維 UV,將 3D 紋理貼圖映射至目前的 FogVolume

in vec3 SIZE

shape 有設定大小時,目前 FogVolume 的尺寸。

in vec3 SDF

FogVolume 表面的有號距離場。於體積內為負,反之為正。

out vec3 ALBEDO

輸出基礎色值,會與光源互動產生最終顏色。僅在使用時會寫入至霧體積。

out float DENSITY

輸出密度值。可為負數,允許一個體積從另一個體積中減除。霧著色器必須使用密度,否則不會寫入任何數值。

out vec3 EMISSION

輸出發光色值,於光照階段加到顏色上產生最終顏色。僅在使用時會寫入至霧體積。