Module light

Source
Expand description

Lighting effects.

This module includes support for various types of lights such as directional, point, and spot lights.

Additionally, the module provides shadow mapping to create realistic shadows.

Also provided is an implementation of light tiling, a technique that optimizes the rendering of thousands of analytical lights. If you find your scene performing poorly under the load of very many lights, LightTiling can speed things up.

§Analytical lights

Analytical lights are a fundamental lighting effect in a scene. These lights can be created directly from the Stage using the methods

Each of these methods returns an AnalyticalLight instance that can be manipulated to simulate different lighting conditions.

Once created, these lights can be positioned and oriented using Transform or NestedTransform objects. The Transform allows you to set the position, rotation, and scale of the light, while NestedTransform enables hierarchical transformations, which is useful for complex scenes where lights need to follow specific objects or structures.

By adjusting the properties of these lights, such as intensity, color, and direction, you can achieve a wide range of lighting effects, from simulating sunlight with directional lights to creating focused spotlights or ambient point lights. These lights can also be combined with shadow mapping techniques to enhance the realism of shadows in the scene.

§Shadow mapping

Shadow mapping is a technique used to add realistic shadows to a scene by simulating the way light interacts with objects.

To create a ShadowMap, use the Stage::new_shadow_map method, passing in the light source and desired parameters such as the size of the shadow map and the near and far planes of the light’s frustum. Once created, the shadow map needs to be updated each frame (or as needed) using the ShadowMap::update method, which renders the scene from the light’s perspective to determine which areas are in shadow.

This technique allows for dynamic shadows that change with the movement of lights and objects, enhancing the realism of the scene. Proper configuration of shadow map parameters, such as bias and resolution, is crucial to achieving high-quality shadows without artifacts, and varies with each scene.

§Light tiling

Light tiling is a technique used to optimize the rendering of scenes with a large number of lights.

It divides the rendering surface into a grid of tiles, allowing for efficient computation of lighting effects by processing each tile independently and cutting down on the overall lighting calculations.

To create a LightTiling, use the Stage::new_light_tiling method, providing a LightTilingConfig to specify parameters such as tile size and maximum lights per tile.

Once created, the LightTiling instance should be kept in sync with the scene by calling the LightTiling::run method each frame, or however you see fit. This method updates the lighting calculations for each tile based on the current scene configuration, ensuring optimal performance even with many lights.

By using light tiling, you can significantly improve the performance of your rendering pipeline, especially in complex scenes with numerous light sources.

Re-exports§

pub use super::shader::Candela;
pub use super::shader::Lux;

Modules§

shader
Shader functions for the lighting system.

Structs§

AnalyticalLight
A bundle of lighting resources representing one analytical light in a scene.
DirectionalLight
A directional light.
LightTiling
Shaders and resources for conducting light tiling.
LightTilingConfig
Parameters for tuning light tiling.
Lighting
Manages lighting for an entire scene.
LightingBindGroupLayoutEntries
PointLight
A point light.
ShadowMap
Projects shadows from a single light source for specific objects.
SpotLight
A spot light.

Enums§

Light
LightingError

Traits§

IsLight
Describes shared behaviour between all analytical lights.