# graphics3d/shadowmap (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/graphics3d/shadowmap/

Shadow map. (original graphics3d/shadowmap.js)
- Real-time directional light shadows, a depth texture (hardware compare sampling, sampler2DShadow) and an orthographic light matrix.
- begin_render() starts the depth pass, and the main pass samples the resulting texture.
- The light matrix snaps to texel units to reduce shadow edge shimmer while moving. When the light points almost straight up or down, the up axis is taken as z so the matrix does not break.
- Construction restores the previous texture and framebuffer bindings. (so building it after models does not leave the depth texture on a texture unit and make drawing INVALID_OPERATION)
- ShadowAtlas: stores point light and spot light shadows as tiles in one depth texture. (original ShadowAtlas, the form of Unity URP's additional light shadow atlas)
  Tile size follows the URP default. Each tile asks for tile_resolution, and if they do not all fit in the atlas, the tile side is halved until they fit. (512 for one point light, 1024 for one spot light)
  The toon shader pushes the receiving position toward the normal by (1 + 3 x (1 - dot(N, L))) tile texels at that distance before comparing. (larger for surfaces at a grazing angle to the light, prevents shadow acne)
- Texel snapping rounds 0.5 up, like the original Math.round. (Rust round goes away from zero, so it differs for negative numbers)
- The original default resolution argument 2048 is DEFAULT_SHADOWMAP_RESOLUTION. (Rust has no default arguments)
- The sun shadow bias is the shadow-texel value of set_bias(depth, normal). (default 1, 1, the same unit as Depth Bias and Normal Bias of Unity URP, the receiving ToonRenderer applies it multiplied by the texel size and slope)
- The shadow update mode (the original ShadowUpdateMode) lives in the shadow depth cache that ShadowMap and ShadowAtlas each hold (the original createShadowCache). ToonDrawQueue compares, and begin_render binds by that decision.
  begin_render changes the cache through &self, so the cache sits in a RefCell. (The original changes the values in the object directly)

## ShadowMap (struct)

Shadow map.
- The depth texture is a square DEPTH_COMPONENT24 in comparison mode (LEQUAL), so shaders read it with sampler2DShadow.

Example: Draw one frame's shadow depth pass and pass the shadow map to the main pass renderer

```rust
use vanilla::graphics3d::shadowmap::DEFAULT_SHADOWMAP_RESOLUTION;
use vanilla::{Matrix4, ShadowMap, SkinnedModel, SkinnedModelRenderer, Vector3};

fn create_shadow_map(gl: &vanilla::GlContext) -> Result<ShadowMap, String> {
	ShadowMap::new(gl, DEFAULT_SHADOWMAP_RESOLUTION)
}

fn render_shadow_pass(gl: &vanilla::GlContext, shadow_map: &mut ShadowMap, skinned_model_renderer: &mut SkinnedModelRenderer, skinned_model: &mut SkinnedModel) {
	let light_direction = Vector3::create(-0.5, -0.8, -0.35);
	shadow_map.update_light_matrix(Vector3::zero(), light_direction, 4.0, 0.5, 30.0);
	let light_view_projection_elements = *shadow_map.get_light_view_projection_matrix().get_elements();
	let model_matrix = Matrix4::create_identity();
	shadow_map.begin_render(gl);
	skinned_model_renderer.draw_depth(gl, skinned_model, &light_view_projection_elements, model_matrix.get_elements());
	let texel_size = 1.0 / shadow_map.get_resolution() as f64;
	skinned_model_renderer.set_shadow_map(Some(shadow_map.get_depth_texture()), Some(&light_view_projection_elements), texel_size);
}
```

- `pub fn new(gl: &crate::GlContext, resolution: i32) -> Result<ShadowMap, String>` (constructor, since 0.3.2): Constructor. (depth texture + framebuffer without color, restores the previous texture and framebuffer bindings)
  - The light matrix starts as the identity matrix. (filled by update_light_matrix)
  - `gl` &crate::GlContext: GL context. (taken out with Graphic::get_gl)
  - `resolution` i32: Number of texels per side of the depth texture. (square, the original default is DEFAULT_SHADOWMAP_RESOLUTION = 2048)
  - returns Result<ShadowMap, String>: New shadow map. Err(GL error message) if the texture or framebuffer cannot be created.
- `pub fn update_light_matrix(&mut self, focus_position: Vector3, light_direction: Vector3, extent: f64, near_distance: f64, far_distance: f64)` (method, since 0.3.2): Updates the light matrix. (orthographic projection covering the area around the focus, texel snapping, the up direction becomes the z axis when the light travels almost straight up or down)
  - light_direction is the direction the light travels, extent is the half coverage range around the focus.
  - The light eye is placed (near_distance + far_distance) / 2 away from the focus on the side opposite the light, and up is Vector3::up().
    If the absolute value of the y component of the light direction exceeds 0.99 (almost straight up or down), up is switched to the z axis (0, 0, 1).
  - `focus_position` Vector3: Center of the shadow coverage. (world)
  - `light_direction` Vector3: Direction the light travels. (world, any length, normalized internally)
  - `extent` f64: Half range covered horizontally and vertically from the focus. (world units, the orthographic box is -extent ~ extent)
  - `near_distance` f64: Near distance of the light's orthographic projection. (world units)
  - `far_distance` f64: Far distance of the light's orthographic projection. (world units)

  Example: Cover a radius of 4 around the origin when the sun shines at an angle

  ```rust
  use vanilla::{ShadowMap, Vector3};
  
  fn aim_sun(shadow_map: &mut ShadowMap) {
  	let sun_direction = Vector3::create(0.5, 0.8, 0.35).normalize();
  	let light_travel_direction = sun_direction.multiply_scalar(-1.0);
  	shadow_map.update_light_matrix(Vector3::zero(), light_travel_direction, 4.0, 0.5, 30.0);
  }
  ```

- `pub fn begin_render(&self, gl: &crate::GlContext)` (method, since 0.3.2): Starts the depth pass. (framebuffer bind + viewport + depth clear; when ToonDrawQueue uses the cache, it draws into the baked target or copies the baked target and draws over it)
  - Turns off the scissor test and turns on the depth test and depth writing. When done, the caller sets the next pass's framebuffer and viewport again.
  - `gl` &crate::GlContext: GL context.
- `pub fn set_update_mode(&mut self, update_mode: ShadowUpdateMode, update_interval: u32)` (method, since 0.4.0): Sets how the shadow is redrawn. (the original setUpdateMode, ToonDrawQueue follows it, default ShadowUpdateMode::OnChange, setting it redraws everything on the next draw)
  - Rust has no default arguments, so the original's default updateInterval argument 1 is always passed. (Unused unless Interval)
  - `update_mode` ShadowUpdateMode: ShadowUpdateMode.
  - `update_interval` u32: How many frames apart to draw for Interval. (1 if smaller than 1)

  Example: Drawing the shadow every third frame

  ```rust
  use vanilla::{GlContext, ShadowMap, ShadowUpdateMode};
  
  fn draw_shadow_every_third_frame(gl: &GlContext) {
  	let mut shadow_target = ShadowMap::new(gl, 1024).unwrap();
  	shadow_target.set_update_mode(ShadowUpdateMode::Interval, 3);
  	println!("{:?} {}", shadow_target.get_update_mode(), shadow_target.get_update_interval());
  	shadow_target.set_update_mode(ShadowUpdateMode::EveryFrame, 1);
  	shadow_target.destroy(gl);
  }
  ```

- `pub fn get_update_mode(&self) -> ShadowUpdateMode` (method, since 0.4.0): Returns how the shadow is redrawn. (the original getUpdateMode)
  - returns ShadowUpdateMode: ShadowUpdateMode. (default OnChange)
- `pub fn get_update_interval(&self) -> u32` (method, since 0.4.0): Returns the frame count for Interval. (the original getUpdateInterval)
  - returns u32: How many frames apart it draws. (1 or more, default 1)
- `pub fn request_update(&mut self)` (method, since 0.4.0): Makes the next draw redraw everything. (the original requestUpdate, for changes the caster records cannot see, for example when a mesh's vertices were edited)
- `pub fn get_framebuffer(&self) -> GlFramebuffer` (method, since 0.3.2): Returns the framebuffer.
  - returns GlFramebuffer: Depth-only framebuffer. (no color attachment)
- `pub fn get_depth_texture(&self) -> GlTexture` (method, since 0.3.2): Returns the depth texture.
  - returns GlTexture: Depth texture for comparison sampling (sampler2DShadow). (DEPTH_COMPONENT24)
- `pub fn get_resolution(&self) -> i32` (method, since 0.3.2): Returns the resolution.
  - returns i32: Number of texels per side of the depth texture.
- `pub fn get_light_view_projection_matrix(&self) -> &Matrix4` (method, since 0.3.2): Returns the light view-projection matrix.
  - returns &Matrix4: Light view-projection matrix. (world → light clip, identity before update_light_matrix)
- `pub fn set_bias(&mut self, depth_bias: f64, normal_bias: f64)` (method, since 0.4.0): Sets the shadow bias. (in shadow texels, default depth 1, normal 1, applied by the receiver when it reads the shadow)
  - It is multiplied by the world size of one texel (light matrix width / resolution), so the same amount applies when the extent or resolution changes. (the same units as Depth Bias and Normal Bias in Unity URP)
  - Depth bias pulls the compared depth toward the light. Normal bias pushes the receiving point along the surface normal before reading. Both are multiplied by the 1.5 texel radius of the 3x3 PCF.
  - ToonRenderer adds a slope-scaled bias on top (grows as the light grazes the surface, 2.5 texels x slope, slope clamped at 10).
  - Lower values keep shadows attached but invite self-shadow acne. Higher values remove acne but make shadows look detached (peter panning).
  - `depth_bias` f64: Depth bias. (in shadow texels, 0 or more)
  - `normal_bias` f64: Normal bias. (in shadow texels, 0 or more)

  Example: Setting the shadow bias in texels

  ```rust
  use vanilla::{GlContext, ShadowMap, Vector3};
  
  fn soften_shadow(gl: &GlContext) {
  	let mut shadow_map = ShadowMap::new(gl, 1024).unwrap();
  	shadow_map.update_light_matrix(Vector3::create(0.0, 0.0, 0.0), Vector3::create(-0.3, -1.0, -0.2), 20.0, 1.0, 100.0);
  	shadow_map.set_bias(0.5, 1.5);
  	println!("{} {}", shadow_map.get_depth_bias(), shadow_map.get_normal_bias());
  	shadow_map.destroy(gl);
  }
  ```

- `pub fn get_depth_bias(&self) -> f64` (method, since 0.4.0): Returns the depth bias.
  - returns f64: Depth bias. (in shadow texels, default 1)
- `pub fn get_normal_bias(&self) -> f64` (method, since 0.4.0): Returns the normal bias.
  - returns f64: Normal bias. (in shadow texels, default 1)
- `pub fn set_focus_step(&mut self, world_step: f64)` (method, since 0.4.0): Set the world step the focus moves in. (for the sun shadow cache, the default 0 does not snap and only snaps to texels)
  - When the focus follows a camera, passing a single texel changes the light matrix, so the ShadowUpdateMode::OnChange cache redraws every frame.
  - With a step, the focus is moved to multiples of the world step on each of x, y and z, so the matrix stays the same inside one cell and the baked map is reused. The covered width and depth get the step as margin so the area around the focus never leaves the map.
  - The same idea as the fixed-cell focus snapping of the cached shadows and virtual shadow maps in Unity and Unreal. (guessed, the sources were not read)
  - Texel snapping still applies on top. With the margin, one texel covers a slightly larger world size.
  - `world_step` f64: World step. (in world units, 0 or less turns it off)

  Example: Moving the focus in one meter steps

  ```rust
  use vanilla::{GlContext, ShadowMap, Vector3};
  
  fn snap_focus(gl: &GlContext) {
  	let mut shadow_map = ShadowMap::new(gl, 1024).unwrap();
  	shadow_map.set_focus_step(1.0);
  	shadow_map.update_light_matrix(Vector3::create(0.2, 0.0, 0.0), Vector3::create(-0.4, -1.0, -0.3), 20.0, 0.5, 100.0);
  	println!("{}", shadow_map.get_focus_step());
  	shadow_map.destroy(gl);
  }
  ```

- `pub fn get_focus_step(&self) -> f64` (method, since 0.4.0): Return the world step the focus moves in.
  - returns f64: World step. (0 means off)
- `pub fn destroy(&self, gl: &crate::GlContext)` (method, since 0.3.2): Destroy. (Releases GL resources, deletes the framebuffer, the depth texture and the baked target)
  - `gl` &crate::GlContext: GL context used at creation.

## ShadowAtlasLight (struct) (Clone, Copy, Debug, PartialEq)

One light of the shadow atlas. (Values to upload to the shader)

Example: Read the lights the atlas picked and their first tiles

```rust
use vanilla::ShadowAtlas;

fn print_shadow_lights(shadow_atlas: &ShadowAtlas) {
	for light in shadow_atlas.get_lights() {
		let tile_count = if light.tangent > 0.0 {
			1
		}
		else {
			6
		};
		println!("light {} uses tiles {}..{}", light.light_index, light.first_tile, light.first_tile + tile_count);
	}
}
```

- `pub light_index: usize` (field, since 0.4.0): Order in the light list. (ToonRenderer attaches this shadow to that point light)
  - returns usize
- `pub position: [f64; 3]` (field, since 0.4.0): Light position.
  - returns [f64; 3]
- `pub forward: [f64; 3]` (field, since 0.4.0): Forward direction. (Spotlights only)
  - returns [f64; 3]
- `pub up: [f64; 3]` (field, since 0.4.0): Up direction. (Spotlights only)
  - returns [f64; 3]
- `pub tangent: f64` (field, since 0.4.0): Tangent of the half angle. (0 for a point light)
  - returns f64
- `pub near: f64` (field, since 0.4.0): Near distance.
  - returns f64
- `pub far: f64` (field, since 0.4.0): Far distance.
  - returns f64
- `pub first_tile: usize` (field, since 0.4.0): First tile number.
  - returns usize

## ShadowAtlasTile (struct) (Clone, Copy, Debug)

One tile of the shadow atlas.

Example: Read the viewport position of each tile

```rust
use vanilla::ShadowAtlas;

fn print_tiles(shadow_atlas: &ShadowAtlas) {
	for tile_index in 0..shadow_atlas.get_tile_count() {
		let tile = shadow_atlas.get_tile(tile_index);
		println!("tile {} at ({}, {}) size {}", tile_index, tile.x, tile.y, tile.size);
	}
}
```

- `pub view_projection_matrix: Matrix4` (field, since 0.4.0): View and projection of the tile.
  - returns Matrix4
- `pub x: i32` (field, since 0.4.0): Bottom-left x of the tile. (Pixels)
  - returns i32
- `pub y: i32` (field, since 0.4.0): Bottom-left y of the tile. (Pixels)
  - returns i32
- `pub size: i32` (field, since 0.4.0): Side of a tile. (Pixels)
  - returns i32

## ShadowAtlasLightSource (struct) (Clone, Copy, Debug, PartialEq)

Light description the shadow atlas takes. (One object of the original updateLights, built from ToonPointLight)

Example: One point light and one spotlight

```rust
use vanilla::ShadowAtlasLightSource;

let point_light = ShadowAtlasLightSource {
	position: [0.0, 2.0, 0.0],
	direction: None,
	outer_cone_angle: 0.0,
	range: 10.0,
	shadow_near: 0.05,
	casts_shadow: true,
};
let spot_light = ShadowAtlasLightSource {
	position: [3.0, 4.0, 0.0],
	direction: Some([0.0, -1.0, 0.0]),
	outer_cone_angle: std::f64::consts::FRAC_PI_4,
	..point_light
};
assert!(point_light.direction.is_none());
assert!(spot_light.direction.is_some());
```

- `pub position: [f64; 3]` (field, since 0.4.0): Light position.
  - returns [f64; 3]
- `pub direction: Option<[f64; 3]>` (field, since 0.4.0): Direction the light travels. (spotlight if Some)
  - returns Option<[f64; 3]>
- `pub outer_cone_angle: f64` (field, since 0.4.0): Outer cone half angle of the spotlight. (Radians)
  - returns f64
- `pub range: f64` (field, since 0.4.0): Far distance. (30 if 0)
  - returns f64
- `pub shadow_near: f64` (field, since 0.4.0): Near distance.
  - returns f64
- `pub casts_shadow: bool` (field, since 0.4.0): Whether it casts a shadow.
  - returns bool

## ShadowAtlas (struct)

Shadow atlas. (Stores real-time shadows of point lights and spotlights as tiles in one depth texture, the original ShadowAtlas)
- A spotlight is drawn into one perspective shadow map tile, a point light draws the six cube faces into six tiles (90 degree perspective per face).
- update_lights(light list) picks lights with casts_shadow true up to SHADOW_ATLAS_MAXIMUM_LIGHTS, divides the tiles and computes view and projection per tile.
- Tiles form a grid of grid_size per side. (grid_size = ceil(square root of the tile count), tile side = floor(resolution / grid_size))
- Drawing: begin_render clears the target, then per tile begin_tile sets the viewport and depth is drawn with that tile's view and projection. (ToonRenderer::begin_shadow_atlas_pass, set_shadow_atlas_tile)

Example: Divide tiles from the light list and draw depth per tile

```rust
use vanilla::{ShadowAtlas, ShadowAtlasLightSource};

fn render_shadows(gl: &vanilla::GlContext, shadow_atlas: &mut ShadowAtlas, light_source_list: &[ShadowAtlasLightSource]) {
	shadow_atlas.update_lights(light_source_list);
	shadow_atlas.begin_render(gl);
	for tile_index in 0..shadow_atlas.get_tile_count() {
		shadow_atlas.begin_tile(gl, tile_index);
		let _view_projection_matrix = shadow_atlas.get_tile(tile_index).view_projection_matrix;
	}
}
```

- `pub fn new(gl: &crate::GlContext, resolution: i32, tile_resolution: i32) -> Result<ShadowAtlas, String>` (constructor, since 0.4.0): Constructor. (Depth texture and framebuffer without color, restores the previous bindings)
  - Starts with no tiles. (Grid side 1, tile side equal to the resolution, divided by update_lights)
  - resolution is the side of the atlas, and tile_resolution is the side each tile asks for. (the original defaults are DEFAULT_SHADOW_ATLAS_RESOLUTION, DEFAULT_SHADOW_ATLAS_TILE_RESOLUTION)
  - `gl` &crate::GlContext: GL context.
  - `resolution` i32: Number of texels per side of the depth texture. (Square)
  - `tile_resolution` i32: Side each tile asks for. (Pixels, clamped to 1 ~ resolution, halved until the tiles fit)
  - returns Result<ShadowAtlas, String>: New shadow atlas. Err(GL error message) if the texture or framebuffer cannot be created.
- `pub fn update_lights(&mut self, light_source_list: &[ShadowAtlasLightSource])` (method, since 0.4.0): Divides tiles from the light list. (Ones with casts_shadow true up to SHADOW_ATLAS_MAXIMUM_LIGHTS, one tile per spotlight, six per point light)
  - The near distance does not go below 0.001, and the far distance does not go below the near distance + 0.01. (30 if range is 0 or less)
  - The perspective half angle of a spotlight is the outer cone half angle (at least 0.01) plus 0.05 radians, clamped at 1.45 radians.
  - `light_source_list` &[ShadowAtlasLightSource]: Light list. (The order becomes ShadowAtlasLight::light_index, built with ToonLightSet::read_shadow_light_sources)
- `pub fn begin_render(&self, gl: &crate::GlContext)` (method, since 0.4.0): Begins the depth pass. (Binds the framebuffer and clears the whole target, begin_tile per tile; when ToonDrawQueue uses the cache, it draws into the baked target or copies the baked target and draws over it)
  - Sets the viewport to the whole target, turns off the scissor test, and turns on the depth test and depth writes.
  - `gl` &crate::GlContext: GL context.
- `pub fn set_update_mode(&mut self, update_mode: ShadowUpdateMode, update_interval: u32)` (method, since 0.4.0): Sets how the shadow is redrawn. (the original setUpdateMode, ToonDrawQueue follows it, default ShadowUpdateMode::OnChange, setting it redraws everything on the next draw)
  - Rust has no default arguments, so the original's default updateInterval argument 1 is always passed. (Unused unless Interval)
  - `update_mode` ShadowUpdateMode: ShadowUpdateMode.
  - `update_interval` u32: How many frames apart to draw for Interval. (1 if smaller than 1)

  Example: Drawing the shadow every third frame

  ```rust
  use vanilla::{GlContext, ShadowAtlas, ShadowUpdateMode, DEFAULT_SHADOW_ATLAS_TILE_RESOLUTION};
  
  fn draw_shadow_every_third_frame(gl: &GlContext) {
  	let mut shadow_target = ShadowAtlas::new(gl, 1024, DEFAULT_SHADOW_ATLAS_TILE_RESOLUTION).unwrap();
  	shadow_target.set_update_mode(ShadowUpdateMode::Interval, 3);
  	println!("{:?} {}", shadow_target.get_update_mode(), shadow_target.get_update_interval());
  	shadow_target.set_update_mode(ShadowUpdateMode::EveryFrame, 1);
  	shadow_target.destroy(gl);
  }
  ```

- `pub fn get_update_mode(&self) -> ShadowUpdateMode` (method, since 0.4.0): Returns how the shadow is redrawn. (the original getUpdateMode)
  - returns ShadowUpdateMode: ShadowUpdateMode. (default OnChange)
- `pub fn get_update_interval(&self) -> u32` (method, since 0.4.0): Returns the frame count for Interval. (the original getUpdateInterval)
  - returns u32: How many frames apart it draws. (1 or more, default 1)
- `pub fn request_update(&mut self)` (method, since 0.4.0): Makes the next draw redraw everything. (the original requestUpdate, for changes the caster records cannot see, for example when a mesh's vertices were edited)
- `pub fn begin_tile(&self, gl: &crate::GlContext, tile_index: usize)` (method, since 0.4.0): Set the viewport to one tile.
  - `gl` &crate::GlContext: GL context.
  - `tile_index` usize: Tile number. (0 ~ get_tile_count() - 1, panics if out of range)
- `pub fn get_lights(&self) -> &[ShadowAtlasLight]` (method, since 0.4.0): Returns the lights whose shadows are received.
  - returns &[ShadowAtlasLight]: List of lights picked by the last update_lights. (Up to SHADOW_ATLAS_MAXIMUM_LIGHTS)
- `pub fn get_light_count(&self) -> usize` (method, since 0.4.0): Returns the number of shadow-casting lights. (the original getLightCount, the length of get_lights)
  - returns usize: Number of lights the last update_lights picked. (0 ~ SHADOW_ATLAS_MAXIMUM_LIGHTS)

  Example

  ```rust
  use vanilla::ShadowAtlas;
  
  fn has_shadow_lights(shadow_atlas: &ShadowAtlas) -> bool {
  	shadow_atlas.get_light_count() > 0
  }
  ```

- `pub fn get_tile_resolution(&self) -> i32` (method, since 0.4.0): Returns the side each tile asks for. (pixels, the value given at creation)
  - returns i32: Side each tile asks for. (Pixels)
- `pub fn get_tile_count(&self) -> usize` (method, since 0.4.0): Return the tile count.
  - returns usize: Tile count. (1 per spotlight plus 6 per point light)
- `pub fn get_tile(&self, tile_index: usize) -> &ShadowAtlasTile` (method, since 0.4.0): Return a tile.
  - `tile_index` usize: Tile number. (0 ~ get_tile_count() - 1, panics if out of range)
  - returns &ShadowAtlasTile: The tile's view and projection, position and size.
- `pub fn get_grid_size(&self) -> i32` (method, since 0.4.0): Return the number of tiles per side of the grid.
  - returns i32: Number of tiles per side of the grid.
- `pub fn get_tile_size(&self) -> i32` (method, since 0.4.0): Return the side of a tile. (Pixels)
  - returns i32: Side of a tile. (Pixels)
- `pub fn get_resolution(&self) -> i32` (method, since 0.4.0): Returns the resolution.
  - returns i32: Number of texels per side of the depth texture.
- `pub fn get_depth_texture(&self) -> GlTexture` (method, since 0.4.0): Return the depth texture. (Comparison sampling with sampler2DShadow)
  - returns GlTexture: GL handle of the atlas depth texture.
- `pub fn get_framebuffer(&self) -> GlFramebuffer` (method, since 0.4.0): Returns the framebuffer.
  - returns GlFramebuffer: GL handle of the depth-only framebuffer.
- `pub fn destroy(&self, gl: &crate::GlContext)` (method, since 0.4.0): Destroy. (Releases GL resources, deletes the framebuffer, the depth texture and the baked target)
  - `gl` &crate::GlContext: GL context this atlas was built in.

## Functions and constants

- `pub const DEFAULT_SHADOWMAP_RESOLUTION: i32 = 2048` (field, since 0.3.2): Default resolution. (the original constructor's default argument)
  - returns i32
- `pub const DEFAULT_SHADOW_ATLAS_RESOLUTION: i32 = 2048` (field, since 0.4.0): Default side of the shadow atlas. (the original ShadowAtlas default argument, Unity URP's additional light shadow atlas default 2048)
  - returns i32
- `pub const DEFAULT_SHADOW_ATLAS_TILE_RESOLUTION: i32 = 1024` (field, since 0.4.0): Default side each shadow atlas tile asks for. (the original ShadowAtlas default argument, Unity URP's additional light shadow resolution tier High default 1024, the light's default tier is High)
  - returns i32
- `pub const SHADOW_ATLAS_MAXIMUM_LIGHTS: usize = 4` (field, since 0.4.0): Upper limit of point lights and spotlights the shadow atlas receives. (Size of the uniform arrays in the shader)
  - returns usize

## ShadowUpdateMode (enum) (Clone, Copy, Debug, Default, PartialEq, Eq, Hash)

How shadow depth is redrawn. (the original ShadowUpdateMode, followed by set_update_mode of ShadowMap and ShadowAtlas and by ToonDrawQueue::draw_shadows and draw_local_shadows)
- EveryFrame: redraws every caster every frame.
- OnChange: does not redraw when the lights and casters are unchanged. Casters that stay unchanged for a long time are baked separately, and only the moving ones are drawn over them every frame. (default, the screen is the same as drawing every frame)
- Interval: redraws everything once every N frames. (Frames in between reuse the previous shadow, so the shadow of moving things follows late)

Example: Sun shadow only on change, point light shadow every four frames

```rust
use vanilla::{GlContext, ShadowAtlas, ShadowMap, ShadowUpdateMode, DEFAULT_SHADOW_ATLAS_TILE_RESOLUTION};

fn choose_shadow_updates(gl: &GlContext) {
	let mut shadow_map = ShadowMap::new(gl, 1024).unwrap();
	shadow_map.set_update_mode(ShadowUpdateMode::OnChange, 1);
	let mut shadow_atlas = ShadowAtlas::new(gl, 1024, DEFAULT_SHADOW_ATLAS_TILE_RESOLUTION).unwrap();
	shadow_atlas.set_update_mode(ShadowUpdateMode::Interval, 4);
	println!("{:?} {:?} {}", shadow_map.get_update_mode(), shadow_atlas.get_update_mode(), shadow_atlas.get_update_interval());
	shadow_map.destroy(gl);
	shadow_atlas.destroy(gl);
}
```

- `EveryFrame`: Everything every frame.
- `OnChange`: Only on change. (default)
- `Interval`: Every N frames.
