Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

rayrender

> 编程语言
Open source

A pathtracer for R. Build and render complex scenes and 3D data visualizations directly from R

643 stars0 likes1 views
WebsiteGitHub

About

A pathtracer for R. Build and render complex scenes and 3D data visualizations directly from R

rayrender

Overview

rayrender is an open source R package for raytracing scenes in created in R. This package provides a tidy R interface to a fast pathtracer written in C++ to render scenes built out of an array of primitives and meshes. rayrender builds scenes using a pipeable iterative interface, and supports diffuse, metallic, dielectric (glass), glossy, microfacet, light emitting materials, as well as procedural and user-specified image/roughness/bump/normal textures and HDR environment lighting. rayrender includes multicore support (with progress bars) via RcppThread, random number generation via the PCG RNG, OBJ/PLY support, and denoising support with Intel Open Image Denoise (OIDN).

Browse the documentation and see more examples at the website (if you aren’t already there):

rayrender.net

Installation

r
# To install the latest version from Github:
# install.packages("devtools")
devtools::install_github("tylermorganwall/rayrender")

Optional: denoising with Intel Open Image Denoise (OIDN)

rayrender can use Intel Open Image Denoise to denoise rendered images when OIDN is available on your system. If OIDN is not found, rayrender will still work, just without denoising support.

To get denoising support, you need to install OIDN. You can download the official binaries from Intel and set the OIDN_PATH argument in your .Renviron file with the following command line instructions:

macOS

bash
# Download the appropriate binary for your architecture
curl -LO https://github.com/OpenImageDenoise/oidn/releases/download/v2.3.1/oidn-2.3.1.x86_64.macos.tar.gz
# or for Apple Silicon
curl -LO https://github.com/OpenImageDenoise/oidn/releases/download/v2.3.1/oidn-2.3.1.arm64.macos.tar.gz

# Extract the archive
tar -xvzf oidn-2.3.1.x86_64.macos.tar.gz
# or for Apple Silicon
tar -xvzf oidn-2.3.1.arm64.macos.tar.gz

# Set OIDN_PATH in your .Renviron file to the extracted directory
echo "OIDN_PATH=/path/to/extracted/oidn" >> ~/.Renviron

linux

bash
# Download the binary
curl -LO https://github.com/OpenImageDenoise/oidn/releases/download/v2.3.1/oidn-2.3.1.x86_64.linux.tar.gz

# Extract the archive
tar -xvzf oidn-2.3.1.x86_64.linux.tar.gz

# Set OIDN_PATH in your .Renviron file to the extracted directory
echo "OIDN_PATH=/path/to/extracted/oidn" >> ~/.Renviron

Windows (Rtools45)

Windows is slightly trickier and requires Rtools45. The steps are:

  1. Install make and ninja via RTools.
  2. Install ISPC (Intel SPMD Program Compiler).
  3. Download the OIDN source repository.
  4. Compile and install OIDN, and point rayrender to it via OIDN_PATH.

OIDN_PATH should point to a directory that contains include/OpenImageDenoise and lib (or lib64) with the OIDN libraries.

Install prerequisites

  1. Install Rtools45

  2. Open the “Rtools45 MinGW UCRT64” shell (ucrt64) in RTools45.

  3. Inside that shell, install the build tools (including make, ninja, cmake, git, and ispc) via pacman:

bash
pacman -Sy --needed \
    mingw-w64-ucrt-x86_64-make \
    mingw-w64-ucrt-x86_64-ninja \
    mingw-w64-ucrt-x86_64-cmake \
    mingw-w64-ucrt-x86_64-ispc
  1. Make sure the Rtools static-posix toolchain and the MinGW binaries are on PATH (this mirrors the setup used to build OIDN):
bash
export PATH="/c/rtools45/x86_64-w64-mingw32.static.posix/bin:/mingw64/bin:${PATH}"
  1. Verify the toolchain:
bash
gcc --version
g++ --version
make --version
ninja --version
cmake --version
ispc --version
  1. Confirm ISPC is available:
bash
ispc --version

Build and install OIDN from source (CPU-only)

All of the following commands are run from the Rtools45 ucrt64 shell:

…

If CMake cannot find TBB in Rtools automatically, add a hint such as:

bash
-DTBB_ROOT=/path/to/rtools45/x86_64-w64-mingw32.static.posix

(adjust the path for your actual Rtools45 install) to the cmake command above.

Then build and install:

bash
ninja
ninja install

After installation you should have, for example:

C:/local/oidn/include/OpenImageDenoise/oidn.h
C:/local/oidn/lib/libOpenImageDenoise.a   (and related libs)

Tell R where OIDN lives

In a regular Windows shell or PowerShell, add to your user .Renviron:

powershell
echo 'OIDN_PATH=C:/local/oidn' >> "$HOME/.Renviron"

or edit the file and add the above manually with devtools::edit_r_environ().

Restart R (or your IDE), then reinstall rayrender from source:

r
devtools::install_github("tylermorganwall/rayrender", force = TRUE)

After this, rayrender should detect OIDN during configure and enable denoising support on Windows.

Usage

We’ll first start by rendering a simple scene consisting of the ground, a sphere, and the included R.obj file. The location of the R.obj file can be accessed by calling the function r_obj(). First adding the ground using the render_ground() function. This renders an extremely large sphere that (at our scene’s scale) functions as a flat surface. We also add a simple blue sphere to the scene.

r
library(rayrender)

scene = generate_ground(material=diffuse(checkercolor="grey20")) |>
  add_object(sphere(y=0.2,material=glossy(color="#2b6eff",reflectance=0.05))) 
render_scene(scene, parallel = TRUE, width = 800, height = 800, samples = 16)

By default, a scene without any lights includes a blue sky. We can turn this off either by setting ambient_light = FALSE, or by adding a light to our scene. We will add an emissive sphere above and behind our camera.

r
scene = generate_ground(material=diffuse(checkercolor="grey20")) |>
  add_object(sphere(y=0.2,material=glossy(color="#2b6eff",reflectance=0.05))) |>
  add_object(sphere(y=10,z=1,radius=4,material=light(intensity=4))) |>
  add_object(sphere(z=15,material=light(intensity=70)))
render_scene(scene, parallel = TRUE, width = 800, height = 800, samples = 16)

Now we’ll add the (included) R .obj file into the scene, using the obj_model() function. We will scale it down slightly using the scale_obj argument, and then embed it on the surface of the ball.

r
scene = generate_ground(material=diffuse(checkercolor="grey20")) |>
  add_object(sphere(y=0.2,material=glossy(color="#2b6eff",reflectance=0.05))) |>
  add_object(obj_model(r_obj(simple_r = TRUE),
                       z=1,y=-0.05,scale_obj=0.45,material=diffuse())) |>
  add_object(sphere(y=10,z=1,radius=4,material=light(intensity=4))) |>
  add_object(sphere(z=15,material=light(intensity=70)))
render_scene(scene, parallel = TRUE, width = 800, height = 800, samples = 16)

Here we’ll render a grid of different viewpoints.

…

Here’s another example: We start by generating an empty Cornell box and rendering it with render_scene(). Setting parallel = TRUE will utilize all available cores on your machine. The lookat, lookfrom, aperture, and fov arguments control the camera, and the samples argument controls how many samples to take at each pixel. Higher sample counts result in a less noisy image.

r
scene = generate_cornell()
render_scene(scene, lookfrom=c(278,278,-800),lookat = c(278,278,0), aperture=0, fov=40, samples = 16,
             ambient_light=FALSE, parallel=TRUE, width=800, height=800)

Here we add a metal ellipsoid, a checkered purple cube, a colored glass sphere, a pig, and plaster the walls with the iris dataset using textures applied to rectangles. We first write the textures out to a temporary filename, and then read the image back in using the png::readPNG() function. We then pass this to the image argument in the diffuse material, which applies it as a texture.

r
tempfileplot = tempfile()
png(filename=tempfileplot,height=1600,width=1600)
plot(iris$Petal.Length,iris$Sepal.Width,col=iris$Species,pch=18,cex=12)
dev.off()
## quartz_off_screen 
##                 2
…

Rayrender also has an interface to create objects using constructive solid geometry, with a wide variety of primitives and operations.

…

We can also use the path() element to draw 3D paths. Here, we render the Lorenz attractor:

…

rayrender also supports an extruded path object that generates a variable width path with any non-intersecting simple polygon (including holes) as an input. You can vary the width, add twist, and change the shape of the polygon along the path’s length.

…
## Warning in mesh3d_model(mesh, x = x, y = y, z = z, override_material = TRUE, :
## material set as vertex color but no texture or bump map passed--ignoring mesh3d
## material.
…
## Warning in mesh3d_model(mesh, x = x, y = y, z = z, override_material = TRUE, :
## material set as vertex color but no texture or bump map passed--ignoring mesh3d
## material.

Finally, rayrender supports environment lighting with the environment_light argument. Pass a high dynamic range image (.hdr) or a low-dynamic range image (.jpg,.png) and the image will be used to light the scene (along with any other lights). Here’s an example using an HDR image of Venice at sunset (obtained for free from hdrihaven.com), also using the Oren-Nayar diffuse model with sigma = 90 for a more realistic diffuse surface. We also add an extruded polygon star, using the extruded_polygon object.

…

Acknowledgments

Thanks to Brodie Gaslam (@brodieG) for contributions to the extruded_polygon() function.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言