Ordered map composition
MapScene.render_passes composes existing RGBA render outputs using a Python
image compositor. It never substitutes for unavailable native scene rendering.
Use MapScene.render and the public vector renderer to produce source images;
the executable example renders color,
relief and a transparent vector overlay on physical hardware, then composes and
replays them through a bundle.
inputs = {
"color_image": f3d.RenderPassInput(color_rgba),
"relief_image": f3d.RenderPassInput(relief_rgba),
"vector_image": f3d.RenderPassInput(overlay_rgba),
}
passes = [
f3d.RenderPassSpec("color", "color", ("color_image",)),
f3d.RenderPassSpec("relief", "relief", ("color", "relief_image"),
"multiply", {"opacity": 0.5}),
f3d.RenderPassSpec("overlay", "overlay", ("relief", "vector_image"),
"alpha_over"),
]
report = scene.render_passes(passes, inputs, "composed.png")
scene.save_bundle("composition")
replay = f3d.MapScene.load_bundle("composition.forge3d")
replay.render_passes(path="replay.png")
Passes execute in list order. Each input reference names either an image snapshot
or a previously executed pass. Two references mean (backdrop, source); one is
allowed only for alpha_over over transparent black. The final pass is the output.
Every supplied input and earlier pass must contribute to the final pass;
disconnected branches and unused snapshots are rejected. An explicit empty
pass list is rejected; omit both arguments to replay or retain no-pass rendering.
Names must be nonempty and unique across inputs and passes. Missing, forward and
self references, dimensions differing from OutputSpec, unsupported operations
or parameters, NaN/infinite channels, and channels outside their domain raise
before composition. kind is color, relief or overlay: it records the role
and does not generate a style or alter pixels.
Inputs accept uint8 RGBA in [0,255] or floating RGBA in [0,1], and copy them
into immutable snapshots. Each input declares color_space="srgb" (default) or
"linear", and alpha_mode="straight" (default) or "premultiplied".
Premultiplication applies in the input’s declared color space and is undone
before color conversion. RGB at zero alpha is ignored. Opacity defaults to one
and scales source alpha only; it is the sole supported pass parameter.
Each pass blends in its declared color_space, defaulting to linear light.
Conversions use the standard sRGB transfer function. For straight RGB Cb, Cs
and backdrop/source alpha ab, as (including opacity):
multiply:B = Cb * Csscreen:B = Cb + Cs - Cb * Csalpha_over:B = Cs
All operations use source-over alpha ao = as + ab*(1-as) and premultiplied
color Co = as*(1-ab)*Cs + as*ab*B + (1-as)*ab*Cb. Output RGB is Co/ao, or zero
at zero alpha. Intermediate passes retain float precision. PNG output is
straight-alpha sRGB, rounded once by the existing PNG writer (8 or 16 bits).
HDR, AOV export, native certificates, provenance and render cache are unsupported
for this compositor and are rejected explicitly.
Pass order, references, parameters, color/alpha semantics and snapshot references
are stored in the recipe and frozen compiled manifest. Composition bundles use
version 4, which older readers reject rather than silently dropping the passes.
Only MapScene.load_bundle opts into that format, and it requires nonempty
passes. The generic and viewer bundle loaders keep their version-3 cap.
Each unique pixel snapshot is stored once in scene/render_pass_inputs/<sha256>.npy:
NumPy format 1.0, C order, little-endian float64. The descriptor records shape,
dtype, color/alpha semantics and SHA-256; loading verifies the file, descriptor
and checksum before use. Replay reads the compiled
specification directly and rejects a recipe/plan mismatch. Optional fields are
absent for scenes without passes, preserving their existing serialization and
native rendering; those bundles remain version 3. No new dependency is required.
Standalone to_dict() recipes retain inline RGBA data for self-contained JSON;
the render, compile and bundle paths use compact references to immutable snapshots.
forge3d.recipe_manifest(scene) also uses these references, lists the passes,
and reports the same recipe hash as the compiled plan. Scene, recipe and mapping
inputs produce the same summary; inline mappings are normalized without changing
the caller’s data.
MapScene(..., pass_specs=passes, pass_inputs=inputs) also configures composition;
call render_passes() to execute it. render() rejects configured image passes
and retains its native-frame contract. render_passes() on a scene without passes
delegates to ordinary render().
Its certificate and cache keywords are forwarded on that no-pass path;
composition rejects nondefault native controls before replacing any saved passes.
Linear-light composition
Set OutputSpec(width=..., height=..., compositing_mode="linear_light") for
MapScene.render() or MapScene.render_passes(). For MapPlate, set the same
option on MapPlateConfig. To opt in for raster drapes in the terrain viewer,
launch it with FORGE3D_VIEWER_COMPOSITING_MODE=linear_light. The viewer reads
the setting when it creates the overlay stack and records the mode in its
texture-build log. "legacy" remains the default for the compatibility release.
The earlier precise_vector_blend_mode="linear_light" selects just the precise
screen-space vector pass, including dashed VectorOverlay strokes. MapScene
records the overall mode and the applied precise-vector mode in
last_render_metadata. The recipe omits compatibility defaults and includes
opt-ins in the path-free render cache identity.
Compositing boundary |
Incoming and outgoing RGB |
Alpha convention |
Transparent destination |
|---|---|---|---|
Precise vector points, rectangles, strokes, joins and polygon fills |
sRGB style and backdrop bytes are decoded. The vector pass returns straight sRGB bytes |
Linear style opacity × sample coverage, with premultiplied RGB through the pass |
Yes |
Native vector and point-cloud display overlays |
sRGB styles decode before GPU drawing. Linear float pixels enter the NumPy compositor. The next display stage receives sRGB8 |
Native polygon style opacity stays floating point through upload. Fill-only styles draw just the fill. Polygon output arrives premultiplied. Weighted OIT and eye-dome lighting outputs arrive straight and are premultiplied for source-over |
Yes |
MapScene label and halo drawing |
sRGB paint is decoded for native text. Ordinary label batches use an RGBA16F attachment and are read back as linear float RGBA. The completed stack publishes straight sRGB bytes |
Linear glyph coverage and alpha. Halo is composited under fill. Run opacity scales each premultiplied batch before source-over into the floating-point stack |
Yes |
MapScene furniture, text masks and placed images |
sRGB swatches and straight sRGB image assets enter one linear working buffer. Observation maps resize within that buffer |
Linear coverage and opacity, premultiplied until the pass returns |
Yes |
MapPlate map, title, legend, scale, arrow and inset |
Straight sRGB8 inputs. Map and inset resize in premultiplied linear values. The finished plate is sRGB8 |
Linear coverage and opacity, premultiplied through the stack |
Yes |
Terrain UV rasters and physical material paint |
Straight sRGB inputs enter the linear buffer. RGBA GeoTIFF bands reproject after premultiplication. The native drape upload decodes the straight sRGB albedo image into filterable RGBA16F before sampling |
Linear opacity and premultiplied RGB to the shader. Categorical nearest sampling retains exact ownership |
Yes |
Building shadows and textured landmark images |
Shadows attenuate linear RGB. Textured images resize and receive their vertical lighting ramp before compositing |
Shadows preserve existing alpha. Texture opacity and resampling use premultiplied alpha |
Yes |
Ordered image passes |
Input snapshots declare linear or sRGB. Display output is straight sRGB |
The graph retains premultiplied linear floats. Multiply and screen compute their overlap color in the declared pass color space |
Yes |
CONCORDIA vectors, landmarks, furniture, native labels and weighted point resolve |
Vector style coverage stays floating point from rasterization through upload. Depth-tested and glyph draws use RGBA16F. Prepared landmark and furniture images enter as RGBA32F. The completed stack is published to sRGB8 |
The GPU applies run opacity and source-over in a premultiplied RGBA32F stack. Weighted OIT retains its depth and resolve policy before its result enters the stack |
Yes in coverage replay. Beauty is opaque |
Viewer raster drape stack and PBR shader |
Straight sRGB8 inputs decode before CPU bilinear sampling. The GPU samples linear RGBA16F from a filterable texture |
Linear opacity and footprint weights. The shader composites onto opaque terrain or applies the existing cutout rule |
Stack yes. Terrain opaque |
Smoke image producer |
Tone-mapped linear RGB8. Pass it as |
Straight opacity, derived from volume transmittance |
The producer returns a transparent layer |
The image compositor uses one NumPy source-over implementation and a shared WGSL include. Native attachment blending uses matching GPU blend factors. Volume transmittance, scalar density interpolation, keyed material reflectance and categorical depth ownership retain their separate physical or sampling rules. Source-over associativity applies to normal composition. Ordered multiply and screen depend on the overlap colors and the order of those operations.
The viewer terrain fragment path keeps group 0 bindings 5 and 6 as a filterable
2D float texture and its sampler. The existing overlay_params.z carries the
blend code and adds 3 for premultiplied inputs. CONCORDIA sends premultiplied
linear vector, landmark and furniture pixels to the float upload path.
GPU raster sources use a blendable RGBA16F attachment. Frame-sized landmark
and furniture images feed the same accumulation pass from RGBA32F without
resampling. The pass reads the source and current RGBA32F stack with a 16-byte
opacity and image-extent uniform.
The final compute pass composites that stack over the decoded terrain
backdrop and writes sRGB8 to the RGBA8 storage view.
For MapScene terrain drapes, group 6 keeps the 224-byte material uniform at
binding 0, the sampler at 15, and the filterable 2D float texture at 17.
map_flags.w selects no drape (0), legacy RGBA8 (1), or linear premultiplied
RGBA16F (2). Terrain beauty and water reflections use the same drape function.
Registered vector stacks retain the linear working buffer through depth tests
and encode once when the display stack returns.
Use the golden accounting tool to
capture baseline from a clean checkout and legacy and linear_light from
the candidate. Supply the same --output directory and backend for all three
runs. The compare command checks every recipe in the catalog, including
compatibility controls such as cloud shadows and 16-bit PNG output. It verifies
frame hashes, compares both modes against the committed recipe PNG, and writes
RGB and any alpha difference images at the rendered precision. Missing frames
and legacy byte changes against the clean render fail the gate. A recorded
clean-render failure can use an exact match to the committed recipe PNG.
--historical-baseline also accepts a capture from a clean ancestor on the
same adapter and seed. The report records that revision, the original failure,
and the byte comparison against the committed reference.