rasterize_scene {rayvertex} | R Documentation |
Rasterize Scene
Description
Render a 3D scene with meshes, lights, and lines using a software rasterizer.
Usage
rasterize_scene(
scene,
filename = NA,
width = 800,
height = 800,
line_info = NULL,
alpha_line = 1,
parallel = TRUE,
plot = is.na(filename),
fov = 20,
lookfrom = c(0, 0, 10),
lookat = NULL,
camera_up = c(0, 1, 0),
fsaa = 2,
light_info = directional_light(),
color = "red",
type = "diffuse",
background = "black",
tangent_space_normals = TRUE,
shadow_map = TRUE,
shadow_map_bias = 0.003,
shadow_map_intensity = 0,
shadow_map_dims = NULL,
ssao = FALSE,
ssao_intensity = 10,
ssao_radius = 0.1,
tonemap = "none",
debug = "none",
near_plane = 0.1,
far_plane = 100,
shader = "default",
block_size = 4,
shape = NULL,
line_offset = 1e-05,
ortho_dimensions = c(1, 1),
bloom = FALSE,
antialias_lines = TRUE,
environment_map = "",
background_sharpness = 1,
verbose = FALSE,
vertex_transform = NULL,
validate_scene = TRUE
)
Arguments
scene |
The scene object. |
filename |
Default |
width |
Default |
height |
Default |
line_info |
Default |
alpha_line |
Default |
parallel |
Default |
plot |
Default |
fov |
Default |
lookfrom |
Default |
lookat |
Default |
camera_up |
Default |
fsaa |
Default |
light_info |
Default |
color |
Default |
type |
Default |
background |
Default |
tangent_space_normals |
Default |
shadow_map |
Default |
shadow_map_bias |
Default |
shadow_map_intensity |
Default |
shadow_map_dims |
Default |
ssao |
Default |
ssao_intensity |
Default |
ssao_radius |
Default |
tonemap |
Default |
debug |
Default |
near_plane |
Default |
far_plane |
Default |
shader |
Default |
block_size |
Default |
shape |
Default |
line_offset |
Default |
ortho_dimensions |
Default |
bloom |
Default |
antialias_lines |
Default |
environment_map |
Default |
background_sharpness |
Default |
verbose |
Default |
vertex_transform |
Default |
validate_scene |
Default |
Value
Rasterized image.
Examples
if(run_documentation()) {
#Let's load the cube OBJ file included with the package
rasterize_scene(cube_mesh(),lookfrom=c(2,4,10),
light_info = directional_light(direction=c(0.5,1,0.7)))
}
if(run_documentation()) {
#Flatten the cube, translate downwards, and set to grey
base_model = cube_mesh() |>
scale_mesh(scale=c(5,0.2,5)) |>
translate_mesh(c(0,-0.1,0)) |>
set_material(diffuse="grey80")
rasterize_scene(base_model, lookfrom=c(2,4,10),
light_info = directional_light(direction=c(0.5,1,0.7)))
}
if(run_documentation()) {
#load the R OBJ file, scale it down, color it blue, and add it to the grey base
r_model = obj_mesh(r_obj(simple_r = TRUE)) |>
scale_mesh(scale=0.5) |>
set_material(diffuse="dodgerblue") |>
add_shape(base_model)
rasterize_scene(r_model, lookfrom=c(2,4,10),
light_info = directional_light(direction=c(0.5,1,0.7)))
}
if(run_documentation()) {
#Zoom in and reduce the shadow mapping intensity
rasterize_scene(r_model, lookfrom=c(2,4,10), fov=10,shadow_map = TRUE, shadow_map_intensity=0.3,
light_info = directional_light(direction=c(0.5,1,0.7)))
}
if(run_documentation()) {
#Include the resolution (4x) of the shadow map for less pixellation around the edges
#Also decrease the shadow_map_bias slightly to remove the "peter panning" floating shadow effect
rasterize_scene(r_model, lookfrom=c(2,4,10), fov=10,
shadow_map_dims=4,
light_info = directional_light(direction=c(0.5,1,0.7)))
}
if(run_documentation()) {
#Add some more directional lights and change their color
lights = directional_light(c(0.7,1.1,-0.9),color = "orange",intensity = 1) |>
add_light(directional_light(c(0.7,1,1),color = "dodgerblue",intensity = 1)) |>
add_light(directional_light(c(2,4,10),color = "white",intensity = 0.5))
rasterize_scene(r_model, lookfrom=c(2,4,10), fov=10,
light_info = lights)
}
if(run_documentation()) {
#Add some point lights
lights_p = lights |>
add_light(point_light(position=c(-1,1,0),color="red", intensity=2)) |>
add_light(point_light(position=c(1,1,0),color="purple", intensity=2))
rasterize_scene(r_model, lookfrom=c(2,4,10), fov=10,
light_info = lights_p)
}
if(run_documentation()) {
#change the camera position
rasterize_scene(r_model, lookfrom=c(-2,2,-10), fov=10,
light_info = lights_p)
}
if(run_documentation()) {
#Add a spiral of lines around the model by generating a matrix of line segments
t = seq(0,8*pi,length.out=361)
line_mat = matrix(nrow=0,ncol=9)
for(i in 1:360) {
line_mat = add_lines(line_mat,
generate_line(start = c(0.5*sin(t[i]), t[i]/(8*pi), 0.5*cos(t[i])),
end = c(0.5*sin(t[i+1]), t[i+1]/(8*pi), 0.5*cos(t[i+1]))))
}
rasterize_scene(r_model, lookfrom=c(2,4,10), fov=10, line_info = line_mat,
light_info = lights)
}