Whoever wants to contribute to this blog , posting his experiences on the same place, please send me a message !

Friday, May 11, 2012

Bidirectional Path Tracing using Nvidia Optix , Part 12 (Depth of field))

The current installment in my project was Depth of Field effect. This simple effect in path tracing is the effect of simulating the focus ability of any kind of non-perfect lens such as the camera lens or the human eye.

Using this effect , the final image has a focused region and two regions that are out of focus, the regions before and after the focused region.

In path tracing this effect is very simple as it is inherent in path tracing and to be exact nvidia provides those 10 lines in the "Cook" example. What i have done is making those lines fit in my code. here they are :

in the BDPT function:
                  // pixel sampling
 float2 pixel_sample = make_float2(bufferLaunch_index) + make_float2(jitter.x, jitter.y);
 float2 d = pixel_sample / make_float2(screen) * 2.f - 1.f;
 // Calculate ray-viewplane intersection point
 float3 ray_origin = eye;
 float3 ray_direction = d.x*U + d.y*V + W;
 float3 ray_target = ray_origin + focal_scale * ray_direction;

 // lens sampling
 float2 sample = optix::square_to_disk(make_float2(jitter.z, jitter.w));
ray_origin = ray_origin + aperture_radius * ( sample.x * normalize( U ) +  sample.y * normalize( V ) );
 ray_direction = normalize(ray_target - ray_origin);

//1st Step : Eye-Path
bool hitLight=true;
int eyeDepth = pathtrace_camera(ray_origin,ray_direction,hitLight, seed);
The light path is next and the combination of all the paths...

With lower aperture

With higher aperture

No comments:

Post a Comment