Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

標準 3D 材質與 ORM 3D 材質

前言

SpatialMaterial 是一種預設的3D材質, 旨在提供藝術家在材質中尋找的大部分功能, 而無需編寫著色器程式碼. 但是, 如果需要其他功能, 可以將其轉換為著色器程式碼.

本教學會解釋 SpatialMaterial 中出現的大多數參數。

SpatialMaterial 新增到物件有 4 種方法。可以在網格的 Material*(材質)屬性中新增。可以在使用該網格的節點(比如 MeshInstance 節點)的 *Material 屬性中新增,可以使用該網格的節點的 *Material Override*(材質覆蓋)屬性中新增,也可以是 *Material Overlay*(材質覆蓋層)屬性。

../../_images/add_material.webp

如果你把材質加到網格本身上, 每次那個網格被使用的時候都會有那個材質. 如果你用網格向一個節點新增材質, 那個材質僅會被那個節點使用, 也會覆蓋網格的材質屬性. 如果材質被新增到了節點的 Material Override(材質覆蓋) 屬性上, 它僅會被那個節點使用, 它也會覆蓋那個節點的常規材質屬性和網格的材質屬性.

*Material Overlay*(材質覆蓋層)屬性會在該網格所使用的目前材質**上方**再渲染一個材質。例如,可以用來在網格上放置半透明護盾效果。

BaseMaterial 3D 設定

StandardMaterial3D 有許多決定材質外觀的設定。所有這些都屬於 BaseMaterial3D 類別

../../_images/spatial_material1.png

ORM 材料幾乎完全相同,只有一處不同。沒有單獨的遮蔽、粗糙度和金屬設定和紋理,而是單一 ORM 紋理。此紋理的不同顏色通道用於每個參數。 Substance Painter 和 Armor Paint 等程式將為您提供以此格式匯出的選項,對於這兩個程式,它具有虛幻引擎的匯出預設,該引擎也使用 ORM 紋理。

透明

By default, materials in Godot are opaque. This is fast to render, but it means the material can't be seen through even if you use a transparent texture in the Albedo > Texture property (or set Albedo > Color to a transparent color).

To be able to see through a material, the material needs to be made transparent. Godot offers several transparency modes:

  • Disabled: Material is opaque. This is the fastest to render, with all rendering features supported.

  • Alpha: Material is transparent. Semi-transparent areas are drawn with blending. This is slow to render, but it allows for partial transparency (also known as translucency). Materials using alpha blending also can't cast shadows, and are not visible in screen-space reflections.

    • Alpha is a good fit for particle effects and VFX.

  • Alpha Scissor: Material is transparent. Semi-transparent areas whose opacity is below Alpha Scissor Threshold are not drawn (above this opacity, these are drawn as opaque). This is faster to render than Alpha and doesn't exhibit transparency sorting issues. The downside is that this results in "all or nothing" transparency, with no intermediate values possible. Materials using alpha scissor can cast shadows.

    • Alpha Scissor is ideal for foliage and fences, since these have hard edges and require correct sorting to look good.

  • Alpha Hash: Material is transparent. Semi-transparent areas are drawn using dithering. This is also "all or nothing" transparency, but dithering helps represent partially opaque areas with limited precision depending on viewport resolution. Materials using alpha hash can cast shadows.

    • Alpha Hash is suited for realistic-looking hair, although stylized hair may work better with alpha scissor.

  • Depth Pre-Pass: This renders the object's fully opaque pixels via the opaque pipeline first, then renders the rest with alpha blending. This allows transparency sorting to be mostly correct (albeit not fully so, as partially transparent regions may still exhibit incorrect sorting). Materials using depth prepass can cast shadows.

備註

Godot will automatically force the material to be transparent with alpha blending if any of these conditions is met:

  • Setting the transparency mode to Alpha (as described here).

  • Setting a blend mode other than the default Mix

  • Enabling Refraction, Proximity Fade, or Distance Fade.

Comparison between alpha blending (left) and alpha scissor (right) transparency:

../../_images/spatial_material12.png

警告

Alpha-blended transparency has several limitations:

  • Alpha-blended materials are significantly slower to render, especially if they overlap.

  • Alpha-blended materials may exhibit sorting issues when transparent surfaces overlap each other. This means that surfaces may render in the incorrect order, with surfaces in the back appearing to be in front of those which are actually closer to the camera.

  • Alpha-blended materials don't cast shadows, although they can receive shadows.

  • Alpha-blended materials don't appear in any reflections (other than reflection probes).

  • Screen-space reflections and sharp SDFGI reflections don't appear on alpha-blended materials. When SDFGI is enabled, rough reflections are used as a fallback regardless of material roughness.

Before using the Alpha transparency mode, always consider whether another transparency mode is more suited for your needs.

Alpha Antialiasing

備註

This property is only visible when the transparency mode is Alpha Scissor or Alpha Hash.

While alpha scissor and alpha hash materials are faster to render than alpha-blended materials, they exhibit hard edges between opaque and transparent regions. While it's possible to use post-processing-based antialiasing techniques such as FXAA and TAA, this is not always desired as these techniques tend to make the final result look blurrier or exhibit ghosting artifacts.

There are 3 alpha antialiasing modes available:

  • Disabled: No alpha antialiasing. Edges of transparent materials will appear aliased unless a post-processing-based antialiasing solution is used.

  • Alpha Edge Blend: Results in a smooth transition between opaque and transparent areas. Also known as "alpha to coverage".

  • Alpha Edge Clip: Results in a sharp, but still antialiased transition between opaque and transparent areas. Also known as "alpha to coverage + alpha to one".

When the alpha antialiasing mode is set to Alpha Edge Blend or Alpha Edge Clip, a new Alpha Antialiasing Edge property becomes visible below in the inspector. This property controls the threshold below which pixels should be made transparent. While you've already defined an alpha scissor threshold (when using Alpha Scissor only), this additional threshold is used to smoothly transition between opaque and transparent pixels. Alpha Antialiasing Edge must always be set to a value that is strictly below the alpha scissor threshold. The default of 0.3 is a sensible value with an alpha scissor of threshold of 0.5, but remember to adjust this alpha antialiasing edge when modifying the alpha scissor threshold.

If you find the antialiasing effect not effective enough, try increasing Alpha Antialiasing Edge while making sure it's below Alpha Scissor Threshold (if the material uses alpha scissor). On the other hand, if you notice the texture's appearance visibly changing as the camera moves closer to the material, try decreasing Alpha Antialiasing Edge.

重要

For best results, MSAA 3D should be set to at least 2× in the Project Settings when using alpha antialiasing. This is because this feature relies on alpha to coverage, which is a feature provided by MSAA.

Without MSAA, a fixed dithering pattern is applied on the material's edges, which isn't very effective at smoothing out edges (although it can still help a little).

混合模式

控制材質的混合模式。請記住,Mix 以外的任何模式都會強制物件通過透明管道。

  • **Mix:**(混合)預設混合模式,Alpha 控制物件可見的程度。

  • **Add:**(新增)對象會進行新增性的混合,非常適合耀斑或類似火焰的效果。

  • **Sub:**從螢幕顏色中減去物件的最終顏色。

  • Front: 當不可見時, 物體的正面被剔除.

../../_images/spatial_material8.png

剔除模式

確定渲染背面時不繪製對象的哪一側:

  • Back: 當不可見時, 物件的背面被剔除(預設).

  • Front: 當不可見時, 物體的正面被剔除.

  • Disabled: 用於雙面對象(不進行剔除).

備註

預設情況下,Blender 在材質上禁用背面剔除,匯出材質時配對其在 Blender 中的渲染方式。這意味著 Godot 中的材質會將其剔除模式設定為 Disabled。這會降低性能,因為背面將被渲染,即使它們不可見。要解決此問題,請在 Blender 的材質分頁中啟用 Backface Culling ,然後再次將場景匯出為 glTF。

深度繪製模式

指定何時必須進行深度渲染.

  • Opaque Only(僅限不透明, 預設): 僅為不透明對象繪製深度.

  • Always(始終): 為不透明和透明對象深度繪製.

  • Never(從不): 不進行深度抽取(不要將其與上面的No Depth Test(無深度測試)選項混淆).

  • Depth Pre-Pass(深度預通過): 對於透明物體, 首先使用不透明部分進行不透明的通過, 然後在上方繪製透明度. 將此選項與透明草或樹葉一起使用.

../../_images/material_depth_draw.png

無深度測試

為了使近距離物體出現在遠處的物體上, 進行深度測試. 禁用它會導致物件出現在其他所有內容之上(或之下).

禁用此選項對於在世界空間中繪製指標最有意義, 並且與Material的 Render Priority 屬性一起效果很好(請參閱本頁底部).

../../_images/spatial_material3.png

著色

著色器

由於depth pre-pass (深度預通過),Godot的每像素成本或多或少是一致的. 所有照明計算都是通過在每個像素上運作照明著色器來完成的.

由於這些計算成本很高, 因此在某些極端情況下可以大大降低性能, 例如繪製幾層透明度(這在粒子系統中很常見). 在這些情況下, 切換到每頂點光照可能會有所幫助.

此外, 在低端或移動裝置上, 切換到頂點照明可以顯著提高渲染性能.

../../_images/spatial_material2.png

請記住,啟用頂點照明時,只有平行光會產生陰影(出於性能原因)。

但是,在某些情況下,您可能只想顯示反照率(顏色)而忽略其餘部分。切換此旗標將刪除所有陰影並顯示純淨,未光照的顏色

../../_images/spatial_material26.png

漫反射模式

指定擊中物件時漫反射光散射所使用的演算法. 預設為 Burley. 也有其他模式可用:

  • **Burley:**預設模式,原始的 Disney Principled PBS 漫反射演算法。

  • **Lambert:**不受粗糙度的影響。

  • **Lambert Wrap:**當粗糙度增加時,將 Lambert 拓展至覆蓋 90 度以上。適用於頭髮和模擬廉價的次表面散射。這種實作是節能的。

  • **Oren Nayar:**此實作旨在將微表面考慮在內(通過粗糙度)。適用於粘土類材質和某些型別的布料。

  • Toon: 為照明提供硬邊緣, 光滑度受粗糙度的影響. 建議您從環境的環境光設定中禁用sky contribution(天空補償), 或禁用空間材質中的環境光以獲得更好的效果.

../../_images/spatial_material6.png

鏡面反射模式

指定鏡面反射斑點的呈現方式。鏡面反射斑點是在對象中反射的光源的形狀。

  • ** ShlickGGX:** 現在PBR 3D引擎使用的最常見的blob.

  • Blinn: 在上一代引擎中很常見. 現在不值得使用, 但為了相容性而留在這裡.

  • ** Phong:** 同上.

  • Toon: 建立一個toon blob, 根據粗糙度改變大小.

  • 禁用: 有時候blob很煩人. 消失吧!

../../_images/spatial_material7.png

停用環境光

使物體不會接收任何會照亮它的環境光。

停用霧

使物體不受基於深度或體積霧的影響。這對於粒子或其他新增混合的材質很有用,否則它們會顯示網格的形狀(即使在沒有霧的情況下看不見的地方)。

頂點顏色

This setting allows choosing what is done by default to vertex colors that come from your 3D modeling application. By default, they are ignored.

../../_images/spatial_material4.png

用作反照率

選擇此選項意味著用頂點顏色作為反射顏色.

是 sRGB

大多數3D DCC可能會將頂點顏色匯出為sRGB, 因此切換此選項將有助於它們看起來正確.

反照率

Albedo 是材質的基色, 所有其他設定都在其上運作. 設定為 Unshaded 時, 這是唯一可見的顏色. 在以前版本的Godot中, 這個通道被命名為 Diffuse . 名稱的改變主要是因為在PBR(Physically Based Rendering, 基於物理渲染)中, 這種顏色影響的計算遠不止漫射光照路徑.

反照率顏色(Albedo Color)可以和紋理一起使用,因為它們會被相乘。

反照率顏色和紋理的 Alpha通道 也用於物件透明度. 如果你使用帶 alpha通道 的顏色或紋理, 請確保啟用透明度或 alpha scissoring 以使其正常工作.

金屬度

由於其簡單性,Godot使用金屬模型而不是別的模型. 此參數定義材質的反射程度. 反射越多, 漫射/環境光的影響越小, 反射的光越多. 這種模型被稱為 "能量守恆(energy-conserving)".

Specular 參數是反射率的一般數量(與 Metallic 不同,能量不守恆,因此請將其保留為 0.5 並且除非你需要,否則不要碰它)。

最小的內部反射率是 0.04,因此不可能使材質完全不產生反射,就像在現實生活中一樣。

../../_images/spatial_material13.png

粗糙度

粗糙度 會影響反射的發生方式. 值 0 使其成為完美的鏡子, 而 1 的值完全模糊了反射(模擬自然微表面). 最常見的材質型別可以通過 MetallicRoughness 的正確組合來實作.

../../_images/spatial_material14.png

自發光

發射 指定材質發出的光量(請記住, 這不包括環繞幾何體的光, 除非使用 doc_gi_probes ). 此值將新增到生成的最終圖像中, 並且不受場景中其他光照的影響.

../../_images/spatial_material15.png

法線貼圖

法線貼圖允許你設定一個代表更精細形狀細節的紋理, 這不會修改幾何體, 只會修改光的入射角. 在Godot中, 為了更好的壓縮和更廣泛的相容性, 只使用了法線貼圖的紅色和綠色通道.

../../_images/spatial_material16.png

備註

Godot 中的法線對應必須使用 X+, Y- 與 Z+ 座標。換句話說,若匯入使用於其他引擎的素材,則必須將其 Y 軸翻轉過來,否則,法線對應方向的 Y 軸可能會顯示為相反。

有關更多法線對應的資訊 (包含各種常見引擎的座標順序表),請參考 此處 (英文)

邊緣

一些織物具有小的微毛, 導致光在其周圍散射. Godot使用 Rim 參數模擬它. 與僅使用發射通道的其他邊緣照明實施方式不同, 這實際上考慮了光(沒有光意味著沒有邊緣). 這使得效果顯著地更加可信.

../../_images/spatial_material17.png

邊緣大小取決於粗糙度, 並且有一個特殊參數來指定它必須如何著色. 如果 Tint0, 則燈光的顏色用於邊緣. 如果 Tint1, 則使用材質的反照率. 使用中間的值通常效果最佳.

清漆

Clearcoat 參數用於為材質新增輔助的透明塗層。這在汽車油漆和玩具中很常見。在實踐中,它是在現有材質之上新增的較小的鏡面反射斑點。

../../_images/clearcoat_comparison.png

各向異性

這會更改鏡面反射斑點的形狀並將其與切線空間對齊。各向異性通常與頭髮一起使用,或使諸如拉絲鋁之類的材質更加逼真。與流向貼圖結合使用時效果特別好。

../../_images/spatial_material18.png

環境光遮蔽

可以指定烘焙的環境遮擋貼圖. 此貼圖會影響有多少環境光到達物體每個表面(預設情況下它不會影響直接光). 雖然可以使用螢幕空間環境遮擋(Screen-Space Ambient Occlusion, SSAO)來生成環境遮擋, 但沒有什麼能比良好烘焙的AO貼圖的品質更好. 建議盡可能烘焙環境遮擋.

../../_images/spatial_material19.png

光照

在材質上設定深度貼圖會做一個ray-marching搜索, 以模擬沿視圖方向的空穴的正確位移. 這不是真正增加的幾何, 而是一種深度的幻覺. 它可能不適用於複雜的物件, 但它會為紋理產生逼真的深度效果. 為獲得最佳效果,*Depth* 應與法線貼圖一起使用.

../../_images/spatial_material20.png

次表面散射

此效果類比穿透物體表面, 散射然後散出的光. 創造逼真的皮膚, 大理石, 有色液體等有用.

../../_images/spatial_material21.png

背部照明

這可以控制有多少光從被點亮的一側(正對燈光)傳輸到暗側(背對燈光). 這適用於植物葉子, 草, 人耳等薄物體.

折射

When refraction is enabled, Godot attempts to fetch information from behind the object being rendered. This allows distorting the transparency in a way similar to refraction in real life.

請記住使用透明反照率紋理(或減少反照率顏色的 Alpha 通道)以使折射可見,因為折射依賴透明度來產生可見效果。

可以選擇在 折射紋理 屬性中指定法線貼圖,以允許在每個像素的基礎上扭曲折射方向。

../../_images/spatial_material23.png

備註

折射作為螢幕空間效果實作,並強製材質透明。這使得效果相對較快,但這會導致一些限制:

  • 透明度排序 可能會出現問題。

  • 折射材料不能折射到自身或其他透明材料。另一種透明材料後面的折射材料將是看不見的。

  • 螢幕外的物體不能出現在折射中。這在高折射強度值時最為明顯。

  • 折射材料前面的不透明材料將看起來具有“折射”邊緣,即使它們不應該如此。

細節

Godot允許使用輔助反射和法線貼圖生成細節紋理, 可以通過多種方式進行混合. 通過將其與二級UV或三平面模式相結合, 可以實作許多有趣的紋理.

../../_images/spatial_material24.png

有幾種設定可以控制細節的使用方式.

Mask(遮罩): 細節遮罩是一個黑白圖像, 用來控制紋理的混合位置. 白色為細節紋理, 黑色為常規材質紋理, 不同深淺的灰色用於材質紋理和細節紋理的部分混合.

混合模式: 有四種模式控制紋理的混合方式.

  • 融合: 合併兩個紋理的像素值. 黑色時, 僅顯示材質紋理;白色時, 僅顯示細節紋理. 灰色的值在兩者之間建立一個平滑的混合.

  • 相加: 將一個紋理與另一個紋理的像素值相加. 與融合模式不同的是, 兩個紋理在蒙板的白色部分而不是灰色部分完全混合. 原始紋理在黑色部分基本沒有變化

  • 相減: 將一個紋理的像素值與另一個紋理的像素值相減. 第二種紋理在蒙版的白色部分被完全減去, 在黑色部分只被減去一點, 灰色部分根據具體實際紋理減去不同的程度.

  • 相乘: 將上方紋理中每個像素的 RGB 通道數與下方紋理中相應像素的值相乘.

Albedo: 在此處放置要混合的反射紋理. 如果此插槽中沒有任何內容, 則預設情況下將其解釋為純白.

法線: 在此處放置需要混合的法線紋理. 如果這個槽中沒有任何東西, 它將被解釋為一個平坦的法線貼圖. 即使材質未啟用法線貼圖也可以使用這個槽.

UV1和UV2

Godot每種材質支援兩個UV通道. 二級UV通常可用於環境遮擋或發射(烘焙的光照). UV可以縮放和偏移, 這在使用重複紋理時很有用.

Triplanar Mapping(三平面對應)

UV1和UV2都支援三平面對應. 這是獲得紋理座標的另一種方法, 有時稱為 "自動紋理". 紋理在X,Y和Z中取樣, 並由法線混合. 可以在世界空間或物件空間中執行三平面對應.

在下圖中,你可以看到所有像素如何與世界三平面共用相同的材質,因此磚紋理在它們之間平滑地繼續。

../../_images/spatial_material25.png

世界三平面

使用三平面對應時(見下文, 在UV1和UV2設定中), 在物件局部空間中計算三平面. 此選項使triplanar在世界空間中工作.

重新取樣

篩選

材質使用的紋理的篩選方法。有關選項及其說明的完整列表,請參閱本頁<class_BaseMaterial3D_property_texture_filter>`。

重覆

材質使用的紋理是否重複,以及它們如何重複。有關選項及其說明的完整列表,請參閱本頁<class_BaseMaterial3D_property_texture_repeat>。

陰影

Do Not Receive Shadows(不接受陰影)

使物件不會接收任何可能會被投射到其上的陰影.

Use Shadow to Opacity(使用陰影轉為不透明度)

光照會改變alpha值, 陰影部分是不透明的, 而沒有陰影的地方是透明的. 對於AR中將陰影堆疊到一個照相機回饋中很有用.

佈告欄

Billboard Mode(看板模式)

為繪圖材質啟用看板模式. 這會控制物體面向攝像頭的方式:

  • Disabled: 禁用看板模式.

  • Enabled: Billboard mode is enabled. The object's -Z axis will always face the camera's viewing plane.

  • Y-Billboard: The object's X axis will always be aligned with the camera's viewing plane.

  • Particle Billboard: Most suited for particle systems, because it allows specifying flipbook animation.

../../_images/spatial_material9.png

The Particles Anim section is only visible when the billboard mode is Particle Billboard.

Billboard Keep Scale(看板保持縮放)

啟用在看板模式下縮放網格.

生長

沿法線指向的方向增長對象頂點:

../../_images/spatial_material10.png

這通常用於建立廉價的輪廓. 新增第二個material pass, 使其變為黑色, 無陰影(unshaded), 反向剔除(Cull Front), 並新增一些增長:

../../_images/spatial_material11.png

變換

固定大小

這使得無論距離如何, 物件都以相同的大小呈現. 這主要用於指示物(無深度測試和高渲染優先順序)和某些型別的看板.

使用點大小

此選項僅在渲染的幾何體由點組成時有效(通常從3D DCC匯入時由三角形組成). 如果是這樣, 那麼這些點可以被調整大小(見下文).

點大小

繪製點時,指定點的大小,單位為像素。

轉場

這可以控制有多少光從被點亮的一側(正對燈光)傳輸到暗側(背對燈光). 這適用於植物葉子, 草, 人耳等薄物體.

../../_images/spatial_material22.png

Proximity and distance fade(接近和距離漸隱)

Godot允許材質通過彼此接近以及取決於與觀察者的距離而隱去. 接近隱去對於諸如軟粒子或大量水平滑地過渡到海岸是有用的. 距離漸隱對於僅在給定距離之後存在的光軸或指示物是有用的.

../../_images/spatial_material_proxfade.gif

距離淡入淡出對於僅在給定距離後才出現的光軸或指示器非常有用。

請記住,使用 Pixel Alpha 模式啟用鄰近淡入淡出或距離淡入淡出可實作 Alpha 混合。 Alpha 混合更加耗費 GPU 資源,並可能導致透明度排序問題。 Alpha 混合也會停用許多材質功能,例如投射陰影的能力。要在角色太靠近相機時隱藏角色,請考慮使用**像素抖動**或更好的**物件抖動**(甚至比**像素抖動**更快)。

材質

Render priority(渲染優先順序)

可以更改物件的渲染順序, 儘管這對於透明物件有用(或執行深度繪製但沒有顏色繪製的不透明物件, 例如地板上的裂縫).

下一階段

設定下一個頻道要使用的材質。這會使用不同的材質再次渲染該物件。