|
Depth of field is implemented by giving the "eyepoint" an area,
much like soft shadows work by giving point lights an area.
Here, the size of the aperture (for our purposes, the lens
size) is calculated by the f-stop--just like in a real camera.
Larger apertures are denoted by smaller f-stops. On a normal
35mm camera, the largest aperture is usually around f-2.8 or
f-3.5, where the smallest aperture is usually f-22 or even f-27.
The size of the aperture determines the depth of field for a
scene. That is, a large aperture will result in a small
depth of field...or a smaller z-distance that is in focus.
When using a real camera with a large aperture, it's very
important to make sure that you focus on exactly what you want to
have in focus, because everything else will be slightly blurry.
Our implementation takes the normal eyepoint and shoots a (fake)
ray to the focal plane for a particular pixel (fake. adj:
it doesn't return a color). That intersection is noted.
The real ray (the one that returns a color) has origin not at the
eyepoint, but some random point on the lens. The ray is shot
to the intersection point on the focal plane that was noted
earlier. This means that everything on the plane of focus
will be hit where it originally would've been hit with a pinhole
camera model. The further away from the plane of focus an object
is, the more "incorrect" point it will be intersected--resulting
in the blurring effect we're after. My biggest
issue with this implementation was that I wasn't paying enough
attention to the physics of real cameras; I thought that I wasn't
getting the correct results, when actually I was. In my
raytracer, the lens radius is defined in terms of meters, meaning
that for the purpose of depth of field, my scene is also described
in terms of meters. My Cornell box scene of previous
assignments is 10m cubed. I have to stand 20m away to fit
the entire room in the viewplane of the camera (this seems
realistic). On most 50mm camera lenses (which is what we're
modeling) there is no option to focus at 20m...20m means infinity.
You just can't get any depth of field effects at that distance
with realistic apertures. To illustrate depth of
field in my raytracer, I brought the objects closer to the camera.
The somewhat lame scene below (sorry, I don't have time to model
something cool) have objects at 0.25m, 0.5m, 1m, and 50m away from
the camera lens (labeled). This first set of four images all
have aperture sizes calculated for a 50mm lens at f-3.5 (the
largest aperture on my personal 50mm lens). Each was set to
focus on a different z-plane. All the spheres have radius
50mm except the green one which has radius 12 meters.
|
|
Ah, back to my Cornell box problem... The
great thing about computers is that they don't have to obey the
physical restrictions of real cameras. The image below is
focused at 22.75m (the location of the glass sphere) and set to
f-0.025...meaning the diameter of the aperture is 2 meters wide!
It's too bad there isn't a real camera that big. (Actually,
in real life, this problem is solved by zoom lenses...like the
large ones you see professional photographers have at sporting
events. These can have a focal length of 1600mm and usually
just one f-stop, something like f-16. Meaning that
effectively the aperture diameter is something like 100mm.
Zoom lenses--by their nature--actually shorten the depth of field
of an image more so than standard lenses...so the blurring the
would occur is actually more than what you'd expect with a 0.1m
aperture.)
|
As a side note, the reason the wall intersections still have
this nice (ugly) square shape (instead of being blurred out of their
square shape) is because my aperture is based on a square, not a
disk.
One more thing: Ever since project 2 I've had this
"vertical-field-of-view" parameter in my raytracer. I
never knew what this actually should be set to for realistic
cameras. For this project I looked it up. The
vertical-field-of-view for a 50mm lens with film size 36mm x
24mm is 29.9915 degrees. So, that's the default setting
now. Like I mentioned above, it seems realistic, because
in order to fit the 10m tall Cornell box into my scene the lens
has to be 20m away.
Executable compiled with Microsoft Visual Studio
.NET Professional and run on a Dell desktop with an Intel Pentium 4 1.8
GHz processor with 1.0GB of RDRAM running Microsoft Windows XP.
|