if (FALSE) { # interactive() || isTRUE(as.logical(Sys.getenv("IN_PKGDOWN")))
texture_dim = 800
u = seq(0, 2 * pi, length.out = texture_dim)
v = seq(0, 2 * pi, length.out = texture_dim)
knit_texture = outer(u, v, function(x, y) {
sin(10 * x + 0.75 * sin(10 * y))^2 + 0.35 * cos(12 * y)^2
})
knit_texture = (knit_texture - min(knit_texture)) / diff(range(knit_texture))
knit_texture = array(
rep(knit_texture, 3),
dim = c(texture_dim, texture_dim, 3)
)
rayimage::plot_image(knit_texture)
light_info = directional_light(c(1,1,1), color="dodgerblue",intensity=0.8) |>
add_light(directional_light(c(-1,-1,0.1), color="red",intensity=0.8)) |>
add_light(directional_light(c(0.5,1,0.5),intensity=0.8))
displacement_sphere(knit_texture,
displacement_scale = 0.08, verbose = TRUE) |>
rasterize_scene(light_info = light_info, fov=15)
#The default sphere has issues near the poles
displacement_sphere(knit_texture, displacement_scale = 0.08) |>
rasterize_scene(light_info = light_info, fov=10, lookfrom=c(0,10,10))
# A cube will render more nicely near the poles
displacement_sphere(knit_texture, use_cube = TRUE, displacement_scale = 0.08) |>
rasterize_scene(light_info = light_info, fov=10, lookfrom=c(0,10,10))
}
Run the code above in your browser using DataLab