baked_lightmaps.rst 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. .. _doc_baked_lightmaps:
  2. Baked lightmaps
  3. ===============
  4. Introduction
  5. ------------
  6. Baked lightmaps are an alternative workflow for adding indirect (or baked)
  7. lighting to a scene. Unlike the :ref:`doc_gi_probes` approach,
  8. baked lightmaps work fine on low-end PCs and mobile devices, as they consume
  9. almost no resources at run-time.
  10. Unlike ``GIProbe``\ s, Baked Lightmaps are completely static. Once baked, they can't be
  11. modified at all. They also don't provide the scene with
  12. reflections, so using :ref:`doc_reflection_probes` together with it on interiors
  13. (or using a Sky on exteriors) is a requirement to get good quality.
  14. As they are baked, they have fewer problems than ``GIProbe`` regarding light bleeding,
  15. and indirect light can look better if using Raytrace
  16. mode on high quality setting (but baking can take a while).
  17. In the end, deciding which indirect lighting approach is better depends on your
  18. use case. In general, GIProbe looks better and is much
  19. easier to set up. For mobile or low-end compatibility, though, Baked Lightmaps
  20. are your only choice.
  21. Visual comparison
  22. -----------------
  23. Here are some comparisons of how Baked Lightmaps vs. GIProbe look. Notice that
  24. lightmaps are more accurate, but also suffer from the fact
  25. that lighting is on an unwrapped texture, so transitions and resolution may not
  26. be that good. GIProbe looks less accurate (as it's an approximation), but
  27. smoother overall.
  28. .. image:: img/baked_light_comparison.png
  29. Setting up
  30. ----------
  31. First of all, before the lightmapper can do anything, the objects to be baked need
  32. an UV2 layer and a texture size. An UV2 layer is a set of secondary texture coordinates
  33. that ensures any face in the object has its own place in the UV map. Faces must
  34. not share pixels in the texture.
  35. There are a few ways to ensure your object has a unique UV2 layer and texture size:
  36. Unwrap from your 3D DCC
  37. ~~~~~~~~~~~~~~~~~~~~~~~
  38. One option is to do it from your favorite 3D app. This approach is generally
  39. not recommended, but it's explained first so that you know it exists.
  40. The main advantage is that, on complex objects that you may want to re-import a
  41. lot, the texture generation process can be quite costly within Godot,
  42. so having it unwrapped before import can be faster.
  43. Simply do an unwrap on the second UV2 layer.
  44. .. image:: img/baked_light_blender.png
  45. And import normally. Remember you will need to set the texture size on the mesh
  46. after import.
  47. .. image:: img/baked_light_lmsize.png
  48. If you use external meshes on import, the size will be kept.
  49. Be wary that most unwrappers in 3D DCCs are not quality oriented, as they are
  50. meant to work quickly. You will mostly need to use seams or other techniques to
  51. create better unwrapping.
  52. Unwrap from within Godot
  53. ~~~~~~~~~~~~~~~~~~~~~~~~
  54. Godot has an option to unwrap meshes and visualize the UV channels.
  55. It can be found in the Mesh menu:
  56. .. image:: img/baked_light_mesh_menu.png
  57. This will generate a second set of UV2 coordinates which can be used for baking,
  58. and it will also set the texture size automatically.
  59. Unwrap on scene import
  60. ~~~~~~~~~~~~~~~~~~~~~~
  61. This is probably the best approach overall. The only downside is that, on large
  62. models, unwrapping can take a while on import.
  63. Just select the imported scene in the filesystem dock, then go to the Import tab.
  64. There, the following option can be modified:
  65. .. image:: img/baked_light_import.png
  66. The **Light Baking** mode needs to be set to **"Gen Lightmaps"**. A texel size
  67. in world units must also be provided, as this will determine the
  68. final size of the lightmap texture (and, in consequence, the UV padding in the map).
  69. The effect of setting this option is that all meshes within the scene will have
  70. their UV2 maps properly generated.
  71. As a word of warning: When reusing a mesh within a scene, keep in mind that UVs
  72. will be generated for the first instance found. If the mesh is re-used with different
  73. scales (and the scales are wildly different, more than half or twice), this will
  74. result in inefficient lightmaps. Just don't reuse a source mesh at different scales
  75. if you are planning to use lightmapping.
  76. Checking UV2
  77. ~~~~~~~~~~~~
  78. In the mesh menu mentioned before, the UV2 texture coordinates can be visualized.
  79. Make sure, if something is failing, to check that the meshes have these UV2 coordinates:
  80. .. image:: img/baked_light_uvchannel.png
  81. Setting up the scene
  82. --------------------
  83. Before anything is done, a **BakedLightmap** Node needs to be added to a scene.
  84. This will enable light baking on all nodes (and sub-nodes) in that scene, even
  85. on instanced scenes.
  86. .. image:: img/baked_light_scene.png
  87. A sub-scene can be instanced several times, as this is supported by the baker, and
  88. each will be assigned a lightmap of its own (just make sure to respect the rule
  89. about scaling mentioned before):
  90. Configure bounds
  91. ~~~~~~~~~~~~~~~~
  92. Lightmap needs an approximate volume of the area affected because it uses it to
  93. transfer light to dynamic objects inside it (more on that later). Just
  94. cover the scene with the volume as you do with ``GIProbe``:
  95. .. image:: img/baked_light_bounds.png
  96. Setting up meshes
  97. ~~~~~~~~~~~~~~~~~
  98. For a **MeshInstance** node to take part in the baking process, it needs to have
  99. the "Use in Baked Light" property enabled.
  100. .. image:: img/baked_light_use.png
  101. When auto-generating lightmaps on scene import, this is enabled automatically.
  102. Setting up lights
  103. ~~~~~~~~~~~~~~~~~
  104. Lights are baked with indirect light by default. This means that shadowmapping
  105. and lighting are still dynamic and affect moving objects, but light bounces from
  106. that light will be baked.
  107. Lights can be disabled (no bake) or be fully baked (direct and indirect). This
  108. can be controlled from the **Bake Mode** menu in lights:
  109. .. image:: img/baked_light_bake_mode.png
  110. The modes are:
  111. - **Disabled:** Light is ignored in baking. Keep in mind hiding a light will have no effect for baking, so this must be used instead.
  112. - **Indirect:** This is the default mode. Only indirect lighting will be baked.
  113. - **All:** Both indirect and direct lighting will be baked. If you don't want the light to appear twice (dynamically and statically), simply hide it.
  114. Baking quality
  115. ~~~~~~~~~~~~~~
  116. ``BakedLightmap`` uses, for simplicity, a voxelized version of the scene to compute
  117. lighting. Voxel size can be adjusted with the **Bake Subdiv** parameter.
  118. More subdivision results in more detail, but also takes more time to bake.
  119. In general, the defaults are good enough. There is also a **Capture Subdivision**
  120. (that must always be equal to or less than the main subdivision), which is used
  121. for capturing light in dynamic objects (more on that later). Its default value
  122. is also good enough for most cases.
  123. .. image:: img/baked_light_capture.png
  124. Besides the capture size, quality can be modified by setting the **Bake Mode**.
  125. Two modes of capturing indirect are provided:
  126. .. image:: img/baked_light_mode.png
  127. - **Voxel Cone**: Trace: Is the default one; it's less precise, but faster. Looks similar to (but slightly better than) ``GIProbe``.
  128. - **Ray Tracing**: This method is more precise, but can take considerably longer to bake. If used in low or medium quality, some scenes may produce grain.
  129. Baking
  130. ------
  131. To begin the bake process, just push the big **Bake Lightmaps** button on top
  132. when selecting the ``BakedLightmap`` node:
  133. .. image:: img/baked_light_bake.png
  134. This can take from seconds to minutes (or hours) depending on scene size, bake
  135. method and quality selected.
  136. Configuring bake
  137. ~~~~~~~~~~~~~~~~
  138. Several more options are present for baking:
  139. - **Bake Subdiv**: The Godot lightmapper uses a grid to transfer light information around; the default value is fine and should work for most cases. Increase it in case you want better lighting on small details or your scene is large.
  140. - **Capture Subdiv**: This is the grid used for real-time capture information (lighting dynamic objects). Default value is generally OK, it's usually smaller than Bake Subdiv and can't be larger than it.
  141. - **Bake Quality**: Three bake quality modes are provided, Low, Medium and High. Higher quality takes more time.
  142. - **Bake Mode**: The baker can use two different techniques: *Voxel Cone Tracing* (fast, but approximate), or *RayTracing* (slow, but accurate).
  143. - **Propagation**: Used for the *Voxel Cone Trace* mode. Works just like in ``GIProbe``.
  144. - **HDR**: If disabled, lightmaps are smaller, but can't capture any light over white (1.0).
  145. - **Image Path**: Where lightmaps will be saved. By default, on the same directory as the scene ("."), but can be tweaked.
  146. - **Extents**: Size of the area affected (can be edited visually)
  147. - **Light Data**: Contains the light baked data after baking. Textures are saved to disk, but this also contains the capture data for dynamic objects, which can be a bit heavy. If you are using .tscn formats (instead of .scn), you can save it to disk.
  148. Dynamic objects
  149. ---------------
  150. In other engines or lightmapper implementations, you are required to manually
  151. place small objects called "lightprobes" all around the level to generate *capture*
  152. data. This is used to, then, transfer the light to dynamic objects that move
  153. around the scene.
  154. However, this implementation of lightmapping uses a different method. The process is
  155. automatic, so you don't have to do anything. Just move your objects around, and
  156. they will be lit accordingly. Of course, you have to make sure you set up your
  157. scene bounds accordingly or it won't work.
  158. .. image:: img/baked_light_indirect.gif