spatial_material.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. Vertex Color
  82. ------------
  83. This setting allows choosing what is done by default to vertex colors that come
  84. from your 3D modelling application. By default they are ignored.
  85. .. image:: img/spatial_material4.png
  86. Use as Albedo
  87. ~~~~~~~~~~~~~
  88. Choosing this option means vertex color is used as albedo color.
  89. Is SRGB
  90. ~~~~~~~
  91. Most 3D DCCs will likely export vertex colors as sRGB, so toggling this
  92. option on will help them look correct.
  93. Parameters
  94. -----------
  95. ``SpatialMaterial`` also has several configurable parameters to tweak
  96. many aspects of the rendering:
  97. .. image:: img/spatial_material5.png
  98. Diffuse Mode
  99. ~~~~~~~~~~~~
  100. Specifies the algorithm used by diffuse scattering of light when hitting
  101. the object. The default is *Burley*. Other modes are also available:
  102. * **Burley:** Default mode, the original Disney Principled PBS diffuse algorithm.
  103. * **Lambert:** Is not affected by roughness.
  104. * **Lambert Wrap:** Extends Lambert to cover more than 90 degrees when
  105. roughness increases. Works great for hair and simulating cheap
  106. subsurface scattering. This implementation is energy conserving.
  107. * **Oren Nayar:** This implementation aims to take microsurfacing into account
  108. (via roughness). Works well for clay-like materials and some types of cloth.
  109. * **Toon:** Provides a hard cut for lighting, with smoothing affected by roughness.
  110. It is recommended you disable sky contribution from your environment's
  111. ambient light settings or disable ambient light in the spatial material
  112. to achieve a better effect.
  113. .. image:: img/spatial_material6.png
  114. Specular Mode
  115. ~~~~~~~~~~~~~
  116. Specifies how the specular blob will be rendered. The specular blob
  117. represents the shape of a light source reflected in the object.
  118. * **ShlickGGX:** The most common blob used by PBR 3D engines nowadays.
  119. * **Blinn:** Common in previous-generation engines.
  120. Not worth using nowadays, but left here for the sake of compatibility.
  121. * **Phong:** Same as above.
  122. * **Toon:** Creates a toon blob, which changes size depending on roughness.
  123. * **Disabled:** Sometimes the blob gets in the way. Begone!
  124. .. image:: img/spatial_material7.png
  125. Blend Mode
  126. ~~~~~~~~~~
  127. Controls the blend mode for the material. Keep in mind that any mode
  128. other than *Mix* forces the object to go through the transparent pipeline.
  129. * **Mix:** Default blend mode, alpha controls how much the object is visible.
  130. * **Add:** Object is blended additively, nice for flares or some
  131. fire-like effects.
  132. * **Sub:** Object is subtracted.
  133. * **Mul:** Object is multiplied.
  134. .. image:: img/spatial_material8.png
  135. Cull Mode
  136. ~~~~~~~~~
  137. Determines which side of the object is not drawn when backfaces are rendered:
  138. * **Back:** The back of the object is culled when not visible (default).
  139. * **Front:** The front of the object is culled when not visible.
  140. * **Disabled:** Used for objects that are double-sided (no culling is performed).
  141. Depth Draw Mode
  142. ~~~~~~~~~~~~~~~
  143. Specifies when depth rendering must take place.
  144. * **Opaque Only (default):** Depth is only drawn for opaque objects.
  145. * **Always:** Depth draw is drawn for both opaque and transparent objects.
  146. * **Never:** No depth draw takes place
  147. (do not confuse this with the No Depth Test option above).
  148. * **Depth Pre-Pass:** For transparent objects, an opaque pass is made first
  149. with the opaque parts, then transparency is drawn above.
  150. Use this option with transparent grass or tree foliage.
  151. .. image:: img/material_depth_draw.png
  152. Line Width
  153. ~~~~~~~~~~
  154. When drawing lines, specify the width of the lines being drawn.
  155. This option is not available on most modern hardware.
  156. Point Size
  157. ~~~~~~~~~~
  158. When drawing points, specify the point size in pixels.
  159. Billboard Mode
  160. ~~~~~~~~~~~~~~
  161. Enables billboard mode for drawing materials. This controls how the object
  162. faces the camera:
  163. * **Disabled:** Billboard mode is disabled.
  164. * **Enabled:** Billboard mode is enabled, the object's -Z axis will always
  165. face the camera.
  166. * **Y-Billboard:** The object's X axis will always be aligned with the camera.
  167. * **Particles:** Most suited for particle systems, because it allows
  168. specifying animation options.
  169. .. image:: img/spatial_material9.png
  170. The above options are only enabled for Particle Billboard.
  171. Grow
  172. ~~~~
  173. Grows the object vertices in the direction pointed by their normals:
  174. .. image:: img/spatial_material10.png
  175. This is commonly used to create cheap outlines. Add a second material pass,
  176. make it black and unshaded, reverse culling (Cull Front), and add some grow:
  177. .. image:: img/spatial_material11.png
  178. Use Alpha Scissor
  179. ~~~~~~~~~~~~~~~~~
  180. When transparency other than ``0`` or ``1`` is not needed, it's possible to
  181. set a threshold to prevent the object from rendering semi-transparent pixels.
  182. .. image:: img/spatial_material12.png
  183. This renders the object via the opaque pipeline, which is faster and allows it
  184. to use mid- and post-process effects such as SSAO, SSR, etc.
  185. Material colors, maps and channels
  186. ----------------------------------
  187. Besides the parameters, what defines materials themselves are the colors,
  188. textures, and channels. Godot supports a extensive list of them. They are
  189. described in detail below:
  190. Albedo
  191. ~~~~~~
  192. *Albedo* is the base color for the material, on which all the other settings
  193. operate. When set to *Unshaded*, this is the only color that is visible. In
  194. previous versions of Godot, this channel was named *Diffuse*. The change
  195. of name mainly happened because, in PBR rendering, this color affects many
  196. more calculations than just the diffuse lighting path.
  197. Albedo color and texture can be used together as they are multiplied.
  198. *Alpha channel* in albedo color and texture is also used for the
  199. object transparency. If you use a color or texture with *alpha channel*,
  200. make sure to either enable transparency or *alpha scissoring* for it to work.
  201. Metallic
  202. ~~~~~~~~
  203. Godot uses a metallic model over competing models due to its simplicity.
  204. This parameter defines how reflective the material is. The more reflective, the
  205. less diffuse/ambient light affects the material and the more light is reflected.
  206. This model is called "energy-conserving".
  207. The *Specular* parameter is a general amount for the reflectivity (unlike
  208. *Metallic*, this is not energy-conserving, so leave it at ``0.5`` and don't touch
  209. it unless you need to).
  210. The minimum internal reflectivity is ``0.04``, so it's impossible to make a
  211. material completely unreflective, just like in real life.
  212. .. image:: img/spatial_material13.png
  213. Roughness
  214. ~~~~~~~~~
  215. *Roughness* affects the way reflection happens. A value of ``0`` makes it a
  216. perfect mirror while a value of ``1`` completely blurs the reflection (simulating
  217. natural microsurfacing). Most common types of materials can be achieved with
  218. the right combination of *Metallic* and *Roughness*.
  219. .. image:: img/spatial_material14.png
  220. Emission
  221. ~~~~~~~~
  222. *Emission* specifies how much light is emitted by the material (keep in mind this
  223. does not include light surrounding geometry unless :ref:`doc_gi_probes` are used).
  224. This value is added to the resulting final image and is not affected by other
  225. lighting in the scene.
  226. .. image:: img/spatial_material15.png
  227. Normalmap
  228. ~~~~~~~~~
  229. Normal mapping allows you to set a texture that represents finer shape detail.
  230. This does not modify geometry, only the incident angle for light. In Godot,
  231. only the red and green channels of normal maps are used for wider compatibility.
  232. .. image:: img/spatial_material16.png
  233. Rim
  234. ~~~
  235. Some fabrics have small micro-fur that causes light to scatter around it. Godot
  236. emulates this with the *Rim* parameter. Unlike other rim lighting implementations
  237. which just use the emission channel, this one actually takes light into account
  238. (no light means no rim). This makes the effect considerably more believable.
  239. .. image:: img/spatial_material17.png
  240. Rim size depends on roughness, and there is a special parameter to specify how
  241. it must be colored. If *Tint* is ``0``, the color of the light is used for the
  242. rim. If *Tint* is ``1``, then the albedo of the material is used. Using
  243. intermediate values generally works best.
  244. Clearcoat
  245. ~~~~~~~~~
  246. The *Clearcoat* parameter is used to add a secondary pass of transparent coat
  247. to the material. This is common in car paint and toys. In practice, it's a
  248. smaller specular blob added on top of the existing material.
  249. Anisotropy
  250. ~~~~~~~~~~
  251. This changes the shape of the specular blob and aligns it to tangent space.
  252. Anisotropy is commonly used with hair, or to make materials such as brushed
  253. aluminum more realistic. It works especially well when combined with flowmaps.
  254. .. image:: img/spatial_material18.png
  255. Ambient Occlusion
  256. ~~~~~~~~~~~~~~~~~~
  257. It is possible to specify a baked ambient occlusion map. This map affects how
  258. much ambient light reaches each surface of the object (it does not affect direct
  259. light by default). While it is possible to use Screen-Space Ambient Occlusion
  260. (SSAO) to generate ambient occlusion, nothing beats the quality of a well-baked
  261. AO map. It is recommended to bake ambient occlusion whenever possible.
  262. .. image:: img/spatial_material19.png
  263. Depth
  264. ~~~~~
  265. Setting a depth map on a material produces a ray-marched search to emulate the
  266. proper displacement of cavities along the view direction. This is not real
  267. added geometry, but an illusion of depth. It may not work for complex objects,
  268. but it produces a realistic depth effect for textures. For best results,
  269. *Depth* should be used together with normal mapping.
  270. .. image:: img/spatial_material20.png
  271. Subsurface Scattering
  272. ~~~~~~~~~~~~~~~~~~~~~
  273. This effect emulates light that penetrates an object's surface, is scattered,
  274. and then comes out. It is useful to create realistic skin, marble, colored
  275. liquids, etc.
  276. .. image:: img/spatial_material21.png
  277. Transmission
  278. ~~~~~~~~~~~~
  279. This controls how much light from the lit side (visible to light) is transferred
  280. to the dark side (opposite from the light). This works well for thin objects
  281. such as plant leaves, grass, human ears, etc.
  282. .. image:: img/spatial_material22.png
  283. Refraction
  284. ~~~~~~~~~~~
  285. When refraction is enabled, it supersedes alpha blending, and Godot attempts to
  286. fetch information from behind the object being rendered instead. This allows
  287. distorting the transparency in a way similar to refraction in real life.
  288. .. image:: img/spatial_material23.png
  289. Detail
  290. ~~~~~~
  291. Godot allows using secondary albedo and normal maps to generate a detail
  292. texture, which can be blended in many ways. By combining this with secondary
  293. UV or triplanar modes, many interesting textures can be achieved.
  294. .. image:: img/spatial_material24.png
  295. UV1 and UV2
  296. ~~~~~~~~~~~~
  297. Godot supports two UV channels per material. Secondary UV is often useful for
  298. ambient occlusion or emission (baked light). UVs can be scaled and offset
  299. which is useful when using repeating textures.
  300. Triplanar Mapping
  301. ~~~~~~~~~~~~~~~~~
  302. Triplanar mapping is supported for both UV1 and UV2. This is an alternative way
  303. to obtain texture coordinates, sometimes called "Autotexture". Textures are
  304. sampled in X, Y and Z and blended by the normal. Triplanar mapping can be
  305. performed in either world space or object space.
  306. In the image below, you can see how all primitives share the same material with
  307. world triplanar, so the brick texture continues smoothly between them.
  308. .. image:: img/spatial_material25.png
  309. Proximity and distance fade
  310. ----------------------------
  311. Godot allows materials to fade by proximity to each other as well as depending
  312. on the distance from the viewer. Proximity fade is useful for effects such as
  313. soft particles or a mass of water with a smooth blending to the shores. Distance
  314. fade is useful for light shafts or indicators that are only present after a
  315. given distance.
  316. Keep in mind enabling these enables alpha blending, so abusing them for an
  317. entire scene is usually not a good idea.
  318. .. image:: img/spatial_material_proxfade.gif
  319. Render priority
  320. ---------------
  321. The rendering order of objects can be changed, although this is mostly
  322. useful for transparent objects (or opaque objects that perform depth draw
  323. but no color draw, such as cracks on the floor).