spatial_material.rst 19 KB

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