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.

空間著色器

Spatial shaders are used for shading 3D objects. They are the most complex type of shader Godot offers. Spatial shaders are highly configurable with different render modes and different rendering options (e.g. Subsurface Scattering, Transmission, Ambient Occlusion, Rim lighting, etc.). Users can optionally write vertex, fragment, and light processor functions to affect how objects are drawn.

算繪模式

這些算繪模式的視覺範例,請參見 Standard Material 3D 與 ORM Material 3D

算繪模式

說明

blend_mix

混合混合模式(Alpha 為透明度),預設。

blend_add

加法混合模式。

blend_sub

減法混合模式。

blend_mul

乘法混合模式。

blend_premul_alpha

預乘 Alpha 混合模式(完全透明時為加法,完全不透明時為混合模式)。

depth_draw_opaque

僅繪製不透明幾何體的深度(不含透明部分)。

depth_draw_always

始終繪製深度(不透明與透明物件均包含)。

depth_draw_never

不繪製深度。

depth_prepass_alpha

對透明幾何體進行不透明的深度預處理。

depth_test_disabled

停用深度測試。

depth_test_default

Depth test will discard the pixel if it is behind other pixels. In Forward+ only, the pixel is also discarded if it's at the exact same depth as another pixel.

depth_test_inverted

Depth test will discard the pixel if it is in front of other pixels. Useful for stencil effects.

sss_mode_skin

皮膚用的次表面散射模式(最佳化人類皮膚的視覺效果,例如加強紅色通道)。

cull_back

剔除背面(預設)。

cull_front

剔除正面。

cull_disabled

停用剔除(雙面渲染)。

unshaded

僅顯示反照率,不進行任何燈光或陰影計算,提升渲染效能。

wireframe

Geometry draws using lines (useful for troubleshooting). When using the Compatibility renderer, you must call RenderingServer.set_debug_generate_wireframes(true) before the mesh is loaded for wireframe rendering to work. In the Compatibility renderer, backface culling is always disabled in wireframe mode, while in the Forward+ and Mobile renderers, the cull mode is respected.

debug_shadow_splits

方向性陰影的每個分割區會以不同顏色繪製(方便除錯)。

diffuse_burley

漫反射使用 Burley(迪士尼 PBS,預設)。

diffuse_lambert

漫反射使用 Lambert 著色。

diffuse_lambert_wrap

漫反射使用 Lambert Wrap 著色(依粗糙度變化)。

diffuse_toon

漫反射使用卡通著色。

specular_schlick_ggx

直接光鏡面反射使用 Schlick-GGX(預設)。

specular_toon

直接光鏡面反射使用卡通著色。

specular_disabled

停用直接光的鏡面高光,不影響反射光(如需完全停用請使用 SPECULAR = 0.0)。

skip_vertex_transform

VERTEXNORMALTANGENTBITANGENT 需要在 vertex() 函式中手動進行轉換。

world_vertex_coords

VERTEXNORMALTANGENTBITANGENT 會在世界空間(而非模型空間)下被修改。

ensure_correct_normals

當網格有非均勻縮放時使用(註:目前尚未實作)。

shadows_disabled

停用著色器中的陰影運算。該著色器不會接收陰影,但仍可投射陰影。

ambient_light_disabled

停用環境光與輻射圖的影響。

shadow_to_opacity

光照會調整 Alpha,使陰影區域不透明、無陰影區域透明。適合用於 AR 場景將陰影融合在相機畫面上。

vertex_lighting

使用頂點光照(取代逐像素光照)。

particle_trails

Enables the trails when used on particle geometry.

alpha_to_coverage

Alpha 抗鋸齒模式,詳見 此連結

alpha_to_coverage_and_one

Alpha 抗鋸齒模式,詳見 此連結

fog_disabled

停用基於深度或體積的霧氣接收。對於如粒子的 blend_add 材質很有用。

Stencil modes

備註

Stencil support is experimental, use at your own risk. We will try to not break compatibility as much as possible, but if significant flaws are found in the API, it may change in the next minor version.

Stencil operations are a set of operations that allow writing to an efficient buffer in an hardware-accelerated manner. This is generally used to mask in or out parts of the scene.

Some of the most well-known uses are:

  • Outlines: Mask out the inner mesh that is being outlined to avoid inner outlines.

  • X-Ray: Display a mesh behind other objects.

  • Portals: Draw geometry that is normally "impossible" (non-Euclidian) by masking objects.

備註

You can only read from the stencil buffer in the transparent pass. Any attempt to read in the opaque pass will fail, as it's currently not supported behavior.

Note that for compositor effects, the main renderer's stencil buffer can't be copied to a custom texture.

Stencil mode

說明

read

Read from the stencil buffer.

write

Write reference value to the stencil buffer.

write_if_depth_fail

Write reference value to the stencil buffer if the depth test fails.

compare_always

Always pass stencil test.

compare_equal

Pass stencil test if the reference value is equal to the stencil buffer value.

compare_not_equal

Pass stencil test if the reference value is not equal to the stencil buffer value.

compare_less

Pass stencil test if the reference value is less than the stencil buffer value.

compare_less_or_equal

Pass stencil test if the reference value is less than or equal to the stencil buffer value.

compare_greater

Pass stencil test if the reference value is greater than the stencil buffer value.

compare_greater_or_equal

Pass stencil test if the reference value is greater than or equal to the stencil buffer value.

內建變數

標記為 in 的值為唯讀。標記為 out 的值可以選擇寫入,且不一定包含合理的預設值。標記為 inout 的值則有預設值,可以選擇寫入。取樣器(sampler)無法寫入,因此未標註。

並非所有內建變數都能在所有處理函式中使用。若要在 fragment() 函式中存取頂點階段內建變數,可以利用 varying。同理,若需在 light() 函式中存取片段階段的內建變數,也請使用 varying。

全域內建變數

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

內建變數

說明

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.

in bool OUTPUT_IS_SRGB

當輸出處於 sRGB 色彩空間時為 true``(相容性算繪器為 ``true,Forward+ 與行動端為 false)。

in float CLIP_SPACE_FAR

裁剪空間的遠端 z 值。在 Forward+ 或行動算繪器中為 0.0,在相容性算繪器中為 -1.0。

in bool IS_MULTIVIEW

true when output is stereoscopic (XR), false when output is monoscopic.

in bool IN_SHADOW_PASS

true when the shader is being rendered in a shadow mapping pass, false otherwise. This can be used to render objects differently in shadow maps compared to their regular rendering.

頂點階段內建變數

頂點資料(VERTEXNORMALTANGENTBITANGENT)預設以模型(本地)空間表示。若未對這些變數寫入,將直接傳遞並在之後自動轉換為視圖空間給 fragment() 使用。

啟用 world_vertex_coords 算繪模式時,這些值可選擇以世界空間表示。

使用者可停用內建的 modelview 變換(投影仍會在後續進行),並自行於 shader 內進行如下轉換:

shader_type spatial;
render_mode skip_vertex_transform;

void vertex() {
    VERTEX = (MODELVIEW_MATRIX * vec4(VERTEX, 1.0)).xyz;
    NORMAL = normalize((MODELVIEW_MATRIX * vec4(NORMAL, 0.0)).xyz);
    BINORMAL = normalize((MODELVIEW_MATRIX * vec4(BINORMAL, 0.0)).xyz);
    TANGENT = normalize((MODELVIEW_MATRIX * vec4(TANGENT, 0.0)).xyz);
}

其他內建變數如 UVUV2COLOR,若未於頂點階段修改,亦會自動傳遞至 fragment() 階段。

使用者可透過寫入 POSITION 內建變數來覆蓋模型視圖與投影轉換。只要 shader 任何地方有寫入 POSITION,就會以該值為主,使用者需確保它始終有效。當 POSITION 被使用時,VERTEX 的值會被忽略且不進行投影,但傳遞至 fragment shader 的插值仍來自 VERTEX

在產生實體(instancing)時,INSTANCE_CUSTOM 變數包含自訂實例資料。用於粒子時內容通常如下:

  • x:旋轉角度,單位為弧度。

  • y:生命週期進度階段(0.0 ~ 1.0)。

  • z:動畫影格索引。

This allows you to easily adjust the shader to a particle system using default particle material. When writing a custom particle shader, this value can be used as desired.

內建變數

說明

in vec2 VIEWPORT_SIZE

視窗大小(像素)。

in mat4 VIEW_MATRIX

世界空間到視圖空間的轉換。

in mat4 INV_VIEW_MATRIX

視圖空間到世界空間的轉換。

in mat4 MAIN_CAM_INV_VIEW_MATRIX

View space to world space transform of the camera used to draw the current viewport.

in mat4 INV_PROJECTION_MATRIX

裁剪空間到視圖空間的轉換。

in vec3 NODE_POSITION_WORLD

節點位置(世界空間)。

in vec3 NODE_POSITION_VIEW

節點位置(視圖空間)。

in vec3 CAMERA_POSITION_WORLD

Camera position, in world space. Represents the midpoint of the two eyes when in multiview/stereo rendering.

in vec3 CAMERA_DIRECTION_WORLD

相機方向(世界空間)。

in uint CAMERA_VISIBLE_LAYERS

目前算繪通道的相機可見圖層遮罩。

in int INSTANCE_ID

產生實體(instancing)時的實例 ID。

in vec4 INSTANCE_CUSTOM

自訂實體資料(主要用於粒子)。

in int VIEW_INDEX

目前算繪的視圖。 VIEW_MONO_LEFT0 )用於單視圖或左眼, VIEW_RIGHT1 )用於右眼。

in int VIEW_MONO_LEFT

單視圖或左眼用常數,值永遠為 0。

in int VIEW_RIGHT

右眼用常數,值永遠為 1。

in vec3 EYE_OFFSET

Position offset for the eye being rendered, in view space. Only applicable for multiview rendering.

inout vec3 VERTEX

頂點位置(模型空間)。如啟用 world_vertex_coords 則為世界空間。

in int VERTEX_ID

目前頂點在頂點緩衝區中的索引。

inout vec3 NORMAL

法線向量(模型空間),若啟用 world_vertex_coords 則為世界空間。

inout vec3 TANGENT

切線向量(模型空間),如啟用 world_vertex_coords 則為世界空間。

inout vec3 BINORMAL

副法線向量(模型空間),如啟用 world_vertex_coords 則為世界空間。

out vec4 POSITION

If written to on any branch, overrides final vertex position in clip space.

inout vec2 UV

UV 主通道。

inout vec2 UV2

UV2 次通道。

inout vec4 COLOR

Color from vertices. Limited to values between 0.0 and 1.0 for each channel and 8 bits per channel precision (256 possible levels). Alpha channel is supported. Values outside the allowed range are clamped, and values may be rounded due to precision limitations. Use CUSTOM0-CUSTOM3 to pass data with more precision if needed.

out float ROUGHNESS

頂點光照用的粗糙度。

inout float POINT_SIZE

點算繪時的點大小。

inout mat4 MODELVIEW_MATRIX

模型(本地)空間到視圖空間的轉換(建議使用)。

inout mat3 MODELVIEW_NORMAL_MATRIX

in mat4 MODEL_MATRIX

模型(本地)空間到世界空間的轉換。

in mat3 MODEL_NORMAL_MATRIX

inout mat4 PROJECTION_MATRIX

視圖空間到裁剪空間的轉換。

in uvec4 BONE_INDICES

in vec4 BONE_WEIGHTS

in vec4 CUSTOM0

來自頂點原始資料的自訂值。若使用額外 UV,xy 對應 UV3,zw 對應 UV4。

in vec4 CUSTOM1

來自頂點原始資料的自訂值。若使用額外 UV,xy 對應 UV5,zw 對應 UV6。

in vec4 CUSTOM2

來自頂點原始資料的自訂值。若使用額外 UV,xy 對應 UV7,zw 對應 UV8。

in vec4 CUSTOM3

來自頂點原始資料的自訂值。

out float Z_CLIP_SCALE

If written to on any branch, scales the vertex towards the camera to avoid clipping into things like walls. Lighting and shadows will continue to work correctly when this is written to, but screen-space effects like SSAO and SSR may break with lower scales. Try to keep this value as close to 1.0 as possible.

備註

MODELVIEW_MATRIX 結合了 WORLD_MATRIXINV_CAMERA_MATRIX,更適合可能會造成浮點數問題的場合。例如,如果物件距離世界原點非常遠,那麼使用單獨的 WORLD_MATRIXINV_CAMERA_MATRIX 可能就會遇到浮點數問題。

備註

INV_VIEW_MATRIX 是本次算繪通道用來轉換物件的矩陣,與 MAIN_CAM_INV_VIEW_MATRIX``(場景中主相機的矩陣)不同。在陰影通道時,``INV_VIEW_MATRIX 會以燈光所處位置的相機視圖為基準。

片段階段內建變數

Godot 片段處理函式的預設用途是設定物件的材質屬性,並交由內建算繪器處理最終著色。不必對所有這些屬性都寫入,未使用的部份 Godot 會自動優化移除相關運算。

內建變數

說明

in vec2 VIEWPORT_SIZE

視窗大小(像素)。

in vec4 FRAGCOORD

Coordinate of pixel center in screen space. xy specifies position in window. Upper-left of the viewport is the origin, (0.0, 0.0). Bottom-right of the viewport is (1.0, 1.0). z specifies fragment depth. It is also used as the output value for the fragment depth unless DEPTH is written to.

in bool FRONT_FACING

若當前面朝向正面則為 true,否則為 false

in vec3 VIEW

從片段位置指向相機的單位向量(視圖空間)。無論透視或正交攝影機,皆相同。

in vec2 UV

vertex() 傳來的 UV。

in vec2 UV2

vertex() 傳來的 UV2。

in vec4 COLOR

vertex() 函式傳遞來的顏色。

in vec2 POINT_COORD

使用 POINT_SIZE 算繪點時的點座標。

in mat4 MODEL_MATRIX

模型(本地)空間到世界空間的轉換。

in mat3 MODEL_NORMAL_MATRIX

模型(本地)空間至世界空間的法線轉換矩陣。預設與 MODEL_MATRIX 相同,若物件有非均勻縮放則設為 transpose(inverse(mat3(MODEL_MATRIX)))

in mat4 VIEW_MATRIX

世界空間到視圖空間的轉換。

in mat4 INV_VIEW_MATRIX

視圖空間到世界空間的轉換。

in mat4 PROJECTION_MATRIX

視圖空間到裁剪空間的轉換。

in mat4 INV_PROJECTION_MATRIX

裁剪空間到視圖空間的轉換。

in vec3 NODE_POSITION_WORLD

節點位置(世界空間)。

in vec3 NODE_POSITION_VIEW

節點位置(視圖空間)。

in vec3 CAMERA_POSITION_WORLD

Camera position, in world space. Represents the midpoint of the two eyes when in multiview/stereo rendering.

in vec3 CAMERA_DIRECTION_WORLD

相機方向(世界空間)。

in uint CAMERA_VISIBLE_LAYERS

目前算繪通道的相機可見圖層遮罩。

in vec3 VERTEX

片段(像素)的位置(視圖空間)。為 vertex() 傳來的 VERTEX 插值轉換至視圖空間的結果。若啟用 skip_vertex_transform,則可能不是視圖空間。

inout vec3 LIGHT_VERTEX

可寫入的 VERTEX 版本,用於更改光照與陰影。寫入本變數不會改變片段的位置。

in int VIEW_INDEX

目前算繪的視圖。用於多視角/立體算繪時區分視角。 VIEW_MONO_LEFT0 )代表單視角(非多視角)或左眼, VIEW_RIGHT1 )代表右眼。

in int VIEW_MONO_LEFT

單視圖或左眼用常數,值永遠為 0。

in int VIEW_RIGHT

右眼用常數,值永遠為 1。

in vec3 EYE_OFFSET

Position offset for the eye being rendered, in view space. Only applicable for multiview rendering.

sampler2D SCREEN_TEXTURE

已於 Godot 4 移除。請改用帶有 hint_screen_texturesampler2D

in vec2 SCREEN_UV

Screen UV coordinate for the current pixel.

sampler2D DEPTH_TEXTURE

已於 Godot 4 移除。請改用帶有 hint_depth_texturesampler2D

out float DEPTH

Custom depth value (range [0.0, 1.0]). If DEPTH is written to in any shader branch, then you are responsible for setting DEPTH for all other branches. Otherwise, the graphics API will leave them uninitialized.

inout vec3 NORMAL

vertex() 函式傳來的法線(視圖空間)。若啟用 skip_vertex_transform,則可能不是視圖空間。

inout vec3 TANGENT

vertex() 傳來的切線(視圖空間)。若啟用 skip_vertex_transform,則可能不是視圖空間。

inout vec3 BINORMAL

vertex() 傳來的副法線(視圖空間)。若啟用 skip_vertex_transform,則可能不是視圖空間。

out vec3 NORMAL_MAP

Set normal here in tangent space if reading normal from a texture instead of NORMAL. The blue channel is ignored, as it's reconstructed in the engine instead. This allows normal maps with RGTC compression to work.

out float NORMAL_MAP_DEPTH

NORMAL_MAP 的深度值,預設為 1.0。

out vec3 BENT_NORMAL_MAP

Set bent normal map here in tangent space to enable bent normals. This is used to improve specular occlusion, and requires a specially authored bent normal map. The blue channel is ignored, as it's reconstructed in the engine instead. This allows bent normal maps with RGTC compression to work.

out vec3 ALBEDO

反照率(預設白色)。基底色。

out float ALPHA

Alpha (range [0.0, 1.0]). If read from or written to, the material will go to the transparent pipeline.

out float ALPHA_SCISSOR_THRESHOLD

If written to on any branch, values below a certain amount of alpha are discarded.

out float ALPHA_HASH_SCALE

使用 alpha hash 透明模式時的雜湊縮放。預設為 1.0,值越高,抖動圖樣中可見像素越多。

out float ALPHA_ANTIALIASING_EDGE

設定啟用 alpha to coverage 抗鋸齒的 alpha 閾值。預設 0.0。需搭配 alpha_to_coverage 模式,且此值應小於 ALPHA_SCISSOR_THRESHOLD 才有效。

out vec2 ALPHA_TEXTURE_COORDINATE

用於 alpha-to-coverage 抗鋸齒的材質座標。需啟用 alpha_to_coverage 模式。通常設為 UV * vec2(albedo_texture_size),其中 albedo_texture_size 為反照率貼圖的像素大小。

out float PREMUL_ALPHA_FACTOR

預乘 Alpha 因子。僅於啟用 render_mode blend_premul_alpha; 時生效。若使用有光照的預乘 Alpha 混合材質,請寫入此值。無光照(unshaded)材質則不需處理。

out float METALLIC

Metallic (range [0.0, 1.0]).

out float SPECULAR

鏡面反射強度(非物理準確)。預設 0.5,設為 0.0 可停用反射。

out float ROUGHNESS

Roughness (range [0.0, 1.0]).

out float RIM

Rim (range [0.0, 1.0]). If used, Godot calculates rim lighting. Rim size depends on ROUGHNESS.

out float RIM_TINT

Rim Tint, range from 0.0 (white) to 1.0 (albedo). If used, Godot calculates rim lighting.

out float CLEARCOAT

在現有鏡面反射上新增小範圍的高光。如有使用,Godot 會自動計算 Clearcoat(透明漆層)。

out float CLEARCOAT_GLOSS

Clearcoat 光澤度。如有使用,Godot 會自動計算 Clearcoat。

out float ANISOTROPY

依切線空間變形鏡面反射高光。

out vec2 ANISOTROPY_FLOW

失真方向,搭配 flowmap 使用。

out float SSS_STRENGTH

次表面散射強度。如有設定物件會啟用 SSS 效果。

out vec4 SSS_TRANSMITTANCE_COLOR

次表面散射穿透顏色。如有設定物件會啟用 SSS 穿透效果。

out float SSS_TRANSMITTANCE_DEPTH

次表面散射穿透深度,值越高效果越深入物件內部。

out float SSS_TRANSMITTANCE_BOOST

如設為大於 0.0 ,會加強次表面散射穿透,讓效果即使在直射光下也可見

inout vec3 BACKLIGHT

背光顏色(類似直接光照,但就算法線未完全朝向光源也會接收)。如有設定,物件會有背光效果,可作為次表面散射的較省效能近似法。

out float AO

環境遮蔽強度。用於搭配預先烘焙的 AO。

out float AO_LIGHT_AFFECT

How much ambient occlusion affects direct light (range [0.0, 1.0], default 0.0).

out vec3 EMISSION

自發光顏色(HDR 可超過 (1.0, 1.0, 1.0) )。

out vec4 FOG

If written to on any branch, blends final pixel color with FOG.rgb based on FOG.a.

out vec4 RADIANCE

If written to on any branch, blends environment map radiance with RADIANCE.rgb based on RADIANCE.a.

out vec4 IRRADIANCE

If written to on any branch, blends environment map irradiance with IRRADIANCE.rgb based on IRRADIANCE.a.

備註

寫入 ALPHA 並進入透明管線的 shader 可能會遇到透明排序問題。詳情與解法請參閱 3D 算繪限制頁之透明排序章節

燈光階段內建變數

撰寫光照處理函式(light processor function)是完全可選的。若使用 unshaded 算繪模式則可直接省略 light()。如果未撰寫 light 函式,Godot 會根據 fragment() 中的材質屬性自動計算燈光效果(依算繪模式而定)。

每一盞燈、每一個像素都會呼叫一次 light() 函式。此函式會針對每種燈光型別在迴圈中被呼叫。

以下是一個採用 Lambert 漫反射模型的自訂 light() 函式範例:

void light() {
    if (LIGHT_IS_AREA) {
        // Area light GGX shading.
        DIFFUSE_LIGHT += LIGHT_AREA_DIFFUSE_MULTIPLIER * ATTENUATION * LIGHT_COLOR;
        SPECULAR_LIGHT += LIGHT_AREA_SPECULAR_MULTIPLIER * ATTENUATION * LIGHT_COLOR * SPECULAR_AMOUNT;
    } else {
        // Used for all other light types (directional, omni, spot).
        DIFFUSE_LIGHT += clamp(dot(NORMAL, LIGHT), 0.0, 1.0) * ATTENUATION * LIGHT_COLOR / PI;
    }
}

若要讓多盞燈光疊加,請使用 += 將光照貢獻加到 DIFFUSE_LIGHT,而非直接覆蓋。

警告

若啟用 vertex_lighting 算繪模式,或在專案設定啟用 Rendering > Quality > Shading > Force Vertex Shading 時,light() 函式將不會執行。(在行動裝置預設啟用。)

內建變數

說明

in vec2 VIEWPORT_SIZE

視窗大小(像素)。

in vec4 FRAGCOORD

Coordinate of pixel center in screen space. xy specifies position in window. Upper-left of the viewport is the origin, (0.0, 0.0). Bottom-right of the viewport is (1.0, 1.0). z specifies fragment depth. It is also used as the output value for the fragment depth unless DEPTH is written to.

in mat4 MODEL_MATRIX

模型(本地)空間到世界空間的轉換。

in mat4 INV_VIEW_MATRIX

視圖空間到世界空間的轉換。

in mat4 VIEW_MATRIX

世界空間到視圖空間的轉換。

in mat4 PROJECTION_MATRIX

視圖空間到裁剪空間的轉換。

in mat4 INV_PROJECTION_MATRIX

裁剪空間到視圖空間的轉換。

in vec3 NORMAL

法線向量(視圖空間)。

in vec2 SCREEN_UV

Screen UV coordinate for the current pixel.

in vec2 UV

vertex() 傳來的 UV。

in vec2 UV2

vertex() 傳來的 UV2。

in vec3 VIEW

視線向量(視圖空間)。

in vec3 LIGHT

燈光向量(視圖空間)。

in vec3 LIGHT_COLOR

光源顏色 乘以 光源能量 再乘以 PI。乘上 PI 是因物理式光照模型會對光能量除以 PI

in float SPECULAR_AMOUNT

若為 OmniLight3DSpotLight3D,為 2.0 乘以 light_specular;若為 DirectionalLight3D,則為 1.0

in bool LIGHT_IS_DIRECTIONAL

若本通道為 DirectionalLight3D 則為 true

in float ATTENUATION

距離或陰影造成的光照衰減。

in vec3 ALBEDO

基底反照率。

in vec3 BACKLIGHT

in float METALLIC

金屬度。

in float ROUGHNESS

粗糙度。

out vec3 DIFFUSE_LIGHT

漫反射光輸出。

out vec3 SPECULAR_LIGHT

鏡面反射光輸出。

out float ALPHA

Alpha (range [0.0, 1.0]). If written to on any branch, the material will go through the transparent pipeline.

備註

寫入 ALPHA 並進入透明管線的 shader 可能會遇到透明排序問題。詳情與解法請參閱 3D 算繪限制頁之透明排序章節

透明材質無法投射陰影,也無法出現在 hint_screen_texturehint_depth_texture uniform 內。因此這些材質不會出現在螢幕空間反射或折射效果中。SDFGI 的銳利反射不會顯示於透明材質(僅粗糙反射可見)。