Assignment 4
Fabian Prada
This assignament explores the simulation of a realistic camera.
Part I: Ray Tracing Through a Lens System
The construction of the realistic was done as specified in [1]. My implementation consists of three classes:
1) LensElement:
Attributes:
- float sphericalRadius
- float z_axiz_intercept
- float WorldSideRefractionIndex
- float CameraSideRefractionIndex
- float sphericalCentre
- float aperture
- bool isConvex
Methods:
- bool generateRefractionDirection(Ray *ray): This methods receives a ray that comes from the camera side of the lens system. It finds the intersection point of the ray with this element (if any) and calculates the refraction direction usnig Snell's law. Then update the ray origin and direction to the hitting point and the refraction direction.
- bool generateReverseOrderRefractionDirection(Ray *ray): This method does an analogous task to the previous one, but now the ray is coming from the world side of the lens.
2) apertureStop:
Attributes:
- float z_axiz_intercept
- float aperture_diameter
Methods:
- bool evaluatePassApertureStop(Ray *ray): Determines if the given ray pass trhough the apperture stop. The ray is not modified.
3) lensSystem:
Attributes:
- int numElements
- int posApertureStop
- lensElement * elements
- apertureStop * apStop
- float filmdistance
- float aperture_diameter
Methods:
- bool evaluateRayTrajectory(Ray *ray): This methods determines if a given ray gets entering to the back element of the len system (the closest element to the film) and traverse the remain elements. In such case, it assigns to the pointed ray the origin at the intersection with the front element of the len system and the last refraction direction.
- bool evaluateReverseOrderRayTrajectory(Ray * ray): This method is analogous to the previous one, but now the ray is coming from the world side of the lens system, and it determines if the ray gets the back element.
Implementation Procedure:
- Given a sample in Raster coordinates it is initially transformed to Film coordinates at Camera Space.
- Using the lensU and lensV values of the sample, and ConcentricSampleDisk(), I defined a point in the aperture disk of the back element of the len system. The ray to be evaluated is constructed with origin at the sample position in the Film and direction to the point in the aperture disk of the back elemenent.
- The ray trajectory through the lens system is calculated using the method evaluateRayTrajectory(), which invokes the method generateRefractionDirection() at each element. evaluatePassApertureStop() is called between the two elements where the aperture stop is located.
- If the ray gets the front element of the lens system, the this ray is transformed from Camera Sapce to World Space and it is passed to the renderer.
Results:
Camera |
4 Samples |
512 Samples |
DGauss 50mm |
|
|
Wide 22mm |
|
|
Telephoto 250mm |
|
|
Fisheye 10mm |
|
|
Part II: Autofocus Simulation
My implementation of Autofocus is based on estimating the position of the Princial Planes and Focal Points as described in [1]. The procedure I used to find such points was shooting parellel rays from both sides of the lens system as suggested in [1]:
- I generate 20 rays parallel to z axis from 1mm behind the back element of the lens system and distributed vertically. I took as principal focal point F the mean of the z value where the rays intersected the xz plane. The principal plane P was estimated as the mean z value where the refracted rays intersected the original rays.
- The secondary focal point F' and the secondary plane P' were estimated analogously, but now the test rays where generated 1mm before the front element and in direction to the the Film.
- To calculate the focus adjustment as suggested in [1] I required to konw the object position. Then I generated rays from the Autofocus Zone in the Film (at Camera Space) that cross the lens system and go to the World. Using the scene class I was able to calculate the intersection of the ray in the World Space. Using the inverse of the CameraToWorld transform I was able to get the intersection point Camera Space coordinates.
- From the equation 1/z'-1/z=1/f', in [1], (z=distance from P to the object, z'=distance from P' to film, f'=distance P' to F'), and all the previous information, I was able to calculate z', and consecuently, the new position of the film.
- Finally the film was moved to the new position In order to have the desired object at focus.
Results:
Scene |
In Focus |
Out of Focus |
DGauss 50mm Close Up |
|
|
DGauss 50mm BG |
|
|
Scene |
In Focus 1 |
In Focus 2 |
Out of Focus |
DGauss 50mm Spheres |
|
|
|
Scene |
Default Focus |
Close Focus |
Far Focus |
DGauss 50mm Bunnies |
|
|
|
Reference
- [1]"A Realistic Camera Model for Computer Graphics".Craig Kolb, Don Mitchell, and Pat Hanrahan. Computer Graphics (Proceedings of SIGGRAPH '95), ACM SIGGRAPH, 1995, pp. 317-324