Reflecting sphere in focus.
Finally got some time to work on the project. The depth of field is working correctly now as you can see from the image above. For this effect, I moved the image plane behind the camera and tried to mimick a true camera. The camera was changed from a pin hole camera to one with an aperture. The aperture is controlled by the user. The user can now choose where to have focus on the screen by passing a parameter for distance of object from the camera.
The algorithm is as follows:
- Shoot a ray from the image pixel passing through the center of the lens into the scene.
- Calculate the point of intersection with the focal plane.
- Calculate the radius of the actual lens depending on its f-Number (aperture value).
- Shoot random rays within the aperture to this point. Smaller f-Number values (bigger radius of opening) will cause objects farther from the focal plane to be more out of focus. Also more areas come into focus as the f-Number increases.
Aperture: f/1.8 (F-Number: 1.8)
Aperture: f/8 (F-Number: 8)
Aperture: f/18 (F-Number: 18)
Pin hole camera
Is the code online on Github?
ReplyDelete