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¶
Return negative squared distance from camera for back-to-front sorting. |
|
Split instance list into opaque, double-sided opaque, and transparent. |
|
Sort transparent instances back-to-front relative to camera position. |
|
Extract world-space camera position from a view matrix. |
Data¶
API¶
- simvx.graphics.renderer.transparency.__all__¶
[‘compute_sort_key’, ‘split_instances’, ‘sort_transparent’]
- 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]], 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]]]¶
Split instance list into opaque, double-sided opaque, and transparent.
Each returned entry is
(mesh_handle, transform, material_id, viewport_id, original_index)whereoriginal_indexis the position in the originalinstanceslist (needed to reference the correct SSBO slot).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, transparent) with original indices appended.
- 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 * twhere 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.