using_decals.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. .. _doc_using_decals:
  2. Using decals
  3. ============
  4. .. note::
  5. Decals are only supported in the Clustered Forward and Forward Mobile
  6. rendering backends, not the Compatibility backend.
  7. If using the Compatibility backend, consider using Sprite3D as an alternative
  8. for projecting decals onto (mostly) flat surfaces.
  9. Decals are projected textures that apply on opaque or transparent surfaces in
  10. 3D. This projection happens in real-time and doesn't rely on mesh generation.
  11. This allows you to move decals every frame with only a small performance impact,
  12. even when applied on complex meshes.
  13. While decals cannot add actual geometry detail onto the projected surface,
  14. decals can still make use of physically-based rendering to provide similar
  15. properties to full-blown :abbr:`PBR (Physically-Based Rendering)` materials.
  16. On this page, you'll learn:
  17. - How to set up decals in the 3D editor.
  18. - How to create decals during gameplay in a 3D scene (such as bullet impacts).
  19. - How to balance decal configuration between performance and quality.
  20. .. seealso::
  21. The Godot demo projects repository contains a
  22. `3D decals demo <https://github.com/godotengine/godot-demo-projects/tree/4.0-dev/3d/decals>`__.
  23. If you're looking to write arbitrary 3D text on top of a surface, use
  24. :ref:`doc_3d_text` placed close to a surface instead of a Decal node.
  25. Use cases
  26. ---------
  27. Static decoration
  28. ^^^^^^^^^^^^^^^^^
  29. Sometimes, the fastest way to add texture detail to a scene is to use decals.
  30. This is especially the case for organic detail, such as patches of dirt or sand
  31. scattered on a large surface. Decals can help break up texture repetition in
  32. scenes and make patterns look more natural. On a smaller scale, decals can also
  33. be used to create detail variations for objects. For example, decals can be used
  34. to add nuts and bolts on top of hard-surface geometry.
  35. Since decals can inject their own :abbr:`PBR (Physically-Based Rendering)`
  36. properties on top of the projected surfaces, they can also be used to create
  37. footprints or wet puddles.
  38. .. figure:: img/decals_dirt.webp
  39. :align: center
  40. :alt: Dirt added on top of level geometry using decals
  41. Dirt added on top of level geometry using decals
  42. Dynamic gameplay elements
  43. ^^^^^^^^^^^^^^^^^^^^^^^^^
  44. Decals can represent temporary or persistent gameplay effects such as bullet
  45. impacts and explosion scorches.
  46. Using an AnimationPlayer node or a script, decals can be made to fade over time
  47. (and then be removed using ``queue_free()``) to improve performance.
  48. Blob shadows
  49. ^^^^^^^^^^^^
  50. Blob shadows are frequently used in mobile projects (or to follow a retro art
  51. style), as real-time lighting tends to be too expensive on low-end mobile
  52. devices. However, when relying on baked lightmaps with fully baked lights,
  53. dynamic objects will not cast *any* shadow from those lights. This makes dynamic
  54. objects in lightmapped scenes look flat in comparison to real-time lighting,
  55. with dynamic objects almost looking like they're floating.
  56. Thanks to blob shadows, dynamic objects can still cast an approximative shadow.
  57. Not only this helps with depth perception in the scene, but this can also be a
  58. gameplay element, especially in 3D platformers. The blob shadow's length can be
  59. extended to let the player know where they will land if they fall straight down.
  60. Even with real-time lighting, blob shadows can still be useful as a form of
  61. ambient occlusion for situations where SSAO is too expensive or too unstable due
  62. to its screen-space nature. For example, vehicles' underside shadows are
  63. well-represented using blob shadows.
  64. .. figure:: img/decals_blob_shadow.webp
  65. :align: center
  66. :alt: Blob shadow under object comparison
  67. Blob shadow under object comparison
  68. Quick start guide
  69. -----------------
  70. Creating decals in the editor
  71. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  72. 1. Create a Decal node in the 3D editor.
  73. 2. In the inspector, expand the **Textures** section and load a texture in
  74. **Textures > Albedo**.
  75. 3. Move the Decal node towards an object, then rotate it so the decal is visible
  76. (and in the right orientation). If the decal appears mirrored, try to rotate
  77. it by 180 degrees. You can double-check whether it's in the right orientation
  78. by increasing **Parameters > Normal Fade** to 0.5. This will prevent the Decal
  79. from being projected on surfaces that are not facing the decal.
  80. 4. If your decal is meant to affect static objects only, configure it to prevent
  81. affecting dynamic objects (or vice versa). To do so, change the decal's
  82. **Cull Mask** property to exclude certain layers. After doing this, modify
  83. your dynamic objects' MeshInstance3D nodes to change their visibility layers.
  84. For instance, you can move them from layer 1 to layer 2, then disable layer 2
  85. in the decal's **Cull Mask** property.
  86. Decal node properties
  87. ---------------------
  88. - **Extents:** The size of the decal. The Y axis determines the length of the
  89. decal's projection. Keep the projection length as short as possible to improve
  90. culling opportunities, therefore improving performance.
  91. Textures
  92. ^^^^^^^^
  93. - **Albedo:** The albedo (diffuse/color) map to use for the decal. In
  94. most situations, this is the texture you want to set first. If using a normal
  95. or ORM map, an albedo map *must* be set to provide an alpha channel. This
  96. alpha channel will be used as a mask to determine how much the normal/ORM maps
  97. will affect the underlying surface.
  98. - **Normal:** The normal map to use for the decal. This can be used
  99. to increase perceived detail on the decal by modifying how light reacts to it.
  100. The impact of this texture is multiplied by the albedo texture's alpha channel
  101. (but not **Albedo Mix**).
  102. - **ORM:** The Occlusion/Roughness/Metallic map to use for the decal.
  103. This is an optimized format for storing PBR material maps. Ambient Occlusion
  104. map is stored in the red channel, roughness map in the green channel, metallic
  105. map in the blue channel. The impact of this texture is multiplied by the
  106. albedo texture's alpha channel (but not **Albedo Mix**).
  107. - **Emission:** The emission texture to use for the decal. Unlike
  108. **Albedo**, this texture will appear to glow in the dark.
  109. Parameters
  110. ^^^^^^^^^^
  111. - **Emission Energy:** The brightness of the emission texture.
  112. - **Modulate:** Multiplies the color of the albedo and emission textures. Use
  113. this to tint decals (e.g. for paint decals, or to increase variation by
  114. randomizing each decal's modulation).
  115. - **Albedo Mix:** The opacity of the albedo texture. Unlike using an albedo
  116. texture with a more transparent alpha channel, decreasing this value below
  117. ``1.0`` does *not* reduce the impact of the normal/ORM texture on the
  118. underlying surface. Set this to ``0.0`` when creating normal/ORM-only decals
  119. such as footsteps or wet puddles.
  120. - **Normal Fade:** Fades the Decal if the angle between the Decal's
  121. :abbr:`AABB (Axis-Aligned Bounding Box)` and the target surface becomes too large.
  122. A value of ``0.0`` projects the decal regardless of angle, while a value of ``0.999``
  123. limits the decal to surfaces that are nearly perpendicular. Setting **Normal
  124. Fade** to a value greater than ``0.0`` has a small performance cost due to the
  125. added normal angle computations.
  126. Vertical Fade
  127. ^^^^^^^^^^^^^
  128. - **Upper Fade:** The curve over which the decal will fade as the surface gets
  129. further from the center of the :abbr:`AABB (Axis-Aligned Bounding Box)`
  130. (towards the decal's projection angle). Only positive values are valid.
  131. - **Lower Fade:** The curve over which the decal will fade as the surface gets
  132. further from the center of the :abbr:`AABB (Axis-Aligned Bounding Box)` (away
  133. from the decal's projection angle). Only positive values are valid.
  134. Distance Fade
  135. ^^^^^^^^^^^^^
  136. - **Enabled:** Controls whether distance fade (a form of :abbr:`LOD (Level of Detail)`)
  137. is enabled. The decal will fade out over **Begin + Length**, after which it
  138. will be culled and not sent to the shader at all. Use this to reduce the number
  139. of active decals in a scene and thus improve performance.
  140. - **Begin:** The distance from the camera at which the decal begins to fade away
  141. (in 3D units).
  142. - **Length:** The distance over which the decal fades (in 3D units). The decal
  143. becomes slowly more transparent over this distance and is completely invisible
  144. at the end. Higher values result in a smoother fade-out transition, which is
  145. more suited when the camera moves fast.
  146. Cull Mask
  147. ^^^^^^^^^
  148. - **Cull Mask:** Specifies which VisualInstance3D layers this decal will project
  149. on. By default, decals affect all layers. This is used so you can specify which
  150. types of objects receive the decal and which do not. This is especially useful
  151. so you can ensure that dynamic objects don't accidentally receive a Decal
  152. intended for the terrain under them.
  153. Tweaking performance and quality
  154. --------------------------------
  155. Decal rendering performance is mostly determined by their screen coverage, but
  156. also their number. In general, a few large decals that cover up most of the
  157. screen will be more expensive to render than many small decals that are
  158. scattered around.
  159. To improve rendering performance, you can enable the **Distance Fade** property
  160. as described above. This will make distant decals fade out when they are far
  161. away from the camera (and may have little to no impact on the final scene
  162. rendering). Using node groups, you can also prevent non-essential decorative
  163. decals from spawning based on user configuration.
  164. The way decals are rendered also has an impact on performance. The **Rendering >
  165. Textures > Decals > Filter** advanced project setting lets you control how decal
  166. textures should be filtered. **Nearest/Linear** does not use mipmaps. However,
  167. decals will look grainy at a distance. **Nearest/Linear Mipmaps** will look
  168. smoother at a distance, but decals will look blurry when viewed from oblique
  169. angles. This can be resolved by using **Nearest/Linear Mipmaps Anisotropic**,
  170. which provides the highest quality but is also slower to render.
  171. If your project has a pixel art style, consider setting the filter to one of the
  172. **Nearest** values so that decals use nearest-neighbor filtering. Otherwise,
  173. stick to **Linear**.
  174. Limitations
  175. -----------
  176. Decals cannot affect material properties other than the ones listed above,
  177. such as height (for parallax mapping).
  178. For performance reasons, decals use purely fixed rendering logic. This means
  179. decals cannot use custom shaders. However, custom shaders on the projected
  180. surfaces are able to read the information that is overridden by decals on top of
  181. them, such as roughness and metallic.
  182. When using the Forward Mobile backend, only 8 decals can be applied on each
  183. individual Mesh *resource*. If there are more decals affecting a single mesh,
  184. not all of them will be rendered on the mesh.