simvx.graphics.renderer.transparency

Transparency sorting and instance splitting for correct alpha blending.

Transparent objects must be rendered back-to-front after all opaque geometry, with alpha blending enabled and depth writes disabled.

Module Contents

Functions

compute_sort_key

Return negative squared distance from camera for back-to-front sorting.

split_instances

Split instances into opaque, double-sided opaque, wireframe and transparent.

wireframe_slots

The instance slots whose material draws as wireframe (empty when none does).

sort_transparent

Sort transparent instances back-to-front relative to camera position.

extract_camera_position

Extract world-space camera position from a view matrix.

Data

API

simvx.graphics.renderer.transparency.__all__

[‘compute_sort_key’, ‘sort_transparent’, ‘split_instances’, ‘wireframe_slots’]

simvx.graphics.renderer.transparency.log

‘getLogger(…)’

simvx.graphics.renderer.transparency.compute_sort_key(transform: numpy.ndarray, camera_pos: numpy.ndarray) → float

Return negative squared distance from camera for back-to-front sorting.

Negative so that sorted() produces back-to-front order (farthest first). Uses squared distance to avoid the sqrt.

Args: transform: 4x4 model matrix (row-major numpy). camera_pos: Camera world-space position as (3,) array.

simvx.graphics.renderer.transparency.split_instances(instances: list[tuple[Any, numpy.ndarray, int, int, int]], materials: numpy.ndarray) → tuple[list[tuple[Any, numpy.ndarray, int, int, int]], list[tuple[Any, numpy.ndarray, int, int, int]], list[tuple[Any, numpy.ndarray, int, int, int]], list[tuple[Any, numpy.ndarray, int, int, int]]]

Split instances into opaque, double-sided opaque, wireframe and transparent.

Each returned entry is (mesh_handle, transform, material_id, viewport_id, original_index) where original_index is the position in the original instances list (needed to reference the correct SSBO slot).

A wireframe material draws its edges whatever its blend mode, so it is routed before the alpha test; its lines blend by their alpha.

Args: instances: List of (mesh_handle, transform, material_id, viewport_id) tuples. materials: Numpy array with MATERIAL_DTYPE, indexed by material_id.

Returns: (opaque, double_sided_opaque, wireframe, transparent) with original indices appended.

simvx.graphics.renderer.transparency.wireframe_slots(instances: list, materials: numpy.ndarray | None) → set[int]

The instance slots whose material draws as wireframe (empty when none does).

simvx.graphics.renderer.transparency.sort_transparent(instances: list[tuple[Any, numpy.ndarray, int, int, int]], camera_pos: numpy.ndarray) → list[tuple[Any, numpy.ndarray, int, int, int]]

Sort transparent instances back-to-front relative to camera position.

Args: instances: List of (mesh_handle, transform, material_id, viewport_id, original_index). camera_pos: Camera world-space position as (3,) array.

Returns: Sorted list (farthest from camera first).

simvx.graphics.renderer.transparency.extract_camera_position(view_matrix: numpy.ndarray) → numpy.ndarray

Extract world-space camera position from a view matrix.

For a view matrix V, the camera position is -R^T * t where R is the upper-left 3x3 rotation and t is the translation column.

Args: view_matrix: 4x4 view matrix (row-major numpy).

Returns: (3,) float32 array of the camera world position.