#Render the volcano dataset using pathtracing
if(run_documentation()) {
volcano %>%
sphere_shade() %>%
plot_3d(volcano,zscale = 2)
render_highquality(min_variance = 0, sample_method = "sobol_blue")
}
#Change position of light
if(run_documentation()) {
render_highquality(lightdirection = 45, min_variance = 0, sample_method = "sobol_blue")
}
#Change vertical position of light
if(run_documentation()) {
render_highquality(lightdirection = 45, lightaltitude = 10,
min_variance = 0, samples = 16)
}
#Change the ground material
if(run_documentation()) {
render_highquality(lightdirection = 45, lightaltitude=60,
ground_material = rayrender::diffuse(checkerperiod = 30, checkercolor="grey50"),
min_variance = 0, samples = 16)
}
#Add three different color lights and a title
if(run_documentation()) {
render_highquality(lightdirection = c(0,120,240), lightaltitude=45,
lightcolor=c("red","green","blue"), title_text = "Red, Green, Blue",
title_bar_color="white", title_bar_alpha=0.8,
min_variance = 0, samples = 16)
}
#Change the camera:
if(run_documentation()) {
render_camera(theta=-45,phi=60,fov=60,zoom=0.8)
render_highquality(lightdirection = c(0),
title_bar_color="white", title_bar_alpha=0.8,
min_variance = 0, samples = 16)
}
#Add a shiny metal sphere
if(run_documentation()) {
render_camera(theta=-45,phi=60,fov=60,zoom=0.8)
render_highquality(lightdirection = c(0,120,240), lightaltitude=45,
lightcolor=c("red","green","blue"),
scene_elements = rayrender::sphere(z=-60,y=0,
radius=20,material=rayrender::metal()),
min_variance = 0)
}
#Add a red light to the volcano and change the ambient light to dusk
if(run_documentation()) {
render_camera(theta=45,phi=45)
render_highquality(lightdirection = c(240), lightaltitude=30,
lightcolor=c("#5555ff"),
scene_elements = rayrender::sphere(z=0,y=15, x=-18, radius=5,
material=rayrender::light(color="red",intensity=10)),
min_variance = 0, samples = 16)
}
#Manually change the camera location and direction
if(run_documentation()) {
render_camera(theta=45,phi=45,fov=90)
render_highquality(lightdirection = c(240), lightaltitude=30, lightcolor=c("#5555ff"),
camera_location = c(50,10,10), camera_lookat = c(0,15,0),
scene_elements = rayrender::sphere(z=0,y=15, x=-18, radius=5,
material=rayrender::light(color="red",intensity=10)),
min_variance = 0, samples = 16)
}
# Render the shadow of the Washington Monument with a realistic sky at that datetime
# using the `skymodelr` package.
run_examples = length(find.package("sf", quiet = TRUE)) &&
length(find.package("elevatr", quiet = TRUE)) &&
length(find.package("raster", quiet = TRUE)) &&
run_documentation()
if(run_examples) {
library(sf)
#Set location of washington monument
washington_monument_location = st_point(c(-77.035249, 38.889462))
wm_point = washington_monument_location |>
st_point() |>
st_buffer(0.01) |>
st_sfc(crs = 4326) |>
st_transform(st_crs(washington_monument_multipolygonz))
elevation_data = elevatr::get_elev_raster(locations = wm_point, z = 14)
scene_bbox = st_bbox(st_buffer(wm_point,300))
cropped_data = raster::crop(elevation_data, scene_bbox)
#Use rayshader to convert that raster data to a matrix
dc_elevation_matrix = raster_to_matrix(cropped_data)
#Remove negative elevation data
dc_elevation_matrix[dc_elevation_matrix < 0] = 0
#Plot a 3D map of the national mall
dc_elevation_matrix |>
height_shade() |>
add_shadow(lamb_shade(dc_elevation_matrix), 0) |>
plot_3d(dc_elevation_matrix, zscale=3.7, water = TRUE, waterdepth = 1,
soliddepth=-50, windowsize = 800)
#Zoom in on the monument
render_camera(theta=45, phi=0, zoom= 0.03, fov=130)
#Render the national monument at solar noon on the solstice
rgl::par3d(ignoreExtent = TRUE)
render_multipolygonz(washington_monument_multipolygonz,
extent = raster::extent(cropped_data),
zscale = 4, color = "grey80",
heightmap = dc_elevation_matrix)
#Render using the built-in (but less accurate) Hosek model.
# Here's it's more yellow than it should be, but it's accurate enough for most renders.
render_highquality(
min_variance = 0,
samples = 16,
long = -77.035249,
lat = 38.889462,
iso = 8,
clamp_value = 10000,
datetime = as.POSIXct("2025-12-21 16:00:00", tz = "EST")
)
# Render the more-accurate Praguq model (that requires
# supplemental data that will be downloaded on the first call) and
# specify a higher resolution environment map via `sky_args`
render_highquality(
min_variance = 0,
samples = 16,
long = -77.035249,
lat = 38.889462,
sky_args = list(hosek = FALSE,resolution=4000),
iso = 8,
clamp_value = 10000,
datetime = as.POSIXct("2025-12-21 16:00:00", tz = "EST")
)
}
Run the code above in your browser using DataLab