CG:SKEELOGY
CG:SKEELOGY
CATEGORIES
   REELS
       + demo reels (2)
   PROJECTS
       + games (4)
       + VFX & animations (4)
   PROGRAMMING
       + simulations (8)
       + computer vision (4)
       + rigging & deformation (4)
       + computer graphics (3)
       + artificial intelligence (2)
       + game technologies (2)
   CG
       + rigs (7)
       + models (7)
       + effects & simulations (3)
   TUTORIALS
       + physics simulation (1)
   ME
       + honours & awards (8)
       + events (7)
       + updates (3)
FEATURED PROJECTS
Soft Body Tutorial: Program soft bodies in XNA!
Cloud Guardian: Shape the Orb to fix clouds!
Muskeelar: Muscle system for games
LATEST UPDATES
  + Now On Twitter   + CG:Skeelogy v1.1: The Web 2.0 Version   + Best Physics Knowledge Base Entry In Intel Havok Physics Contest!   + Community Voting Prize In Intel Havok Physics Contest   + Working at Double Negative in London
TAGS
ARCHIVES
 
 
 
CURRENTLY VIEWING
DEPTH OF FIELD USING RAYTRACING
Using raytracing techniques to simulate depth of field
DATE
TYPE
EFFORT
Mar 2007
Rendering
Solo
Depth Of Field Using Raytracing
@ programming > computer graphics
SECTION MENU
     + Depth Of Field Using Raytracing
     + Solid Textures
     + Raytracing

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).

DOF render with: Focal Length = 2, Aperture Size = 64, Rays = 16
DOF render with: Focal Length = 2, Aperture Size = 64, Rays = 16

DOF render with: Focal Length = 5, Aperture Size = 128, Rays = 16
DOF render with: Focal Length = 5, Aperture Size = 128, Rays = 16

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.

Focal point P is found by intersecting the current ray with focal plane F
Focal point P is found by intersecting the current ray with focal plane F

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.

n rays are shot out from the newly placed grid, through the focal point P
n rays are shot out from the newly placed grid, through the focal point P

I used similar triangles to find out where P is at for the current ray. We first find:

  • d: The perpendicular distance from eye to image plane
  • d’: The distance from the eye to the pixel in question

The intersection point of the current ray (due to the current pixel to be rendered) with the focal plane is calculated as

equation

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.

Undesired banded appearance due to uniform sampling
Undesired banded appearance due to uniform sampling

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.

  • Share/Save/Bookmark
Tags: , ,

Related posts


Leave a comment:


Allows tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
CG:SKEELOGY
ABOUT ME
I have experience with physics simulation programming, character rigging and R&D on anatomical and deformable models. In my free time, I work on small personal projects such as casual games and tools development.
I am currently working at Double Negative Visual Effects in London.
MY OTHER SITES
SUBSCRIBE TO SITE
SHARE THIS SITE
Copyright © 2003-2010.
All works are original ones by Skeel, unless otherwise stated.