Baked lightmaps

Introduction

Les Baked lightmaps sont un flux de travail alternatif pour ajouter un éclairage indirect (ou préparé) à une scène. Contrairement à l’approche GI Probes, les Baked lightmaps fonctionnent très bien sur les PC et les appareils mobiles bas de gamme, car elles ne consomment pratiquement pas de ressources en temps réel.

Contrairement aux « GIProbe », les Baked lightmaps sont complètement statiques. Une fois préparées, elles ne peuvent pas être modifiées du tout. Elles ne fournissent pas non plus de reflets à la scène, donc l’utilisation de Reflection probes avec elle à l’intérieur (ou l’utilisation d’un Sky à l’extérieur) est une condition pour obtenir une bonne qualité.

Comme elles sont préparées, elles ont moins de problèmes que GIProbe en ce qui concerne le saignement de la lumière, et la lumière indirecte peut sembler meilleure si on utilise le mode Raytrace sur un réglage de haute qualité (mais la préparation peut prendre un certain temps).

En fin de compte, le choix de l’approche d’éclairage indirect qui convient le mieux dépend de votre cas d’utilisation. En général, GIProbe est plus esthétique et beaucoup plus facile à mettre ne place. Pour une compatibilité mobile ou bas de gamme, cependant, les cartes de lumières préparées sont votre seul choix.

Comparaison visuelle

Voici quelques comparaisons entre Baked Lightmaps et GIProbe. Notez que les lightmaps sont plus précises, mais souffrent aussi du fait que l’éclairage est sur une texture non enveloppée, donc les transitions et la résolution peuvent ne pas être aussi bonnes. GIProbe semble moins précis (car c’est une approximation), mais globalement plus lisse.

../../_images/baked_light_comparison.png

Mise en place

Tout d’abord, pour que le Lightmapper puisse faire quoi que ce soit, les objets à préparer ont besoin d’un calque UV2 et d’une taille de texture. Une couche UV2 est un ensemble de coordonnées de texture secondaires garantissant que chaque face de l’objet a sa propre place dans la carte UV. Les faces ne doivent pas partager de pixels dans la texture.

Il y a plusieurs façons de s’assurer qu’un objet dispose d’un calque UV2 et une taille de texture unique :

Déplier depuis votre logiciel 3D

Une option est de le faire depuis votre logiciel de modélisation 3D. Bien que peu recommandée, cette approche est listée ici pour que vous sachiez qu’elle existe. L’avantage principal de cette méthode est de contourner le processus de génération de texture natif de Godot, celui-ci utilisant d’importantes ressources sur des objets complexes. Déplier depuis votre logiciel 3D permet d’accélérer l’importation.

Il suffit simplement de dérouler la deuxième couche d’UV2.

../../_images/baked_light_blender.png

Et importe normalement. N’oubliez pas que vous devrez définir la taille de la texture sur le maillage après l’importation.

../../_images/baked_light_lmsize.png

If you use external meshes on import, the size will be kept. Be wary that most unwrappers in 3D DCCs are not quality oriented, as they are meant to work quickly. You will mostly need to use seams or other techniques to create better unwrapping.

Unwrap from within Godot

Godot has an option to unwrap meshes and visualize the UV channels. It can be found in the Mesh menu:

../../_images/baked_light_mesh_menu.png

This will generate a second set of UV2 coordinates which can be used for baking, and it will also set the texture size automatically.

Unwrap on scene import

This is probably the best approach overall. The only downside is that, on large models, unwrapping can take a while on import. Just select the imported scene in the filesystem dock, then go to the Import tab. There, the following option can be modified:

../../_images/baked_light_import.png

The Light Baking mode needs to be set to « Gen Lightmaps ». A texel size in world units must also be provided, as this will determine the final size of the lightmap texture (and, in consequence, the UV padding in the map).

The effect of setting this option is that all meshes within the scene will have their UV2 maps properly generated.

As a word of warning: When reusing a mesh within a scene, keep in mind that UVs will be generated for the first instance found. If the mesh is re-used with different scales (and the scales are wildly different, more than half or twice), this will result in inefficient lightmaps. Just don’t reuse a source mesh at different scales if you are planning to use lightmapping.

Vérification UV2

Dans le menu de maillage mentionné précédemment, les coordonnées de texture UV2 peuvent être visualisées. S’assurer, si quelque chose ne fonctionne pas, que les mailles ont ces coordonnées UV2 :

../../_images/baked_light_uvchannel.png

Mise en place de la scène

Before anything is done, a BakedLightmap Node needs to be added to a scene. This will enable light baking on all nodes (and sub-nodes) in that scene, even on instanced scenes.

../../_images/baked_light_scene.png

A sub-scene can be instanced several times, as this is supported by the baker, and each will be assigned a lightmap of its own (just make sure to respect the rule about scaling mentioned before):

Configurer les limites

Lightmap needs an approximate volume of the area affected because it uses it to transfer light to dynamic objects inside it (more on that later). Just cover the scene with the volume as you do with GIProbe:

../../_images/baked_light_bounds.png

Mise en place des maillages

For a MeshInstance node to take part in the baking process, it needs to have the « Use in Baked Light » property enabled.

../../_images/baked_light_use.png

When auto-generating lightmaps on scene import, this is enabled automatically.

Mise en place des lumières

Lights are baked with indirect light by default. This means that shadowmapping and lighting are still dynamic and affect moving objects, but light bounces from that light will be baked.

Lights can be disabled (no bake) or be fully baked (direct and indirect). This can be controlled from the Bake Mode menu in lights:

../../_images/baked_light_bake_mode.png

Les modes sont :

  • Disabled: Light is ignored in baking. Keep in mind hiding a light will have no effect for baking, so this must be used instead.
  • Indirect: This is the default mode. Only indirect lighting will be baked.
  • 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.

Baking quality

BakedLightmap uses, for simplicity, a voxelized version of the scene to compute lighting. Voxel size can be adjusted with the Bake Subdiv parameter. More subdivision results in more detail, but also takes more time to bake.

In general, the defaults are good enough. There is also a Capture Subdivision (that must always be equal to or less than the main subdivision), which is used for capturing light in dynamic objects (more on that later). Its default value is also good enough for most cases.

../../_images/baked_light_capture.png

Besides the capture size, quality can be modified by setting the Bake Mode. Two modes of capturing indirect are provided:

../../_images/baked_light_mode.png
  • Voxel Cone: Trace: Is the default one; it’s less precise, but faster. Looks similar to (but slightly better than) GIProbe.
  • 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.

Baking

To begin the bake process, just push the big Bake Lightmaps button on top when selecting the BakedLightmap node:

../../_images/baked_light_bake.png

This can take from seconds to minutes (or hours) depending on scene size, bake method and quality selected.

Configurer la préparation

Several more options are present for baking:

  • 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.
  • 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.
  • Bake Quality: Three bake quality modes are provided, Low, Medium and High. Higher quality takes more time.
  • Bake Mode: The baker can use two different techniques: Voxel Cone Tracing (fast, but approximate), or RayTracing (slow, but accurate).
  • Propagation: Used for the Voxel Cone Trace mode. Works just like in GIProbe.
  • HDR: If disabled, lightmaps are smaller, but can’t capture any light over white (1.0).
  • Image Path: Where lightmaps will be saved. By default, on the same directory as the scene (« . »), but can be tweaked.
  • Extents: Size of the area affected (can be edited visually)
  • 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.

Objets dynamiques

In other engines or lightmapper implementations, you are required to manually place small objects called « lightprobes » all around the level to generate capture data. This is used to, then, transfer the light to dynamic objects that move around the scene.

However, this implementation of lightmapping uses a different method. The process is automatic, so you don’t have to do anything. Just move your objects around, and they will be lit accordingly. Of course, you have to make sure you set up your scene bounds accordingly or it won’t work.

../../_images/baked_light_indirect.gif