spatial_material.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. .. note::
  158. By default, Blender has backface culling disabled on materials and will
  159. export materials to match how they render in Blender. This means that
  160. materials in Godot will have their cull mode set to **Disabled**. This can
  161. decrease performance since backfaces will be rendered, even when they are
  162. being culled by other faces. To resolve this, enable **Backface Culling** in
  163. Blender's Materials tab, then export the scene to glTF again.
  164. Depth Draw Mode
  165. ~~~~~~~~~~~~~~~
  166. Specifies when depth rendering must take place.
  167. * **Opaque Only (default):** Depth is only drawn for opaque objects.
  168. * **Always:** Depth draw is drawn for both opaque and transparent objects.
  169. * **Never:** No depth draw takes place
  170. (do not confuse this with the No Depth Test option above).
  171. * **Depth Pre-Pass:** For transparent objects, an opaque pass is made first
  172. with the opaque parts, then transparency is drawn above.
  173. Use this option with transparent grass or tree foliage.
  174. .. image:: img/material_depth_draw.png
  175. Line Width
  176. ~~~~~~~~~~
  177. When drawing lines, specify the width of the lines being drawn.
  178. This option is not available on most modern hardware.
  179. Point Size
  180. ~~~~~~~~~~
  181. When drawing points, specify the point size in pixels.
  182. Billboard Mode
  183. ~~~~~~~~~~~~~~
  184. Enables billboard mode for drawing materials. This controls how the object
  185. faces the camera:
  186. * **Disabled:** Billboard mode is disabled.
  187. * **Enabled:** Billboard mode is enabled, the object's -Z axis will always
  188. face the camera.
  189. * **Y-Billboard:** The object's X axis will always be aligned with the camera.
  190. * **Particles:** Most suited for particle systems, because it allows
  191. specifying animation options.
  192. .. image:: img/spatial_material9.png
  193. The above options are only enabled for Particle Billboard.
  194. Billboard Keep Scale
  195. ~~~~~~~~~~~~~~~~~~~~
  196. Enables scaling a mesh in billboard mode.
  197. Grow
  198. ~~~~
  199. Grows the object vertices in the direction pointed by their normals:
  200. .. image:: img/spatial_material10.png
  201. This is commonly used to create cheap outlines. Add a second material pass,
  202. make it black and unshaded, reverse culling (Cull Front), and add some grow:
  203. .. image:: img/spatial_material11.png
  204. Use Alpha Scissor
  205. ~~~~~~~~~~~~~~~~~
  206. When transparency other than ``0`` or ``1`` is not needed, it's possible to
  207. set a threshold to prevent the object from rendering semi-transparent pixels.
  208. .. image:: img/spatial_material12.png
  209. This renders the object via the opaque pipeline, which is faster and allows it
  210. to use mid- and post-process effects such as SSAO, SSR, etc.
  211. Material colors, maps and channels
  212. ----------------------------------
  213. Besides the parameters, what defines materials themselves are the colors,
  214. textures, and channels. Godot supports an extensive list of them. They are
  215. described in detail below:
  216. Albedo
  217. ~~~~~~
  218. *Albedo* is the base color for the material, on which all the other settings
  219. operate. When set to *Unshaded*, this is the only color that is visible. In
  220. previous versions of Godot, this channel was named *Diffuse*. The change
  221. of name mainly happened because, in PBR (Physically Based Rendering), this color affects many
  222. more calculations than just the diffuse lighting path.
  223. Albedo color and texture can be used together as they are multiplied.
  224. *Alpha channel* in albedo color and texture is also used for the
  225. object transparency. If you use a color or texture with *alpha channel*,
  226. make sure to either enable transparency or *alpha scissoring* for it to work.
  227. Metallic
  228. ~~~~~~~~
  229. Godot uses a metallic model over competing models due to its simplicity.
  230. This parameter defines how reflective the material is. The more reflective, the
  231. less diffuse/ambient light affects the material and the more light is reflected.
  232. This model is called "energy-conserving".
  233. The *Specular* parameter is a general amount for the reflectivity (unlike
  234. *Metallic*, this is not energy-conserving, so leave it at ``0.5`` and don't touch
  235. it unless you need to).
  236. The minimum internal reflectivity is ``0.04``, so it's impossible to make a
  237. material completely unreflective, just like in real life.
  238. .. image:: img/spatial_material13.png
  239. Roughness
  240. ~~~~~~~~~
  241. *Roughness* affects the way reflection happens. A value of ``0`` makes it a
  242. perfect mirror while a value of ``1`` completely blurs the reflection (simulating
  243. natural microsurfacing). Most common types of materials can be achieved with
  244. the right combination of *Metallic* and *Roughness*.
  245. .. image:: img/spatial_material14.png
  246. Emission
  247. ~~~~~~~~
  248. *Emission* specifies how much light is emitted by the material (keep in mind this
  249. does not include light surrounding geometry unless :ref:`doc_gi_probes` are used).
  250. This value is added to the resulting final image and is not affected by other
  251. lighting in the scene.
  252. .. image:: img/spatial_material15.png
  253. Normal map
  254. ~~~~~~~~~~
  255. Normal mapping allows you to set a texture that represents finer shape detail.
  256. This does not modify geometry, only the incident angle for light. In Godot,
  257. only the red and green channels of normal maps are used for better compression
  258. and wider compatibility.
  259. .. image:: img/spatial_material16.png
  260. .. note::
  261. Godot requires the normal map to use the X+, Y+ and Z+ coordinates, this is
  262. known as OpenGL style. If you've imported a material made to be used with
  263. another engine it may be DirectX style, in which case the normal map needs to
  264. be converted so its Y axis is flipped.
  265. More information about normal maps (including a coordinate order table for
  266. popular engines) can be found
  267. `here <http://wiki.polycount.com/wiki/Normal_Map_Technical_Details>`__.
  268. Rim
  269. ~~~
  270. Some fabrics have small micro-fur that causes light to scatter around it. Godot
  271. emulates this with the *Rim* parameter. Unlike other rim lighting implementations,
  272. which just use the emission channel, this one actually takes light into account
  273. (no light means no rim). This makes the effect considerably more believable.
  274. .. image:: img/spatial_material17.png
  275. Rim size depends on roughness, and there is a special parameter to specify how
  276. it must be colored. If *Tint* is ``0``, the color of the light is used for the
  277. rim. If *Tint* is ``1``, then the albedo of the material is used. Using
  278. intermediate values generally works best.
  279. Clearcoat
  280. ~~~~~~~~~
  281. *This feature is only available when using the GLES3 backend.*
  282. The *Clearcoat* parameter is used to add a secondary pass of transparent coat
  283. to the material. This is common in car paint and toys. In practice, it's a
  284. smaller specular blob added on top of the existing material.
  285. Anisotropy
  286. ~~~~~~~~~~
  287. *This feature is only available when using the GLES3 backend.*
  288. This changes the shape of the specular blob and aligns it to tangent space.
  289. Anisotropy is commonly used with hair, or to make materials such as brushed
  290. aluminum more realistic. It works especially well when combined with flowmaps.
  291. .. image:: img/spatial_material18.png
  292. Ambient Occlusion
  293. ~~~~~~~~~~~~~~~~~~
  294. It is possible to specify a baked ambient occlusion map. This map affects how
  295. much ambient light reaches each surface of the object (it does not affect direct
  296. light by default). While it is possible to use Screen-Space Ambient Occlusion
  297. (SSAO) to generate ambient occlusion, nothing beats the quality of a well-baked
  298. AO map. It is recommended to bake ambient occlusion whenever possible.
  299. .. image:: img/spatial_material19.png
  300. Depth
  301. ~~~~~
  302. *This feature is only available when using the GLES3 backend.*
  303. Setting a depth map on a material produces a ray-marched search to emulate the
  304. proper displacement of cavities along the view direction. This is not real
  305. added geometry, but an illusion of depth. It may not work for complex objects,
  306. but it produces a realistic depth effect for textures. For best results,
  307. *Depth* should be used together with normal mapping.
  308. .. image:: img/spatial_material20.png
  309. Subsurface Scattering
  310. ~~~~~~~~~~~~~~~~~~~~~
  311. *This feature is only available when using the GLES3 backend.*
  312. This effect emulates light that penetrates an object's surface, is scattered,
  313. and then comes out. It is useful to create realistic skin, marble, colored
  314. liquids, etc.
  315. .. image:: img/spatial_material21.png
  316. Transmission
  317. ~~~~~~~~~~~~
  318. This controls how much light from the lit side (visible to light) is transferred
  319. to the dark side (opposite from the light). This works well for thin objects
  320. such as plant leaves, grass, human ears, etc.
  321. .. image:: img/spatial_material22.png
  322. Refraction
  323. ~~~~~~~~~~~
  324. *This feature is only available when using the GLES3 backend.*
  325. When refraction is enabled, it supersedes alpha blending, and Godot attempts to
  326. fetch information from behind the object being rendered instead. This allows
  327. distorting the transparency in a way similar to refraction in real life.
  328. .. image:: img/spatial_material23.png
  329. Detail
  330. ~~~~~~
  331. Godot allows using secondary albedo and normal maps to generate a detail
  332. texture, which can be blended in many ways. By combining this with secondary
  333. UV or triplanar modes, many interesting textures can be achieved.
  334. .. image:: img/spatial_material24.png
  335. There are several settings that control how detail is used.
  336. Mask: The detail mask is a black and white image used to control where the
  337. blending takes place on a texture. White is for the detail textures, Black
  338. is for the regular material textures, different shades of gray are for
  339. partial blending of the material textures and detail textures.
  340. Blend Mode: These four modes control how the textures are blended together.
  341. - Mix: Combines pixel values of both textures. At black, only show the material texture,
  342. at white, only show the detail texture. Values of gray create a smooth blend between
  343. the two.
  344. - Add: Adds pixel values of one Texture with the other. Unlike mix mode
  345. both textures are completely mixed at white parts of a mask and not at gray
  346. parts. The original texture is mostly unchanged at black
  347. - Sub: Subtracts pixel values of one texture with the other. The second
  348. texture is completely subtracted at white parts of a mask with only a little
  349. subtraction in black parts, gray parts being different levels of subtraction
  350. based on the exact texture.
  351. - Mul: Multiplies the RGB channel numbers for each pixel from the top texture
  352. with the values for the corresponding pixel from the bottom texture.
  353. Albedo: This is where you put an albedo texture you want to blend. If nothing
  354. is in this slot it will be interpreted as white by default.
  355. Normal: This is where you put a normal texture you want to blend. If nothing is
  356. in this slot it will be interpreted as a flat normal map. This can still be used
  357. even if the material does not have normal map enabled.
  358. UV1 and UV2
  359. ~~~~~~~~~~~~
  360. Godot supports two UV channels per material. Secondary UV is often useful for
  361. ambient occlusion or emission (baked light). UVs can be scaled and offset,
  362. which is useful when using repeating textures.
  363. Triplanar Mapping
  364. ~~~~~~~~~~~~~~~~~
  365. Triplanar mapping is supported for both UV1 and UV2. This is an alternative way
  366. to obtain texture coordinates, sometimes called "Autotexture". Textures are
  367. sampled in X, Y and Z and blended by the normal. Triplanar mapping can be
  368. performed in either world space or object space.
  369. In the image below, you can see how all primitives share the same material with
  370. world triplanar, so the brick texture continues smoothly between them.
  371. .. image:: img/spatial_material25.png
  372. Proximity and distance fade
  373. ----------------------------
  374. Godot allows materials to fade by proximity to each other as well as depending
  375. on the distance from the viewer. Proximity fade is useful for effects such as
  376. soft particles or a mass of water with a smooth blending to the shores. Distance
  377. fade is useful for light shafts or indicators that are only present after a
  378. given distance.
  379. Keep in mind enabling these enables alpha blending, so abusing them for an
  380. entire scene is usually not a good idea.
  381. .. image:: img/spatial_material_proxfade.gif
  382. Render priority
  383. ---------------
  384. The rendering order of objects can be changed, although this is mostly
  385. useful for transparent objects (or opaque objects that perform depth draw
  386. but no color draw, such as cracks on the floor).