Skip to content

Instantly share code, notes, and snippets.

@tylermorganwall
Last active September 17, 2019 12:07
Show Gist options
  • Save tylermorganwall/04ff40f1a903a447f47b39a456bef554 to your computer and use it in GitHub Desktop.
Save tylermorganwall/04ff40f1a903a447f47b39a456bef554 to your computer and use it in GitHub Desktop.
Raytracing fractal spheres, and showing off floating point error
library(rayrender)
indexval = 1
disklist = list()
drawCircle = function(x=0, y=0, z=0, radius = 1, depth = 4, frac = 2,
ystep = 1, layercolors = rainbow(depth)) {
materialval = lambertian(color = layercolors[depth])
disklist[[indexval]] <<- sphere(x=x, y=y, z=z, radius = radius,
material = materialval)
indexval <<- indexval + 1
if(depth > 1) {
drawCircle(x + radius/frac, y, z + ystep, radius/frac, depth - 1,
frac = frac, ystep=ystep/frac, layercolors = layercolors)
drawCircle(x - radius/frac, y, z + ystep, radius/frac, depth - 1,
frac = frac, ystep=ystep/frac, layercolors = layercolors)
drawCircle(x, y + radius/frac, z + ystep, radius/frac, depth - 1,
frac = frac, ystep=ystep/frac, layercolors = layercolors)
drawCircle(x, y - radius/frac, z + ystep, radius/frac, depth - 1,
frac = frac, ystep=ystep/frac, layercolors = layercolors)
}
}
drawCircle(ystep = 1, depth=8, frac = 2.5)
diskscene = do.call(rbind,disklist)
diskscene %>%
add_object(sphere(z=1.5, radius=0.05,
material = lambertian(lightintensity = 400, implicit_sample = TRUE))) %>%
render_scene(parallel = TRUE, lookfrom = c(0,0,4), lookat = c(0,0,1),
aperture = 0, fov=40, width = 1000, height = 1000,samples=100,
clamp_value = 20)
diskscene %>%
add_object(sphere(z=4, radius=0.05,
material = lambertian(lightintensity = 3200, implicit_sample = TRUE))) %>%
render_scene(parallel = TRUE, lookfrom = c(0,4,4), lookat = c(0,0,1.2),
aperture = 0, fov=0.4, width = 1200, height = 1200,samples=100,
clamp_value = 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment