Media nest: the innermost medium replaces the surrounding one. Cameras inside media are detected automatically. A medium with zero absorption and scattering creates a vacuum cavity. Intersecting, non-nested volume boundaries are unsupported.

set_medium(scene, medium, keep_surface = FALSE)

Arguments

scene

A `ray_scene` containing closed spheres, cubes, ellipsoids, or watertight consistently oriented triangle meshes.

medium

A description from [homogeneous_medium()], [grid_medium()], or [nanovdb_medium()]. Use `NULL` to remove an attachment.

keep_surface

Default `FALSE`. Keep the object's surface material when `TRUE`, for example to place a medium inside glass. Dielectric attenuation adds absorption to the medium; it does not add emission.

Value

The scene with medium attachments stored independently of materials.

Examples

# An invisible boundary containing a scattering medium.
fog = homogeneous_medium(sigma_s = 2, g = 0.4)
scene = generate_ground(depth = -1, material = diffuse("grey30")) |>
  add_object(set_medium(sphere(x = -1.2), fog, keep_surface = FALSE)) |>
  add_object(sphere(x = 1.2, material = diffuse("coral"))) |>
  add_object(sphere(y = 4, z = -2, radius = 1, material = light(intensity = 30)))
render_scene(scene, lookfrom = c(0, 2, -8), lookat = c(0, 0, 0),
             fov = 40, aperture = 0, samples = 64, ambient_light = FALSE)


# Keep a glass surface around an absorbing water medium.
water = homogeneous_medium(sigma_a = c(0.3, 0.05, 0.02), sigma_s = 0.01)
glass = sphere(material = dielectric())
scene = set_medium(glass, water, keep_surface = TRUE) |>
  add_object(generate_ground(depth = -1,
    material = diffuse("white", checkercolor = "grey30"))) |>
  add_object(sphere(y = 4, z = -2, radius = 1, material = light(intensity = 30)))
render_scene(scene, lookfrom = c(0, 1, -6), lookat = c(0, 0, 0),
             fov = 35, aperture = 0, samples = 64, ambient_light = FALSE)