Last chance! 50% off unlimited learning
Sale ends in
Takes the scene description and renders an image, either to the device or to a filename.
render_scene(
scene,
width = 400,
height = 400,
fov = 20,
samples = 100,
ambient_light = FALSE,
lookfrom = c(0, 1, 10),
lookat = c(0, 0, 0),
camera_up = c(0, 1, 0),
aperture = 0.1,
clamp_value = Inf,
filename = NULL,
backgroundhigh = "#80b4ff",
backgroundlow = "#ffffff",
shutteropen = 0,
shutterclose = 1,
focal_distance = NULL,
ortho_dimensions = c(1, 1),
tonemap = "gamma",
parallel = TRUE,
environment_light = NULL,
rotate_env = 0,
progress = interactive(),
verbose = FALSE,
debug = NULL
)
Tibble of object locations and properties.
Default `400`. Width of the render, in pixels.
Default `400`. Height of the render, in pixels.
Default `20`. Field of view, in degrees. If this is zero, the camera will use an orthographic projection. The size of the plane used to create the orthographic projection is given in argument `ortho_dimensions`.
Default `100`. Number of samples for each pixel.
Default `FALSE`, unless there are no emitting objects in the scene. If `TRUE`, the background will be a gradient varying from `backgroundhigh` directly up (+y) to `backgroundlow` directly down (-y).
Default `c(0,1,10)`. Location of the camera.
Default `c(0,0,0)`. Location where the camera is pointed.
Default `c(0,1,0)`. Vector indicating the "up" position of the camera.
Default `0.1`. Aperture of the camera. Smaller numbers will increase depth of field, causing less blurring in areas not in focus.
Default `Inf`. If a bright light or a reflective material is in the scene, occasionally there will be bright spots that will not go away even with a large number of samples. These can be removed (at the cost of slightly darkening the image) by setting this to a small number greater than 1.
Default `NULL`. If present, the renderer will write to the filename instead of the current device.
Default `#80b4ff`. The "high" color in the background gradient. Can be either a hexadecimal code, or a numeric rgb vector listing three intensities between `0` and `1`.
Default `#ffffff`. The "low" color in the background gradient. Can be either a hexadecimal code, or a numeric rgb vector listing three intensities between `0` and `1`.
Default `0`. Time at which the shutter is open. Only affects moving objects.
Default `1`. Time at which the shutter is open. Only affects moving objects.
Default `NULL`, automatically set to the `lookfrom-lookat` distance unless otherwise specified.
Default `c(1,1)`. Width and height of the orthographic camera. Will only be used if `fov = 0`.
Default `gamma`. Choose the tone mapping function, Default `gamma` solely adjusts for gamma and clamps values greater than 1 to 1. `reinhold` scales values by their individual color channels `color/(1+color)` and then performs the gamma adjustment. `uncharted` uses the mapping developed for Uncharted 2 by John Hable. `hbd` uses an optimized formula by Jim Hejl and Richard Burgess-Dawson. Note: If set to anything other than `gamma`, objects with material `light()` may not be anti-aliased.
Default `FALSE`. If `TRUE`, it will use all available cores to render the image (or the number specified in `options("cores")` if that option is not `NULL`).
Default `NULL`. An image to be used for the background for rays that escape the scene. Supports both HDR (`.hdr`) and low-dynamic range (`.png`, `.jpg`) images.
Default `0`. The number of degrees to rotate the environment map around the scene.
Default `TRUE` if interactive session, `FALSE` otherwise.
Default `FALSE`. Prints information and timing information about scene construction and raytracing progress.
Default `NULL`. If `bvh`, will return an image indicated the number of BVH lookups.
Raytraced plot to current device, or an image saved to a file.
# NOT RUN {
#Generate a large checkered sphere as the ground
scene = generate_ground(depth=-0.5, material = diffuse(color="white", checkercolor="darkgreen"))
# }
# NOT RUN {
render_scene(scene,parallel=TRUE,samples=500)
# }
# NOT RUN {
#Add a sphere to the center
scene = scene %>%
add_object(sphere(x=0,y=0,z=0,radius=0.5,material = diffuse(color=c(1,0,1))))
# }
# NOT RUN {
render_scene(scene,fov=20,parallel=TRUE,samples=500)
# }
# NOT RUN {
#Add a marbled cube
scene = scene %>%
add_object(cube(x=1.1,y=0,z=0,material = diffuse(noise=3)))
# }
# NOT RUN {
render_scene(scene,fov=20,parallel=TRUE,samples=500)
# }
# NOT RUN {
#Add a metallic gold sphere
scene = scene %>%
add_object(sphere(x=-1.1,y=0,z=0,radius=0.5,material = metal(color="gold",fuzz=0.1)))
# }
# NOT RUN {
render_scene(scene,fov=20,parallel=TRUE,samples=500)
# }
# NOT RUN {
#Lower the number of samples to render more quickly (here, we also use only one core).
render_scene(scene, samples=4)
#Add a floating R plot using the iris dataset as a png onto a floating 2D rectangle
# }
# NOT RUN {
tempfileplot = tempfile()
png(filename=tempfileplot,height=400,width=800)
plot(iris$Petal.Length,iris$Sepal.Width,col=iris$Species,pch=18,cex=4)
dev.off()
image_array = aperm(png::readPNG(tempfileplot),c(2,1,3))
scene = scene %>%
add_object(xy_rect(x=0,y=1.1,z=0,xwidth=2,angle = c(0,180,0),
material = diffuse(image = image_array)))
render_scene(scene,fov=20,parallel=TRUE,samples=500)
# }
# NOT RUN {
#Move the camera
# }
# NOT RUN {
render_scene(scene,lookfrom = c(7,1.5,10),lookat = c(0,0.5,0),fov=15,parallel=TRUE)
# }
# NOT RUN {
#Change the background gradient to a night time ambiance
# }
# NOT RUN {
render_scene(scene,lookfrom = c(7,1.5,10),lookat = c(0,0.5,0),fov=15,
backgroundhigh = "#282375", backgroundlow = "#7e77ea", parallel=TRUE,
samples=500)
# }
# NOT RUN {
#Increase the aperture to blur objects that are further from the focal plane.
# }
# NOT RUN {
render_scene(scene,lookfrom = c(7,1.5,10),lookat = c(0,0.5,0),fov=15,
aperture = 0.5,parallel=TRUE,samples=500)
# }
# NOT RUN {
#Spin the camera around the scene, decreasing the number of samples to render faster. To make
#an animation, specify the a filename in `render_scene` for each frame and use the `av` package
#or ffmpeg to combine them all into a movie.
t=1:30
xpos = 10 * sin(t*12*pi/180+pi/2)
zpos = 10 * cos(t*12*pi/180+pi/2)
# }
# NOT RUN {
#Save old par() settings
old.par = par(no.readonly = TRUE)
on.exit(par(old.par))
par(mfrow=c(5,6))
for(i in 1:30) {
render_scene(scene, samples=5,
lookfrom = c(xpos[i],1.5,zpos[i]),lookat = c(0,0.5,0), parallel=TRUE)
}
# }
Run the code above in your browser using DataLab