Rendering
JAX-LaB includes a JAX-native ray marcher for in-situ rendering of three-dimensional arrays. A scene maps each field name to its own surface, refractive volume, or vector-magnitude material. Lighting, shadows, camera motion, global surface smoothing, and ray bounce count are configured once on the scene. Only the final RGB image is transferred to the host when a PNG is requested.
VectorRendering accepts arrays shaped (nx, ny, nz, 3) and maps their magnitude through viridis, plasma, inferno, magma, jet, gray,
or a custom RGB lookup array. Scalar fields may be shaped (nx, ny, nz) or (nx, ny, nz, 1).
Large max_bounces values increase both compilation and render time considerably. The default of one is intended for routine in-situ output. Increase
samples_per_voxel when a thin interface is missed, at the cost of proportionally more ray samples.
VolumeRendering.value_range defines occupancy, not only color normalization. Leave enough margin above the expected liquid density for transient
overshoots. A tight upper cutoff can turn small compressibility oscillations into artificial cavities and refractive layers.
Edge antialiasing is enabled by default. It runs on the active JAX device after layer compositing and adds only a fixed nine-tap image pass. Set
anti_aliasing=False for the lowest possible output overhead, or adjust anti_aliasing_strength between zero and one.
The renderer samples rays twice per voxel by default to avoid missing thin or grazing-angle interfaces. Lower samples_per_voxel only when render
throughput is more important than edge quality.
SurfaceRendering and VolumeRendering can color one field with another named field. Set color_field to a scalar field or a vector field of the
same spatial shape, provide its color_range, and select a colormap. Vector color fields are converted to magnitude on the active JAX device.
This is useful for coloring a density interface with velocity while the density interval continues to control the rendered region.
examples/rendering/liquid_on_staggered_slabs.py combines volume rendering with solid-surface rendering for gravity-driven liquid flow through two
hydrophobic staggered slabs.
jax_lab.render.Light
A positional light source.
Parameters
position (tuple of float): Light location in scene coordinates.
color (tuple of float): RGB light color in [0, 1].
intensity (float): Nonnegative light power.
Source code in jax_lab/render/scene.py
jax_lab.render.SurfaceRendering
Surface material for values inside a closed interval.
Parameters
value_range (tuple of float): Inclusive scalar interval defining the rendered material.
color (tuple of float): RGB surface color in [0, 1].
metallic (float): Metallic response in [0, 1].
roughness (float): Surface roughness in [0, 1].
opacity (float): Surface opacity in [0, 1].
spacing (tuple of float): Positive voxel spacing in scene coordinates.
origin (tuple of float): Field origin in scene coordinates.
casts_shadows (bool): Whether the surface tests visibility to scene lights.
color_field (str, optional): Named scalar or three-component vector field used to color the surface.
color_range (tuple of float, optional): Inclusive scalar or vector-magnitude range mapped through colormap.
colormap (str or numpy.ndarray): Built-in matplotlib-compatible name or RGB control-point array.
Source code in jax_lab/render/scene.py
jax_lab.render.VolumeRendering
Refractive volume material for values inside a closed interval.
Parameters
value_range (tuple of float): Inclusive scalar interval occupied by the volume.
color (tuple of float): RGB volume color in [0, 1].
opacity (float): Per-lattice-unit opacity in [0, 1].
index_of_refraction (float): Positive refractive index of the material.
spacing (tuple of float): Positive voxel spacing in scene coordinates.
origin (tuple of float): Field origin in scene coordinates.
color_field (str, optional): Named scalar or three-component vector field used to color the volume.
color_range (tuple of float, optional): Inclusive scalar or vector-magnitude range mapped through colormap.
colormap (str or numpy.ndarray): Built-in matplotlib-compatible name or RGB control-point array.
Source code in jax_lab/render/scene.py
jax_lab.render.VectorRendering
Colormapped magnitude rendering for a three-component vector field.
Parameters
value_range (tuple of float): Magnitude interval mapped through the colormap.
colormap (str or numpy.ndarray): Built-in matplotlib-compatible name or RGB control-point array.
opacity (float): Per-lattice-unit opacity in [0, 1].
spacing (tuple of float): Positive voxel spacing in scene coordinates.
origin (tuple of float): Field origin in scene coordinates.
Source code in jax_lab/render/scene.py
jax_lab.render.Scene
Define and render a collection of named three-dimensional fields.
Parameters
renderings (mapping of str to rendering configuration): Field names and their unique surface, volume, or vector configuration.
resolution (tuple of int): Output (width, height). Both values are assumed positive.
position (tuple of float): Camera location in scene coordinates.
target (tuple of float): Camera focal point in scene coordinates.
field_of_view (float): Vertical field of view in degrees, assumed to be in (0, 180).
up (tuple of float): Camera up direction.
lights (sequence of Light): Positional lights. At least one light is assumed.
background_color (tuple of float): RGB background color in [0, 1].
global_illumination (float): Nonnegative ambient-light intensity.
global_illumination_color (tuple of float): RGB ambient-light color in [0, 1].
shadows (bool): Enable shadow rays for surfaces that cast shadows.
max_bounces (int): Maximum refraction and indirect-light bounce count.
surface_smoothing (int): Number of on-device smoothing passes applied to scalar surfaces.
samples_per_voxel (float): Ray samples per minimum voxel spacing, assumed to be at least one.
anti_aliasing (bool): Apply a device-side FXAA-style edge filter to the composited image.
anti_aliasing_strength (float): Edge smoothing strength in [0, 1].
output_dir (str or pathlib.Path): Directory used for relative output filenames.
rotate (bool): Rotate the camera around target using rotation_angle.
Source code in jax_lab/render/scene.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
render
Render named fields and optionally save the final RGB image.
Parameters
data (mapping of str to array): Scalar or vector fields matching all names in renderings.
timestep (int): Simulation timestep used by optional camera rotation.
filename (str or pathlib.Path, optional): PNG filename. Relative paths are placed under output_dir.
Returns
jax.Array
RGB image with shape (height, width, 3) and values in [0, 1].
Source code in jax_lab/render/scene.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
rotation_angle
Return camera rotation in radians for a timestep.
Parameters
timestep (int): Current simulation timestep.
Returns
float Rotation angle. Subclasses may override this method.
Source code in jax_lab/render/scene.py
update_camera_position
Return the camera position, including optional target rotation.
Parameters
timestep (int): Current simulation timestep.
Returns
jax.Array
Camera position with shape (3,).
Source code in jax_lab/render/scene.py
jax_lab.render.render
Render data with a scene.
Parameters
scene (Scene): Configured rendering scene.
data (mapping of str to array): Named scalar or vector fields.
timestep (int): Simulation timestep used by optional camera rotation.
filename (str or pathlib.Path, optional): PNG output filename.
Returns
jax.Array Rendered RGB image.