|
This is a program written in openGL to simulate depth-of-field (DOF) effect using raytracing. User will define 3 parameters to specify the DOF look, namely the aperture size (which determines how blur the objects out of focus are), the focal length (which determines the z-distance in the view space which objects will be in focus) and the number of rays (which determines the quality of the blur).
An imaginary focal plane F is first defined behind the image plane. A ray is then cast from the eye through the current pixel to be rendered. The intersection point between this ray and F is the focal point P.
A square grid of length m (determined by the aperture size set by user) is placed on top of the current pixel and n rays are shot out from this grid to P, using stratified sampling. These DOF rays originate from the sampled grid point in image space and not from the eye. The results collected from these rays are blended to get the final color of the pixel to be rendered.
I used similar triangles to find out where P is at for the current ray. We first find:
The intersection point of the current ray (due to the current pixel to be rendered) with the focal plane is calculated as
where e is the eye’s world position, v is the unit vector from eye to current pixel and f is the focal length as specified by the user. Initially I did not jitter the sampling points on the grid and the result obtain had visible bands due to uniform sampling. It is the visual justification that we should use random sampling instead.
Note: As this is part of a group project, this DOF effect is created by modifying a distributed raytracer done by my groupmate Neo Jiet Shern. Tags: depth of field, OpenGL, raytracingRelated postsLeave a comment: |
|