Skip to content

1.0.0!

Latest

Choose a tag to compare

@tylermorganwall tylermorganwall released this 27 Nov 06:17
· 36 commits to master since this release
942a49e

rayshader 1.0.0!

Spatial rasters and scene coordinates

  • Build a terrain scene directly from a georeferenced elevation raster.
    montereybay_spatial |> sphere_shade() |> plot_3d() carries the elevation,
    extent, and coordinate reference system (CRS) through shading into the
    scene. Heightmaps can be matrices, terra or raster package objects, or raster
    filenames. Rayshader infers zscale from cell spacing, including the spacing
    in meters at the center of a longitude/latitude raster. Use
    vertical_exaggeration to scale relief independently. Matrix-based
    workflows and explicit spatial arguments are still supported. The default
    geographic aspect correction accounts for unequal east-west and north-south
    cell spacing.
  • Add layers in their own coordinates. After plot_3d(), a call such as
    render_path(roads) can use the scene's cached terrain, extent, CRS, and
    vertical scale to transform the roads and place them on the surface.
    Spatial layers support filtering to the scene extent with filter_to_extent.
    get_scene_metadata() exposes the coordinate information for the active scene.
  • Take a shaded map back into GIS with spatialize_image(). It returns a
    georeferenced terra::SpatRaster with RGB bands and optional alpha and
    original elevation bands. generate_raster_overlay() aligns a raster
    overlay to a map, and resize_spatial() changes raster resolution while
    preserving extent and CRS.
  • The bundled montereybay_spatial, volcano_spatial, and volcano_trails
    provide elevations and trail geometry for spatial examples. The original
    montereybay elevation matrix remains available.

Integrating 3D data with ggplot2

  • plot_gg() records how ggplot2 maps data into each panel. Points, paths,
    buildings, and extruded polygons can now share coordinates and heights
    with the original plot, including maps drawn with coord_sf(). Use
    flat_substrate = TRUE for a flat base beneath the 3D geometry.
  • render_polygons() maps a height column through the plot's height scale.
    A subset uses the same limits, transformation, binning, and inversion as
    the full data, including on flat plots with hidden legends.
    color = "height" also respects nonlinear scales. Supply scale_data
    for manual scaling or top and bottom for heights in scene units.
  • render_zaxis() adds a vertical axis to terrain and ggplot scenes. Set
    breaks, labels, and a title in the units of the data being shown. Faceted
    ggplots retain panel-specific coordinate information for layers and cameras.

Lakes, shorelines, and streams

  • render_water() and plot_3d() now default to
    water_render_method = "polygon" for exact polygon footprints. Each part
    extends from the lowest terrain beneath it to a level surface, preserving
    islands, small inlets, and exposed walls. Choose "optimized" to fit a
    lake's elevation by matching flooded terrain area to its mapped footprint,
    "raster" for a cell-based shoreline, or "legacy" for the earlier
    box/grid renderer. Code using the development version's area-fitting
    "polygon" method should select "optimized".
  • render_streams() draws streams along the terrain with widths that can
    vary by feature. Set their units with width_units. render_highquality(joined_stream_mesh = TRUE) can join
    the stream geometry. For reflected sunlight on rippled water, use
    water_material = "microfacet" in render_highquality(). The default
    material is "glassy".
  • add_water() accepts spatial masks such as montereybay_spatial < 0.
    It checks alignment, preserves the cached elevations, and leaves cells
    with missing mask values alone. shift_terrain() raises or lowers terrain
    beneath spatial features by a constant or a per-feature amount, for example
    to make room for a lake bed.

Roads, trails, and people at map scale

  • render_roads() builds pavement and lane markings at real-world widths
    and spacing. It reads OpenStreetMap lane, bridge, and layer attributes
    and models vertical road profiles from layer ordering, grades, and
    clearance constraints. Connected ramps meet at junctions even where
    several roads occupy different levels.
  • terrain_grading = TRUE cuts the terrain beneath roads so that surface
    junctions can stay near ground level. Later layers use the same graded
    terrain as the visible scene. render_trails() follows the surface with
    a fixed width or a width column and a choice of width units.
  • render_people() places posed human figures at geographic locations or
    along paths. Both model variants stand 1.8 meters tall, and other poses
    retain their relative proportions. Use simple_rgl = TRUE to preview a
    crowd as points. High-quality renders share full geometry among people
    with the same pose, model variant, and material.

Spatial objects, shading, and Earth curvature

  • render_points() and render_path() accept spatial points and lines.
    render_label() accepts points and multipoints and can label polygons at
    their centroids, with text from a data column and a choice of font.
    render_polygons() and render_beveled_polygons() use
    cached terrain and bounds. render_buildings() places footprints using
    CRS-aware filtering, height columns, roof angles, and roof materials.
    render_obj() can place models from spatial point data and repeat a single
    location at several altitudes. render_tree() accepts a tree-height column
    and offers a lightweight point preview with preview_simple = TRUE.
  • haze_shade() creates a transparent haze overlay from an exponential
    atmospheric model. radiance_shade() renders a top-down lighting pass from
    a DEM, cached shading data, or the active scene. Haze retains the raster's
    inferred zscale, extent, and CRS for subsequent calls to plot_3d().
    generate_altitude_overlay(relative = TRUE) sets transitions as fractions
    of the elevation range.
  • For regional scenes, plot_3d(earth_curvature = TRUE) bends the terrain
    relative to the center of its bounding box using a spherical Earth.
    Vertical exaggeration scales terrain relief independently of curvature.
    Spatial layers reuse the curvature setting for water, terrain-relative
    objects, and explicit altitudes. Inspect it with
    get_scene_metadata()$earth_curvature. It is off by default.
  • plot_3d(normals = FALSE) skips smooth terrain vertex normals and uses
    face normals in high-quality renders and OBJ exports. Other objects keep
    their own normals. shadow_texture_size controls the maximum resolution
    of the blurred base shadow.

High-quality rendering and animation

  • Set a camera position using map coordinates in render_camera() or
    render_highquality(). High-quality renders also accept explicit
    orthographic dimensions and per-object-type materials through rgl_materials.
  • Give render_highquality() a datetime to light a georeferenced scene
    for its location and time. Depending on the sky model, the sky can include
    stars, planets, and the Moon's phase and brightness. For a faceted map,
    select a panel directly or through a spatial camera target or location.
    The sky uses that panel's map bounds and display CRS.
  • The default text_render = "screen" draws camera-facing labels and annotation lines
    without casting shadows on the scene. Labels keep their screen size while
    their anchors follow the map. They appear in the interactive preview.
    deferred_render = TRUE gives you time to set up the camera before sampling.
  • render_movie_hq() renders camera animations from keyframes. Returned
    scenes carry their camera, sky, environment, and integrator settings into
    the movie. With animation overlay support in rayrender, screen-space labels,
    leader lines, and z-axis ticks are projected and checked for occlusion on
    each frame.
  • render_highquality(return_scene = TRUE) returns the resolved camera and
    render defaults. Collect texture assets explicitly with
    rayrender::write_usd() when exporting. Native sky lighting uses
    rayrender's default integrator unless one is supplied.
  • light = TRUE uses infinite disk lights. light_size is the full angular
    diameter in degrees (default 5), independent of scene size and camera
    position. Older rayrender versions without disk lights use spherical lights.

Updating existing code

  • Public arguments with joined descriptive words now use snake case,
    including window_size, base_shape, solid_depth, shadow_color,
    water_color, water_alpha, water_line_color, water_input,
    text_size, sun_angle, sun_altitude, normal_vectors, and
    progress_bar. Legacy spellings passed through ... warn with the
    replacement name. Passing both spellings raises an error. Established
    names such as heightmap, hillshade, zscale, filename, linewidth,
    and camera_lookat keep their spelling. In sphere_shade(), use
    vertical_exaggeration in place of the deprecated color_intensity.
  • render_zaxis() uses data, location, breaks, labels, title, and
    styling arguments without the development version's zaxis_ prefix.
  • Rayshader no longer re-exports %>% or exports run_documentation().
    Use R's native |> for simple pipelines or import %>% from magrittr.
  • Color arguments also accept strings of the form "rgb(20, 100, 255)",
    with channels from 0 to 255 and optional whitespace. Named, hexadecimal,
    and numeric colors retain their behavior.

Fixes and performance improvements

Terrain, ggplot2, and cameras

  • sphere_shade() bounds texture lookups on steep terrain.
    calculate_normal() returns unit-length edge normals oriented upward
    at all four corners.
  • Single-panel numeric geom_spatraster() height layers retain source
    precision, eliminating 8-bit elevation steps and gaps beneath buildings.
    Mixed and faceted height layers still use the image-based path.
    plot_gg() reuses the built height plot so that raster statistics, panel
    metadata, and the drawn image agree.
  • Geographic clipping follows straight panel boundaries. Polygon bases
    respect vertical scaling, and render_multipolygonz(), render_raymesh(),
    and render_obj() align absolute-elevation meshes horizontally with
    points and roads at different values of zscale and vertical exaggeration.
  • High-quality renders honor explicit fov values and choose a valid up
    vector for straight-down cameras. Screen-space text matches rgl's vertical
    alignment, including top z-axis titles and offsets beyond the text bounds.
  • Scene conversion takes one snapshot of rgl object IDs and skips unrelated
    preview materials. verbose = TRUE reports conversion and rayrender
    construction timings.

Water geometry

  • Polygon meshing uses native libgeos intersections only for triangles
    crossing the shoreline. Threads share one terrain snapshot and reuse
    terrain coverage and missing-data boundaries. options(cores = ...)
    controls concurrency and parallel = FALSE selects one thread.
    Diagnostics follow input order. Native terrain sampling preserves water
    levels, waterlines, and exact terrain intersections.
  • Mask boundaries have closed sidewalls. Meshing checks interior terrain
    minima, removes roundoff-only shoreline vertices, and separates bottom
    caps from coplanar terrain. water_surface_tolerance controls clearance
    for nearly coincident tops. Mixed geometry collections retain polygon
    parts and their original elevations.
  • Raster water aligns with pixel centers on spatial ggplots and uses the
    scene's actual terrain triangulation, including simplified terrain.
    Inferred levels get a small clearance, while explicit levels and aligned
    raster elevations retain their precision. Surface winding is corrected,
    and collapsed shoreline triangles are discarded. add_water() applies
    matrix and raster masks without horizontally mirroring them.
  • Exact polygon water uploads as one rgl triangle object even for disconnected
    features. Redraws are deferred until the batch and optional lines are ready.
    The previous redraw setting is restored on completion, error, or interruption.

Roads and bridges

  • Bridge tags activate profiles even without layer tags or crossings. Bridge
    inputs retain junctions with untagged approaches and branching ramps.
    Covered surface roads tagged tunnel = "building_passage" stay at ground
    level unless explicitly marked underground.
  • Road profiles preserve multipart, loop, and clipped segment identity through
    solving, grading, and meshing. Ground clearance is checked between vertices
    and across pavement width. Sharp and reversing joins produce finite terrain
    samples, and clipped endpoints tolerate micrometer-scale rounding. Small
    feasible networks converge more reliably, and diagnostics distinguish a
    solver failure from infeasible constraints.
  • Opaque pavement is 0.11 elevation units thick, independent of placement
    clearance. Both use the effective zscale, with a small precision margin
    against z-fighting. Graded terrain no longer hides rgl road-line previews.
  • Indexed native batches find intersections, continuations, endpoints, and
    crossing events without all-pairs searches. Profile preparation avoids
    repeated CRS parsing and spatial-table copies. Serial and parallel paths
    share a terrain snapshot across densification, cross-sections, bridge
    contacts, and stabilization retries. A new call sees any terrain edits.
    Road replacement defers redraws. verbose = TRUE reports preparation
    and solver stages before meshing.

Buildings, trees, and native builds

  • render_multipolygonz() and save_multipolygonz_to_obj() preserve
    concave faces and holes on horizontal, sloping, and vertical surfaces.
    Ordinary faces are triangulated in native batches. Crossed or overlapping
    boundaries are repaired in the face plane, and a summary warning identifies
    faces skipped after triangulation fails or yields zero area. Set
    options(rayshader.multipolygonz_repair = FALSE) to drop ambiguous
    intersections. verbose = TRUE reports preparation and upload stages.
    render_polygons() uses rayvertex::extruded_polygon_mesh() for extrusion.
  • render_tree() defaults to load_normals = FALSE to avoid shading artifacts
    on low-poly crowns. Set it to TRUE to use the model's normals. Negative
    sizes are discarded after converting absolute elevations, keeping each
    tree's color, dimensions, and rotation together.
  • Repeated trees and OBJ models share materials. Unrotated instances are built
    in native batches, preserving geometry, normals, and texture coordinates.
    Rotated instances retain the general transformation path.
  • Fixed GCC array-bounds warnings in native stream and road code, including
    stream mesh compilation with Rtools45 on Windows.