spatial_material.rst 15 KB

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