Header menu logo Mibo

SceneUpload Module

Effect-agnostic scene-data upload: resolves uniform names on any Effect.

What is uploaded (when the uniform is present on the target effect; absent uniforms are skipped — MonoGame returns null from Parameters["name"]): matrices (matModel/viewProj/normalMatrix/cameraPos), material (albedoColor, texture0..4, roughness/metallic/emissionColor/ opacity/tiling/useNormalMap), lights (ambient + 1 directional + N point + M spot, including per-light shadow indices), shadows (the atlas + shadowViewProjs/ shadowUVOffsets/shadowTexelSize/dirLightCastsShadows, when the frame has a ShadowResult), and bones (boneMatrices[128], only when supplied).

Shadows are opt-in by declaration. A user effect that wants shadow sampling declares the shadow uniforms (shadowViewProjs, shadowUVOffsets, shadowTexelSize, shadowBiases, dirLightCastsShadows, pointLightShadowIdx, spotLightShadowIdx) and a shadowAtlas sampler (declared as sampler2D shadowAtlas : register(s5)); when the frame's shadow pass produced an atlas, those uniforms are uploaded by name and the atlas is bound to the sampler at slot 5 (PointClamp). An effect that declares none of them renders unshadowed — no cost, no sampling. When the frame has no shadow-casting light, dirLightCastsShadows is set to 0 and nothing else shadow-related is uploaded.

Functions and values

Function or value Description

uploadToEffect (gd, effect, view, projection, cameraPos, world, normalMatrix, lights, shadows, bones, material, time)

Full Usage: uploadToEffect (gd, effect, view, projection, cameraPos, world, normalMatrix, lights, shadows, bones, material, time)

Parameters:
    gd : GraphicsDevice
    effect : Effect - The target effect (user-owned; its CurrentTechnique is selected by the caller).
    view : Matrix - Active camera view matrix.
    projection : Matrix - Active camera projection matrix.
    cameraPos : Vector3 - Active camera world position.
    world : Matrix - The draw's world/model matrix.
    normalMatrix : Matrix - transpose(inverse(world)).
    lights : LightBuffers - The frame's accumulated lights.
    shadows : ShadowResult voption
    bones : Matrix[] voption - Bone palette (ValueSome for skinned draws; ValueNone otherwise).
    material : Material3D - The draw's material.
    time : float32 - Total elapsed game time, in seconds — the time uniform for animated shaders.

Uploads the full scene-data contract to effect by resolving each uniform by name. Absent uniforms are skipped (MonoGame returns null). Uploads: matrices (matModel/viewProj/normalMatrix/cameraPos), the time animation clock, material (albedoColor, maps texture0..4, roughness/metallic/emissionColor/opacity/tiling/useNormalMap), lights (ambient + 1 directional + N point + M spot), shadows (when a ShadowResult is present), and bones (boneMatrices[128], only when bones is ValueSome).

gd : GraphicsDevice
effect : Effect

The target effect (user-owned; its CurrentTechnique is selected by the caller).

view : Matrix

Active camera view matrix.

projection : Matrix

Active camera projection matrix.

cameraPos : Vector3

Active camera world position.

world : Matrix

The draw's world/model matrix.

normalMatrix : Matrix

transpose(inverse(world)).

lights : LightBuffers

The frame's accumulated lights.

shadows : ShadowResult voption
bones : Matrix[] voption

Bone palette (ValueSome for skinned draws; ValueNone otherwise).

material : Material3D

The draw's material.

time : float32

Total elapsed game time, in seconds — the time uniform for animated shaders.

Type something to start searching.