Tuesday, April 2, 2013

Depth of Field

Depth of Field


  Depth of Field is help adds depth to your game, through different focal planes.  There are 2 different camera models, Pinhole and thin lens.


  Pinhole (shown on the left) lets a single ray through, which always hits the object, always creates an in focus picture.  While a scene might be in 3D space, it might appear flat since there is no depth within the field of view.  The thin lens model casts out multiple rays through a lens, which are then redirected towards the object.  If the rays come together to a single point and fall on the object at that position, it is considered to be in focus and falls on the focal plane.  If the rays hit it at a point of where they are scattered, they all attribute to image and create a circle of confusion.  This circle of confusion describes how blurry the object is.  The bigger the circle, the more out of focus it is.  


  The above picture shows 3 gnomes in a forest.  You can see the middle gnome is perfectly in focus, thus would fall on the focal plane.  The gnome closest to us is quite blurry and would fall on the Near Plane.  It's circle of confusion would be quite large, hence the extreme amount of blur.  Lastly, the gnome off in the distance would fall on the far plane, and would also have a large circle of confusion.  These planes help convey the depth of the image, and the distance each gnome has in the scene.



  The blur is created by downsampling the in focused image and then applying a gaussian blur.


  To do this for your game, you would take the circle of confusion, set a centre sample, and then randomnly sample parts within the circle using either Stochastic Sampling or Poisson distribution (Poisson is the preferred algorithm).  You then apply this sample to a filter.


  The filter is then sized based on whether or not the point is in focus or blurred.  The more blurred it is, the bigger the circle of confusion and pixels it affects on the kernel.  If it is in focus, it will affect a single pixel within the kernel.


  The end result is a photo-realistic image which conveys the proper depth within the scene, and accentuates the object which is the main focus.  Tune in soon for my next blog post!

No comments:

Post a Comment