Header menu logo Mibo

ShadowAtlas Type

Manages a texture atlas for multiple shadow maps. MonoGame port of the canonical raylib ShadowAtlas.

The atlas is a single square RenderTarget2D with SurfaceFormat.Single (R32F) — MonoGame cannot create a sampleable depth-only render target on either backend (depth buffers are non-sampleable), so the shadow depth is written into the color attachment via DepthShadow.fx (non-linear position.z to .r). The forward pass samples it with a comparison sampler (SamplerState.ComparisonFunction) for hardware PCF — no textureSize or manual 3×3 loop required (SM3.0-clean).

The render target is allocated lazily against the real GraphicsDevice on first ShadowAtlas.EnsureResources call (mirrors the B5/B8 lazy-effect pattern) — GraphicsDevice is not available at pipeline construction time.

Constructors

Constructor Description

ShadowAtlas(config, biasConfig)

Full Usage: ShadowAtlas(config, biasConfig)

Parameters:
Returns: ShadowAtlas
config : ShadowAtlasConfig
biasConfig : ShadowBiasConfig
Returns: ShadowAtlas

Instance members

Instance member Description

this.ActiveCasterCount

Full Usage: this.ActiveCasterCount

Returns: int

Get the number of active caster regions (computed by PrepareUniforms).

Returns: int

this.AddCaster

Full Usage: this.AddCaster

Parameters:
Returns: int<MeasureProduct<ShadowCasterId, MeasureOne>> voption

Register a new shadow caster and allocate atlas regions. Returns the caster ID, or ValueNone if the atlas is full.

casterType : ShadowCasterType
lightPosition : Vector3
lightDirection : Vector3
lightTarget : Vector3
enabled : bool
biasOverride : float32 voption
Returns: int<MeasureProduct<ShadowCasterId, MeasureOne>> voption

this.BiasConfig

Full Usage: this.BiasConfig

Returns: ShadowBiasConfig

The bias configuration.

Returns: ShadowBiasConfig

this.Biases

Full Usage: this.Biases

Returns: float32 array
Returns: float32 array

this.CasterTypes

Full Usage: this.CasterTypes

Returns: int array
Returns: int array

Get all active casters (for iteration).

Returns: ValueCollection<int<MeasureProduct<ShadowCasterId, MeasureOne>>, ShadowCasterData>

this.Clear

Full Usage: this.Clear

Clear all casters and reset slot allocator. Call at start of each frame.

this.Config

Full Usage: this.Config

Returns: ShadowAtlasConfig

The atlas configuration.

Returns: ShadowAtlasConfig

this.Count

Full Usage: this.Count

Returns: int

Number of currently allocated casters.

Returns: int

this.EnsureResources

Full Usage: this.EnsureResources

Parameters:

Lazily allocate the render target against the real GraphicsDevice. Called on first shadow pass (the device isn't available at construction).

gd : GraphicsDevice

this.Fbo

Full Usage: this.Fbo

Returns: RenderTarget2D

The shadow depth render target (R32F color attachment).

Returns: RenderTarget2D

this.GetBias

Full Usage: this.GetBias

Parameters:
Returns: float32

Get bias for a caster type, respecting per-caster override.

caster : ShadowCasterData
Returns: float32

this.GetRegionViewProj

Full Usage: this.GetRegionViewProj

Parameters:
    regionIndex : int

Returns: Matrix

Get the view-projection matrix for a specific atlas region. Returns Matrix.Identity when the region has no VP set. Use this to read back a caster's VP — ShadowCasterData.ViewProj is a struct field that is NOT kept in sync with the region store (it stays Identity after AddCaster); the authoritative copy lives in the region dictionary.

regionIndex : int
Returns: Matrix

this.GetRegionViewport

Full Usage: this.GetRegionViewport

Parameters:
    regionIndex : int

Returns: Viewport

Get a Viewport for a region index.

regionIndex : int
Returns: Viewport

this.GetUVOffsetScale

Full Usage: this.GetUVOffsetScale

Parameters:
    regionIndex : int

Returns: Vector4

Get UV offset/scale for a region index (xy=offset, zw=scale).

regionIndex : int
Returns: Vector4

this.GridSize

Full Usage: this.GridSize

Returns: int

Grid size (rows/columns) of the atlas.

Returns: int

this.LightPositions

Full Usage: this.LightPositions

Returns: Vector3 array
Returns: Vector3 array

this.PrepareUniforms

Full Usage: this.PrepareUniforms

Prepare uniform arrays for upload to the forward shader. Call each frame before uploading shadow uniforms.

this.RegionSize

Full Usage: this.RegionSize

Returns: int

Size of each region in pixels.

Returns: int

this.Release

Full Usage: this.Release

Releases the render target. Called from ForwardPipeline.Shutdown.

this.RemoveCaster

Full Usage: this.RemoveCaster

Parameters:

Remove a shadow caster and free its atlas regions.

id : int<MeasureProduct<ShadowCasterId, MeasureOne>>

this.SetRegionViewProj

Full Usage: this.SetRegionViewProj

Parameters:
    regionIndex : int
    vp : Matrix

Set the view-projection matrix for a specific atlas region.

regionIndex : int
vp : Matrix

this.UVOffsets

Full Usage: this.UVOffsets

Returns: Vector4 array
Returns: Vector4 array

this.ViewProjs

Full Usage: this.ViewProjs

Returns: Matrix array

Get prepared uniform arrays (call after PrepareUniforms).

Returns: Matrix array

Type something to start searching.