bevy/crates/bevy_pbr/src
Marco Buono 1bd3d85769 Take DirectionalLight's GlobalTransform into account when calculating shadow map volume (not just direction) (#6384)
# Objective

This PR fixes #5789, by enabling movable (and scalable) directional light shadow volumes.

## Solution

This PR changes `ExtractedDirectionalLight` to hold a copy of the `DirectionalLight` entity's `GlobalTransform`, instead of just a `direction` vector. This allows the shadow map volume (as defined by the light's `shadow_projection` field) to be transformed honoring translation _and_ scale transforms, and not just rotation.

It also augments the texel size calculation (used to determine the `shadow_normal_bias`) so that it now takes into account the upper bound of the x/y/z scale of the `GlobalTransform`.

This change makes the directional light extraction code more consistent with point and spot lights (that already use `transform`), and allows easily moving and scaling the shadow volume along with a player entity based on camera distance/angle, immediately enabling more real world use cases until we have a more sophisticated adaptive implementation, such as the one described in #3629.

**Note:** While it was previously possible to update the projection achieving a similar effect, depending on the light direction and distance to the origin, the fact that the shadow map camera was always positioned at the origin with a hardcoded `Vec3::Y` up value meant you would get sub-optimal or inconsistent/incorrect results.

---

## Changelog

### Changed

- `DirectionalLight` shadow volumes now honor translation and scale transforms

## Migration Guide

- If your directional lights were positioned at the origin and not scaled (the default, most common scenario) no changes are needed on your part; it just works as before;
- If you previously had a system for dynamically updating directional light shadow projections, you might now be able to simplify your code by updating the directional light entity's transform instead;
- In the unlikely scenario that a scene with directional lights that previously rendered shadows correctly has missing shadows, make sure your directional lights are positioned at (0, 0, 0) and are not scaled to a size that's too large or too small.
2022-11-04 20:12:26 +00:00
..
render Take DirectionalLight's GlobalTransform into account when calculating shadow map volume (not just direction) (#6384) 2022-11-04 20:12:26 +00:00
alpha.rs add ReflectAsset and ReflectHandle (#5923) 2022-10-28 20:42:33 +00:00
bundle.rs Visibilty Inheritance, universal ComputedVisibility and RenderLayers support (#5310) 2022-07-15 23:24:42 +00:00
lib.rs Bloom (#6397) 2022-11-04 01:34:12 +00:00
light.rs Take DirectionalLight's GlobalTransform into account when calculating shadow map volume (not just direction) (#6384) 2022-11-04 20:12:26 +00:00
material.rs separate tonemapping and upscaling passes (#3425) 2022-10-26 20:13:59 +00:00
pbr_material.rs add ReflectAsset and ReflectHandle (#5923) 2022-10-28 20:42:33 +00:00
wireframe.rs separate tonemapping and upscaling passes (#3425) 2022-10-26 20:13:59 +00:00