tylermorganwall / rayrender

A pathtracer for R. Build and render complex scenes and 3D data visualizations directly from R
http://www.rayrender.net
622 stars 43 forks source link

greater aperture -> smaller depth of field #11

Closed brodieG closed 4 years ago

brodieG commented 5 years ago

Sorry to keep hassling you on this issue as it's a rehash of #5. I think the current docs still conflict with observed rayrender behavior, i.e. that smaller apertures lead to larger depths of field, meaning more things are in focus. The following experiment appears to demonstrate this, with the very small aperture having everything in focus. The behavior rayrender exhibits coincides with my understanding of aperture in photography.

Also, from wikipedia we have:

For many cameras, depth of field (DOF) is the distance between the nearest and the farthest objects that are in acceptably sharp focus in an image.

So larger depth of field should mean more things in focus. Sorry to be a PITA. Feel free to ignore all this if it's too much.

Finally, apologies for not basing this off of head but due to the ambient light issue #10 I couldn't get the examples below to work.

library(rayrender)
cylsl <- lapply(5:(-5), function(x) cylinder(length=3, x=-.5, z=x*2, y=1.5, material=diffuse('yellow'), radius=.1))
cylsr <- lapply(5:(-5), function(x) cylinder(length=3, x=.5, z=x*2, y=1.5, material=diffuse('yellow'), radius=.1))

scene = generate_ground(depth=-0.5, material = diffuse(color="white", checkercolor="darkgreen"))

# small aperture: sharp throughout, i.e. large depth of field

render_scene(
  dplyr::bind_rows(c(list(scene), cylsl, cylsr)),
  parallel=TRUE, samples=100, fov=45, aperture=0.00000001
)

# large aperture: blurry except at focal plane, i.e. shallow depth of field

render_scene(
  dplyr::bind_rows(c(list(scene), cylsl, cylsr)),
  parallel=TRUE, samples=100, fov=45, aperture=1
)

Created on 2019-11-11 by the reprex package (v0.3.0)

tylermorganwall commented 4 years ago

Looks good, thanks!