Skip to content

Commit 4ffef4f

Browse files
authored
Merge pull request #10482 from Calinou/using-lightmap-gi-shadowmask
Document shadowmasks in Using LightmapGI
2 parents 5639d1a + 28a7a0b commit 4ffef4f

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed
Binary file not shown.

tutorials/3d/global_illumination/using_lightmap_gi.rst

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ This mode allows performing *subtle* changes to a light's color, energy and
291291
position while still looking fairly correct. For example, you can use this
292292
to create flickering static torches that have their indirect light baked.
293293

294+
Depending on the value of **Shadowmask Mode**, it is possible to still get
295+
distant baked shadows for DirectionalLight3D. This allows shadows up close to be
296+
real-time and show dynamic objects, while allowing static objects in the
297+
distance to still cast shadows.
298+
294299
Static
295300
~~~~~~
296301

@@ -364,6 +369,12 @@ Tweaks
364369
especially with fully baked lights (since they also have direct light baked).
365370
The downside is that directional lightmaps are slightly more expensive to render.
366371
They also require more time to bake and result in larger file sizes.
372+
- **Shadowmask Mode:** If set to a mode other than **None**, the first DirectionalLight3D
373+
in the scene with the **Dynamic** global illumination mode will have its static shadows
374+
baked to a separate texture called a *shadowmask*. This can be used to allow distant
375+
static objects to cast shadows onto other static objects regardless of the distance
376+
from the camera. See the :ref:`section on shadowmasking <doc_using_lightmap_gi_shadowmask>`
377+
for further details.
367378
- **Interior:** If enabled, environment lighting will not be sourced. Use this
368379
for purely indoor scenes to avoid light leaks.
369380
- **Use Texture for Bounces:** If enabled, a texture with the lighting
@@ -397,6 +408,74 @@ Tweaks
397408
- **Gen Probes > Subdiv:** See :ref:`doc_using_lightmap_gi_dynamic_objects`.
398409
- **Data > Light Data:** See :ref:`doc_using_lightmap_gi_data`.
399410

411+
.. _doc_using_lightmap_gi_shadowmask:
412+
413+
Using shadowmasking for distant directional shadows
414+
---------------------------------------------------
415+
416+
When using a DirectionalLight3D, the maximum distance at which it can draw
417+
real-time shadows is limited by its **Shadow Max Distance** property. This can
418+
be an issue in large scenes, as distant objects won't appear to have any shadows
419+
from the DirectionalLight3D. While this can be resolved by using the **Static**
420+
global illumination mode on the DirectionalLight3D, this has several downsides:
421+
422+
- Since both direct and indirect light are baked, there is no way for dynamic
423+
objects to cast shadows onto static surfaces in a realistic manner. Godot skips
424+
shadow sampling entirely in this case to avoid "double lighting" artifacts.
425+
- Static shadows up close lack in detail, as they only rely on the lightmap texture
426+
and not on real-time shadow cascades.
427+
428+
We can avoid these downsides while still benefiting from distant shadows by
429+
using *shadowmasking*. While dynamic objects won't receive shadows from the
430+
shadowmask, it still greatly improves visuals since most scenes are primarily
431+
comprised of static objects.
432+
433+
Since the lightmap texture alone doesn't contain shadow information, we can bake
434+
this shadow information to a separate texture called a *shadowmask*.
435+
436+
Shadowmasking only affects the first DirectionalLight3D in the scene (determined
437+
by tree order) that has the **Dynamic** global illumination mode. It is not
438+
possible to use shadowmasking with the **Static** global illumination mode, as
439+
this mode skips shadow sampling on static objects entirely. This is because the
440+
Static global illumination mode bakes both direct and indirect light.
441+
442+
Three shadowmasking modes are available:
443+
444+
- **None (default):** Don't bake a shadowmask texture. Directional shadows will
445+
not be visible outside the range specified by the DirectionalLight3D's
446+
**Shadow Max Distance** property.
447+
- **Replace:** Bakes a shadowmask texture, and uses it to draw directional
448+
shadows when outside the range specified by the DirectionalLight3D's **Shadow
449+
Max Distance** property. Shadows within this range remain fully real-time.
450+
This option generally makes the most sense for most scenes, as it can deal
451+
well with static objects that exhibit subtle motion (e.g. foliage shadows).
452+
- **Overlay:** Bakes a shadowmask texture, and uses it to draw directional
453+
shadows regardless of the distance from the camera. Shadows within the range
454+
of the DirectionalLight3D's **Shadow Max Distance** property will be overlaid
455+
with real-time shadows. This can make the transition between real-time and
456+
baked shadows less jarring, at the cost of a "smearing" effect present on
457+
static object shadows depending on lightmap texel density. Also, this mode
458+
can't deal as well with static objects that exhibit subtle motion (such as
459+
foliage), as the baked shadows can't be animated over time. Still, for scenes
460+
where the camera moves quickly, this may be a better choice than **Replace**.
461+
462+
Here's a visual comparison of the shadowmask modes with a scene where the
463+
**Shadow Max Distance** was set very low for comparison purposes. The blue boxes
464+
are dynamic objects, while the rest of the scene is a static object. There is
465+
only a single DirectionalLight3D in the scene with the Dynamic global
466+
illumination mode:
467+
468+
.. figure:: img/lightmap_gi_shadowmask.webp
469+
:align: center
470+
:alt: Comparison between shadowmask modes
471+
472+
Comparison between shadowmask modes
473+
474+
.. note::
475+
476+
It is possible to switch between the **Replace** and **Overlay** shadowmask
477+
modes without having to bake lightmaps again.
478+
400479
Balancing bake times with quality
401480
---------------------------------
402481

0 commit comments

Comments
 (0)