spatial_material.rst 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. .. _doc_spatial_material:
  2. Spatial Material
  3. ================
  4. Introduction
  5. ------------
  6. ``SpatialMaterial`` is a default 3D material that aims to provide most of the features
  7. artists look for in a material, without the need for writing shader code. However,
  8. it can be converted to shader code if additional functionality is needed.
  9. This tutorial explains most parameters present in ``SpatialMaterial``.
  10. You can add a ``SpatialMaterial`` to an object by choosing "New SpatialMaterial"
  11. in the *Material* property of the Inspector.
  12. Flags
  13. -----
  14. Spatial materials have many flags determining the general usage of a material.
  15. .. image:: img/spatial_material1.png
  16. Transparent
  17. ~~~~~~~~~~~
  18. In Godot, materials are not transparent unless specifically configured to be.
  19. The main reason behind this is that transparent materials are rendered
  20. using a different technique (sorted from back to front and rendered in order).
  21. This technique is less efficient (many state changes happen) and makes
  22. the materials unusable with many mid- and post-processing effects
  23. (such as SSAO, SSR, etc.) that require perfectly opaque geometry.
  24. For this reason, materials in Godot are assumed opaque unless
  25. specified otherwise. The main settings that enable transparency are:
  26. * Transparent flag (this one)
  27. * Blend mode set to other than "Mix"
  28. * Enabling distance or proximity fade
  29. Unshaded
  30. ~~~~~~~~
  31. In most cases it is common for materials to be affected by lighting (shaded).
  32. However, in some cases you might want to show just the albedo (color) and
  33. ignore the rest. Toggling this flag on will remove all shading and display
  34. pure, unlit color.
  35. .. image:: img/spatial_material26.png
  36. Vertex Lighting
  37. ~~~~~~~~~~~~~~~
  38. Godot has a more or less uniform cost per pixel thanks to depth pre-pass. All
  39. lighting calculations are made by running the lighting shader on every pixel.
  40. As these calculations are costly, performance can be brought down considerably
  41. in some corner cases such as drawing several layers of transparency (which is
  42. common in particle systems). Switching to per-vertex lighting may help in these
  43. cases.
  44. Additionally, on low-end or mobile devices, switching to vertex lighting
  45. can considerably increase rendering performance.
  46. .. image:: img/spatial_material2.png
  47. Keep in mind that when vertex lighting is enabled, only directional lighting
  48. can produce shadows (for performance reasons).
  49. No Depth Test
  50. ~~~~~~~~~~~~~
  51. In order for close objects to appear over far away objects, depth testing
  52. is performed. Disabling it has the result of objects appearing over
  53. (or under) everything else.
  54. Disabling this makes the most sense for drawing indicators in world space,
  55. and works very well with the *Render Priority* property of Material
  56. (see the bottom of this page).
  57. .. image:: img/spatial_material3.png
  58. Use Point Size
  59. ~~~~~~~~~~~~~~~
  60. This option is only effective when the geometry rendered is made of points
  61. (generally it's made of triangles when imported from 3D DCCs). If so, then
  62. those points can be resized (see below).
  63. World Triplanar
  64. ~~~~~~~~~~~~~~~
  65. When using triplanar mapping (see below, in the UV1 and UV2 settings),
  66. triplanar is computed in object local space. This option makes triplanar work
  67. in world space.
  68. Fixed Size
  69. ~~~~~~~~~~
  70. This causes the object to be rendered at the same size no matter the distance.
  71. This is useful mostly for indicators (no depth test and high render priority)
  72. and some types of billboards.
  73. Do Not Receive Shadows
  74. ~~~~~~~~~~~~~~~~~~~~~~
  75. Makes the object not receive any kind of shadow that would otherwise
  76. be cast onto it.
  77. Disable Ambient Light
  78. ~~~~~~~~~~~~~~~~~~~~~
  79. Makes the object not receive any kind of ambient lighting that would
  80. otherwise light it.
  81. Ensure Correct Normals
  82. ~~~~~~~~~~~~~~~~~~~~~~
  83. Fixes normals when non-uniform scaling is used.
  84. Vertex Color
  85. ------------
  86. This setting allows choosing what is done by default to vertex colors that come
  87. from your 3D modelling application. By default they are ignored.
  88. .. image:: img/spatial_material4.png
  89. Use as Albedo
  90. ~~~~~~~~~~~~~
  91. Choosing this option means vertex color is used as albedo color.
  92. Is sRGB
  93. ~~~~~~~
  94. Most 3D DCCs will likely export vertex colors as sRGB, so toggling this
  95. option on will help them look correct.
  96. Parameters
  97. -----------
  98. ``SpatialMaterial`` also has several configurable parameters to tweak
  99. many aspects of the rendering:
  100. .. image:: img/spatial_material5.png
  101. Diffuse Mode
  102. ~~~~~~~~~~~~
  103. Specifies the algorithm used by diffuse scattering of light when hitting
  104. the object. The default is *Burley*. Other modes are also available:
  105. * **Burley:** Default mode, the original Disney Principled PBS diffuse algorithm.
  106. * **Lambert:** Is not affected by roughness.
  107. * **Lambert Wrap:** Extends Lambert to cover more than 90 degrees when
  108. roughness increases. Works great for hair and simulating cheap
  109. subsurface scattering. This implementation is energy conserving.
  110. * **Oren Nayar:** This implementation aims to take microsurfacing into account
  111. (via roughness). Works well for clay-like materials and some types of cloth.
  112. * **Toon:** Provides a hard cut for lighting, with smoothing affected by roughness.
  113. It is recommended you disable sky contribution from your environment's
  114. ambient light settings or disable ambient light in the spatial material
  115. to achieve a better effect.
  116. .. image:: img/spatial_material6.png
  117. Specular Mode
  118. ~~~~~~~~~~~~~
  119. Specifies how the specular blob will be rendered. The specular blob
  120. represents the shape of a light source reflected in the object.
  121. * **ShlickGGX:** The most common blob used by PBR 3D engines nowadays.
  122. * **Blinn:** Common in previous-generation engines.
  123. Not worth using nowadays, but left here for the sake of compatibility.
  124. * **Phong:** Same as above.
  125. * **Toon:** Creates a toon blob, which changes size depending on roughness.
  126. * **Disabled:** Sometimes the blob gets in the way. Begone!
  127. .. image:: img/spatial_material7.png
  128. Blend Mode
  129. ~~~~~~~~~~
  130. Controls the blend mode for the material. Keep in mind that any mode
  131. other than *Mix* forces the object to go through the transparent pipeline.
  132. * **Mix:** Default blend mode, alpha controls how much the object is visible.
  133. * **Add:** Object is blended additively, nice for flares or some
  134. fire-like effects.
  135. * **Sub:** Object is subtracted.
  136. * **Mul:** Object is multiplied.
  137. .. image:: img/spatial_material8.png
  138. Cull Mode
  139. ~~~~~~~~~
  140. Determines which side of the object is not drawn when backfaces are rendered:
  141. * **Back:** The back of the object is culled when not visible (default).
  142. * **Front:** The front of the object is culled when not visible.
  143. * **Disabled:** Used for objects that are double-sided (no culling is performed).
  144. Depth Draw Mode
  145. ~~~~~~~~~~~~~~~
  146. Specifies when depth rendering must take place.
  147. * **Opaque Only (default):** Depth is only drawn for opaque objects.
  148. * **Always:** Depth draw is drawn for both opaque and transparent objects.
  149. * **Never:** No depth draw takes place
  150. (do not confuse this with the No Depth Test option above).
  151. * **Depth Pre-Pass:** For transparent objects, an opaque pass is made first
  152. with the opaque parts, then transparency is drawn above.
  153. Use this option with transparent grass or tree foliage.
  154. .. image:: img/material_depth_draw.png
  155. Line Width
  156. ~~~~~~~~~~
  157. When drawing lines, specify the width of the lines being drawn.
  158. This option is not available on most modern hardware.
  159. Point Size
  160. ~~~~~~~~~~
  161. When drawing points, specify the point size in pixels.
  162. Billboard Mode
  163. ~~~~~~~~~~~~~~
  164. Enables billboard mode for drawing materials. This controls how the object
  165. faces the camera:
  166. * **Disabled:** Billboard mode is disabled.
  167. * **Enabled:** Billboard mode is enabled, the object's -Z axis will always
  168. face the camera.
  169. * **Y-Billboard:** The object's X axis will always be aligned with the camera.
  170. * **Particles:** Most suited for particle systems, because it allows
  171. specifying animation options.
  172. .. image:: img/spatial_material9.png
  173. The above options are only enabled for Particle Billboard.
  174. Billboard Keep Scale
  175. ~~~~~~~~~~~~~~~~~~~~
  176. Enables scaling a mesh in billboard mode.
  177. Grow
  178. ~~~~
  179. Grows the object vertices in the direction pointed by their normals:
  180. .. image:: img/spatial_material10.png
  181. This is commonly used to create cheap outlines. Add a second material pass,
  182. make it black and unshaded, reverse culling (Cull Front), and add some grow:
  183. .. image:: img/spatial_material11.png
  184. Use Alpha Scissor
  185. ~~~~~~~~~~~~~~~~~
  186. When transparency other than ``0`` or ``1`` is not needed, it's possible to
  187. set a threshold to prevent the object from rendering semi-transparent pixels.
  188. .. image:: img/spatial_material12.png
  189. This renders the object via the opaque pipeline, which is faster and allows it
  190. to use mid- and post-process effects such as SSAO, SSR, etc.
  191. Material colors, maps and channels
  192. ----------------------------------
  193. Besides the parameters, what defines materials themselves are the colors,
  194. textures, and channels. Godot supports an extensive list of them. They are
  195. described in detail below:
  196. Albedo
  197. ~~~~~~
  198. *Albedo* is the base color for the material, on which all the other settings
  199. operate. When set to *Unshaded*, this is the only color that is visible. In
  200. previous versions of Godot, this channel was named *Diffuse*. The change
  201. of name mainly happened because, in PBR (Physically Based Rendering), this color affects many
  202. more calculations than just the diffuse lighting path.
  203. Albedo color and texture can be used together as they are multiplied.
  204. *Alpha channel* in albedo color and texture is also used for the
  205. object transparency. If you use a color or texture with *alpha channel*,
  206. make sure to either enable transparency or *alpha scissoring* for it to work.
  207. Metallic
  208. ~~~~~~~~
  209. Godot uses a metallic model over competing models due to its simplicity.
  210. This parameter defines how reflective the material is. The more reflective, the
  211. less diffuse/ambient light affects the material and the more light is reflected.
  212. This model is called "energy-conserving".
  213. The *Specular* parameter is a general amount for the reflectivity (unlike
  214. *Metallic*, this is not energy-conserving, so leave it at ``0.5`` and don't touch
  215. it unless you need to).
  216. The minimum internal reflectivity is ``0.04``, so it's impossible to make a
  217. material completely unreflective, just like in real life.
  218. .. image:: img/spatial_material13.png
  219. Roughness
  220. ~~~~~~~~~
  221. *Roughness* affects the way reflection happens. A value of ``0`` makes it a
  222. perfect mirror while a value of ``1`` completely blurs the reflection (simulating
  223. natural microsurfacing). Most common types of materials can be achieved with
  224. the right combination of *Metallic* and *Roughness*.
  225. .. image:: img/spatial_material14.png
  226. Emission
  227. ~~~~~~~~
  228. *Emission* specifies how much light is emitted by the material (keep in mind this
  229. does not include light surrounding geometry unless :ref:`doc_gi_probes` are used).
  230. This value is added to the resulting final image and is not affected by other
  231. lighting in the scene.
  232. .. image:: img/spatial_material15.png
  233. Normalmap
  234. ~~~~~~~~~
  235. Normal mapping allows you to set a texture that represents finer shape detail.
  236. This does not modify geometry, only the incident angle for light. In Godot,
  237. only the red and green channels of normal maps are used for wider compatibility.
  238. .. image:: img/spatial_material16.png
  239. Rim
  240. ~~~
  241. Some fabrics have small micro-fur that causes light to scatter around it. Godot
  242. emulates this with the *Rim* parameter. Unlike other rim lighting implementations,
  243. which just use the emission channel, this one actually takes light into account
  244. (no light means no rim). This makes the effect considerably more believable.
  245. .. image:: img/spatial_material17.png
  246. Rim size depends on roughness, and there is a special parameter to specify how
  247. it must be colored. If *Tint* is ``0``, the color of the light is used for the
  248. rim. If *Tint* is ``1``, then the albedo of the material is used. Using
  249. intermediate values generally works best.
  250. Clearcoat
  251. ~~~~~~~~~
  252. *This feature is only available when using the GLES3 backend.*
  253. The *Clearcoat* parameter is used to add a secondary pass of transparent coat
  254. to the material. This is common in car paint and toys. In practice, it's a
  255. smaller specular blob added on top of the existing material.
  256. Anisotropy
  257. ~~~~~~~~~~
  258. *This feature is only available when using the GLES3 backend.*
  259. This changes the shape of the specular blob and aligns it to tangent space.
  260. Anisotropy is commonly used with hair, or to make materials such as brushed
  261. aluminum more realistic. It works especially well when combined with flowmaps.
  262. .. image:: img/spatial_material18.png
  263. Ambient Occlusion
  264. ~~~~~~~~~~~~~~~~~~
  265. It is possible to specify a baked ambient occlusion map. This map affects how
  266. much ambient light reaches each surface of the object (it does not affect direct
  267. light by default). While it is possible to use Screen-Space Ambient Occlusion
  268. (SSAO) to generate ambient occlusion, nothing beats the quality of a well-baked
  269. AO map. It is recommended to bake ambient occlusion whenever possible.
  270. .. image:: img/spatial_material19.png
  271. Depth
  272. ~~~~~
  273. *This feature is only available when using the GLES3 backend.*
  274. Setting a depth map on a material produces a ray-marched search to emulate the
  275. proper displacement of cavities along the view direction. This is not real
  276. added geometry, but an illusion of depth. It may not work for complex objects,
  277. but it produces a realistic depth effect for textures. For best results,
  278. *Depth* should be used together with normal mapping.
  279. .. image:: img/spatial_material20.png
  280. Subsurface Scattering
  281. ~~~~~~~~~~~~~~~~~~~~~
  282. *This feature is only available when using the GLES3 backend.*
  283. This effect emulates light that penetrates an object's surface, is scattered,
  284. and then comes out. It is useful to create realistic skin, marble, colored
  285. liquids, etc.
  286. .. image:: img/spatial_material21.png
  287. Transmission
  288. ~~~~~~~~~~~~
  289. This controls how much light from the lit side (visible to light) is transferred
  290. to the dark side (opposite from the light). This works well for thin objects
  291. such as plant leaves, grass, human ears, etc.
  292. .. image:: img/spatial_material22.png
  293. Refraction
  294. ~~~~~~~~~~~
  295. *This feature is only available when using the GLES3 backend.*
  296. When refraction is enabled, it supersedes alpha blending, and Godot attempts to
  297. fetch information from behind the object being rendered instead. This allows
  298. distorting the transparency in a way similar to refraction in real life.
  299. .. image:: img/spatial_material23.png
  300. Detail
  301. ~~~~~~
  302. Godot allows using secondary albedo and normal maps to generate a detail
  303. texture, which can be blended in many ways. By combining this with secondary
  304. UV or triplanar modes, many interesting textures can be achieved.
  305. .. image:: img/spatial_material24.png
  306. UV1 and UV2
  307. ~~~~~~~~~~~~
  308. Godot supports two UV channels per material. Secondary UV is often useful for
  309. ambient occlusion or emission (baked light). UVs can be scaled and offset,
  310. which is useful when using repeating textures.
  311. Triplanar Mapping
  312. ~~~~~~~~~~~~~~~~~
  313. Triplanar mapping is supported for both UV1 and UV2. This is an alternative way
  314. to obtain texture coordinates, sometimes called "Autotexture". Textures are
  315. sampled in X, Y and Z and blended by the normal. Triplanar mapping can be
  316. performed in either world space or object space.
  317. In the image below, you can see how all primitives share the same material with
  318. world triplanar, so the brick texture continues smoothly between them.
  319. .. image:: img/spatial_material25.png
  320. Proximity and distance fade
  321. ----------------------------
  322. Godot allows materials to fade by proximity to each other as well as depending
  323. on the distance from the viewer. Proximity fade is useful for effects such as
  324. soft particles or a mass of water with a smooth blending to the shores. Distance
  325. fade is useful for light shafts or indicators that are only present after a
  326. given distance.
  327. Keep in mind enabling these enables alpha blending, so abusing them for an
  328. entire scene is usually not a good idea.
  329. .. image:: img/spatial_material_proxfade.gif
  330. Render priority
  331. ---------------
  332. The rendering order of objects can be changed, although this is mostly
  333. useful for transparent objects (or opaque objects that perform depth draw
  334. but no color draw, such as cracks on the floor).