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.

标准 3D 材质与 ORM 3D 材质

前言

StandardMaterial3D and ORMMaterial3D (Occlusion, Roughness, Metallic) are default 3D materials that aim to provide most of the features artists look for in a material, without the need for writing shader code. However, they can be converted to shader code if additional functionality is needed.

This tutorial explains the parameters present in both materials.

There are 4 ways to add these materials to an object. A material can be added in the Material property of the mesh. It can be added in the Material property of the node using the mesh (such as a MeshInstance3D node), the Material Override property of the node using the mesh, and the Material Overlay.

../../_images/add_material.webp

如果你把材质加到网格本身上, 每次那个网格被使用的时候都会有那个材质. 如果你用网格向一个节点添加材质, 那个材质仅会被那个节点使用, 也会覆盖网格的材质属性. 如果材质被添加到了节点的 Material Override(材质覆盖) 属性上, 它仅会被那个节点使用, 它也会覆盖那个节点的常规材质属性和网格的材质属性.

Material Overlay(材质覆盖层)属性会在该网格所使用的当前材质上方再渲染一个材质。例如,可以用来在网格上放置半透明护盾效果。

BaseMaterial 3D 设置

StandardMaterial3D 有许多设置来决定材质的外观。所有这些都属于 BaseMaterial3D 类别

../../_images/spatial_material1.png

ORM materials are almost exactly the same with one difference. Instead of separate settings and textures for occlusion, roughness, and metallic, there is a single ORM texture. The different color channels of that texture are used for each parameter. Programs such as Substance Painter and Armor Paint will give you the option to export in this format, for these two programs it's with the export preset for unreal engine, which also uses ORM textures.

透明

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).

Blend Mode(混合模式)

控制材质的混合模式。请记住,Mix 以外的任何模式都会强制对象通过透明管道。

  • Mix:(混合)默认混合模式,Alpha 控制对象可见的程度。

  • Add: The final color of the object is added to the color of the screen, nice for flares or some fire-like effects.

  • Sub:(减去)从屏幕颜色中减去对象的最终颜色。

  • Mul:(相乘) 对象的最终颜色与屏幕的颜色相乘。

../../_images/spatial_material8.png

Cull Mode(剔除模式)

确定渲染背面时不绘制对象的哪一侧:

  • Back: 当不可见时, 对象的背面被剔除(默认).

  • Front: 当不可见时, 物体的正面被剔除.

  • Disabled: 用于双面对象(不进行剔除).

备注

默认情况下,Blender 在材质上禁用背面剔除,导出材质时匹配其在 Blender 中的渲染方式。这意味着 Godot 中的材质会将其剔除模式设置为 Disabled。这会降低性能,因为背面将被渲染,即使它们不可见。要解决此问题,请在 Blender 的材质选项卡中启用 Backface Culling ,然后再次将场景导出为 glTF。

Depth Draw Mode(深度绘制模式)

指定何时必须进行深度渲染.

  • Opaque Only(仅限不透明, 默认): 仅为不透明对象绘制深度.

  • Always(始终): 为不透明和透明对象深度绘制.

  • Never: No depth draw takes place (do not confuse this with the No Depth Test option below).

  • Depth Pre-Pass(深度预通过): 对于透明物体, 首先使用不透明部分进行不透明的通过, 然后在上方绘制透明度. 将此选项与透明草或树叶一起使用.

../../_images/material_depth_draw.png

No Depth Test(无深度测试)

为了使近距离物体出现在远处的物体上, 进行深度测试. 禁用它会导致对象出现在其他所有内容之上(或之下).

禁用此选项对于在世界空间中绘制指标最有意义, 并且与Material的 Render Priority 属性一起效果很好(请参阅本页底部).

../../_images/spatial_material3.png

着色

着色模式

由于depth pre-pass (深度预通过),Godot的每像素成本或多或少是一致的. 所有照明计算都是通过在每个像素上运行照明着色器来完成的.

由于这些计算成本很高, 因此在某些极端情况下可以大大降低性能, 例如绘制几层透明度(这在粒子系统中很常见). 在这些情况下, 切换到每顶点光照可能会有所帮助.

此外, 在低端或移动设备上, 切换到顶点照明可以显着提高渲染性能.

../../_images/spatial_material2.png

请记住,启用顶点照明时,只有平行光会产生阴影(出于性能原因)。

但是,在某些情况下,您可能只想显示反照率(颜色)而忽略其余部分。切换此标志将删除所有阴影并显示纯净,未光照的颜色

../../_images/spatial_material26.png

Diffuse Mode(漫反射模式)

指定击中对象时漫反射光散射所使用的算法. 默认为 Burley. 也有其他模式可用:

  • Burley:默认模式,原始的 Disney Principled PBS 漫反射算法。

  • Lambert:不受粗糙度的影响。

  • Lambert Wrap:当粗糙度增加时,将 Lambert 拓展至覆盖 90 度以上。适用于头发和模拟廉价的次表面散射。这种实现是节能的。

  • Oren Nayar:此实现旨在将微表面考虑在内(通过粗糙度)。适用于粘土类材质和某些类型的布料。

  • Toon: Provides a hard cut for lighting, with smoothing affected by roughness. It is recommended you disable sky contribution from your environment's ambient light settings or disable ambient light in the StandardMaterial3D to achieve a better effect.

../../_images/spatial_material6.png

Specular Mode(镜面反射模式)

指定镜面反射斑点的呈现方式。镜面反射斑点是在对象中反射的光源的形状。

  • SchlickGGX: The most common blob used by PBR 3D engines nowadays.

  • Blinn: 在上一代引擎中很常见. 现在不值得使用, 但为了兼容性而留在这里.

  • ** Phong:** 同上.

  • Toon: 创建一个toon blob, 根据粗糙度改变大小.

  • 禁用: 有时候blob很烦人. 消失吧!

../../_images/spatial_material7.png

Disable Ambient Light(禁用环境光)

使物体不会接收任何会照亮它的环境光。

禁用雾

使对象不受基于深度或体积雾的影响。 这对于粒子或其他添加混合的材质很有用,否则它们会显示网格的形状(即使在没有雾的情况下看不见的地方)。

Vertex Color(顶点颜色)

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

Use as Albedo(用作反照率)

选择此选项意味着用顶点颜色作为反射颜色.

Is sRGB(是sRGB)

Most 3D modeling software will likely export vertex colors as sRGB, so toggling this option on will help them look correct.

Albedo(反照率)

Albedo 是材质的基色, 所有其他设置都在其上运行. 设置为 Unshaded 时, 这是唯一可见的颜色. 在以前版本的Godot中, 这个通道被命名为 Diffuse . 名称的改变主要是因为在PBR(Physically Based Rendering, 基于物理渲染)中, 这种颜色影响的计算远不止漫射光照路径.

反照率颜色(Albedo Color)可以和纹理一起使用,因为它们会被相乘。

反照率颜色和纹理的 Alpha通道 也用于对象透明度. 如果你使用带 alpha通道 的颜色或纹理, 请确保启用透明度或 alpha scissoring 以使其正常工作.

Metallic(金属)

由于其简单性,Godot使用金属模型而不是别的模型. 此参数定义材质的反射程度. 反射越多, 漫射/环境光的影响越小, 反射的光越多. 这种模型被称为 "能量守恒(energy-conserving)".

Specular 参数是反射率的一般数量(与 Metallic 不同,能量不守恒,因此请将其保留为 0.5 并且除非你需要,否则不要碰它)。

最小的内部反射率是 0.04,因此不可能使材质完全不产生反射,就像在现实生活中一样。

../../_images/spatial_material13.png

Roughness(粗糙度)

粗糙度 会影响反射的发生方式. 值 0 使其成为完美的镜子, 而 1 的值完全模糊了反射(模拟自然微表面). 最常见的材质类型可以通过 MetallicRoughness 的正确组合来实现.

../../_images/spatial_material14.png

Emission(发射)

Emission specifies how much light is emitted by the material (keep in mind this does not include light surrounding geometry unless VoxelGI or SDFGI are used). This value is added to the resulting final image and is not affected by other lighting in the scene.

../../_images/spatial_material15.png

法线贴图

法线贴图允许你设置一个代表更精细形状细节的纹理, 这不会修改几何体, 只会修改光的入射角. 在Godot中, 为了更好的压缩和更广泛的兼容性, 只使用了法线贴图的红色和绿色通道.

../../_images/spatial_material16.png

备注

Godot 需要法线贴图使用 X+、Y+、Z+ 坐标,即 OpenGL 风格。如果你导入了用于其他引擎的材质,它可能使用的是 DirectX 风格,那么就需要对法线贴图的进行转换,翻转 Y 轴。

可以在 这里 找到关于法线贴图(包括常见引擎的坐标顺序表)的更多信息.

Rim(边缘)

一些织物具有小的微毛, 导致光在其周围散射. Godot使用 Rim 参数模拟它. 与仅使用发射通道的其他边缘照明实施方式不同, 这实际上考虑了光(没有光意味着没有边缘). 这使得效果显著地更加可信.

../../_images/spatial_material17.png

边缘大小取决于粗糙度, 并且有一个特殊参数来指定它必须如何着色. 如果 Tint0, 则灯光的颜色用于边缘. 如果 Tint1, 则使用材质的反照率. 使用中间的值通常效果最佳.

Clearcoat(清漆)

Clearcoat 参数用于为材质添加辅助的透明涂层。这在汽车油漆和玩具中很常见。在实践中,它是在现有材质之上添加的较小的镜面反射斑点。

../../_images/clearcoat_comparison.png

Anisotropy(各向异性)

这会更改镜面反射斑点的形状并将其与切线空间对齐。各向异性通常与头发一起使用,或使诸如拉丝铝之类的材质更加逼真。与流向贴图结合使用时效果特别好。

../../_images/spatial_material18.png

Ambient Occlusion(环境光遮蔽)

可以指定烘焙的环境遮挡贴图. 此贴图会影响有多少环境光到达物体每个表面(默认情况下它不会影响直接光). 虽然可以使用屏幕空间环境遮挡(Screen-Space Ambient Occlusion, SSAO)来生成环境遮挡, 但没有什么能比良好烘焙的AO贴图的质量更好. 建议尽可能烘焙环境遮挡.

../../_images/spatial_material19.png

Height

在材质上设置深度贴图会做一个ray-marching搜索, 以模拟沿视图方向的空穴的正确位移. 这不是真正增加的几何, 而是一种深度的幻觉. 它可能不适用于复杂的对象, 但它会为纹理产生逼真的深度效果. 为获得最佳效果,*Depth* 应与法线贴图一起使用.

../../_images/spatial_material20.png

Subsurface Scattering(次表面散射)

此效果模拟穿透物体表面, 散射然后散出的光. 创造逼真的皮肤, 大理石, 有色液体等有用.

../../_images/spatial_material21.png

背光照明

这可以控制有多少光从被点亮的一侧(正对灯光)传输到暗侧(背对灯光). 这适用于植物叶子, 草, 人耳等薄物体.

Refraction(折射)

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 通道)使折射可见,因为折射依赖于透明度才能产生可见效果。

可以选择在**Refraction Texture**属性中指定法线贴图,以便在每个像素的基础上扭曲折射方向。

../../_images/spatial_material23.png

备注

折射效果是作为屏幕空间效果实现的,并强制材料透明。这使得效果相对较快,但也造成了一些限制:

  • 透明度排序 可能会出现问题。

  • 折射材料不能折射到自身或其他透明材料上。在另一种透明材料后面的折射材料是不可见的。

  • 屏幕外的物体无法出现在折射效果中。这在折射强度值较高时最为明显。

  • Opaque materials in front of the refractive material will appear to have "refracted" edges, even though they shouldn't.

Detail(细节)

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

World Triplanar(世界三平面)

When using triplanar mapping, it is computed in object local space. This option makes it use world space instead.

Sampling

过滤器

材质使用的纹理过滤方法。请参阅 this page 获取完整的选项列表及其说明。

重复

材质使用的纹理是否重复,以及重复的方式。请参阅 this page 获取完整的选项列表及其说明。

阴影

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(广告牌保持缩放)

启用在广告牌模式下缩放网格.

Grow(增长)

沿法线指向的方向增长对象顶点:

../../_images/spatial_material10.png

这通常用于创建廉价的轮廓. 添加第二个material pass, 使其变为黑色, 无阴影(unshaded), 反向剔除(Cull Front), 并添加一些增长:

../../_images/spatial_material11.png

变换

Fixed Size(固定大小)

这使得无论距离如何, 对象都以相同的大小呈现. 这主要用于指示物(无深度测试和高渲染优先级)和某些类型的广告牌.

Use Point Size(使用点大小)

This option is only effective when the geometry rendered is made of points (generally it's made of triangles when imported from 3D modeling software). If so, then those points can be resized (see below).

Point Size(点大小)

绘制点时,指定点的大小,单位为像素。

Transmission(传输)

这可以控制有多少光从被点亮的一侧(正对灯光)传输到暗侧(背对灯光). 这适用于植物叶子, 草, 人耳等薄物体.

../../_images/spatial_material22.png

Proximity and Distance Fade

Godot allows materials to fade by proximity to each other as well as depending on the distance from the viewer. Proximity fade is useful for effects such as soft particles or a mass of water with a smooth blending to the shores.

../../_images/spatial_material_proxfade.gif

距离渐变适用于在一定距离后才出现的光轴或指示器。

请注意,使用 Pixel Alpha 模式启用近距离渐变或远距离渐变时,会启用 Alpha 混合。Alpha 混合对 GPU 的要求较高,可能会导致透明度排序问题。Alpha 混合也会禁用许多材质功能,例如投射阴影的功能。如果要在角色离摄像机太近时隐藏他们,可以考虑使用**Pixel Dither**或更好的**Object Dither**(它比**Pixel Dither**更快)。

材质设置

Render priority(渲染优先级)

可以更改对象的渲染顺序, 尽管这对于透明对象有用(或执行深度绘制但没有颜色绘制的不透明对象, 例如地板上的裂缝).

下一步

设置下一次渲染使用的材质。这将使用不同的材质再次渲染对象。