standard_material_3d.rst 20 KB

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