Fix #34700: cycles depth of field now works with orthographic cameras too.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 21 Mar 2013 02:38:11 +0000 (02:38 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 21 Mar 2013 02:38:11 +0000 (02:38 +0000)
intern/cycles/blender/blender_camera.cpp
intern/cycles/kernel/kernel_camera.h

index b06ece049f1db0f208ca2c4da7c533dcb86ba49b..6797ed6b71e8999973dd3698b92dd78728faac4b 100644 (file)
@@ -156,7 +156,12 @@ static void blender_camera_from_object(BlenderCamera *bcam, BL::Object b_ob, boo
 
                if(aperture_type == 1) {
                        float fstop = RNA_float_get(&ccamera, "aperture_fstop");
-                       bcam->aperturesize = (bcam->lens*1e-3f)/(2.0f*max(fstop, 1e-5f));
+                       fstop = max(fstop, 1e-5f);
+
+                       if(bcam->type == CAMERA_ORTHOGRAPHIC)
+                               bcam->aperturesize = 1.0f/(2.0f*fstop);
+                       else
+                               bcam->aperturesize = (bcam->lens*1e-3f)/(2.0f*fstop);
                }
                else
                        bcam->aperturesize = RNA_float_get(&ccamera, "aperture_size");
index f9d5bd3dd3fa77cb8406d01f1d655902aa0c8d8c..02f64cd649a2342a5fda9436a62bdbe9a0144c93 100644 (file)
@@ -94,7 +94,7 @@ __device void camera_sample_perspective(KernelGlobals *kg, float raster_x, float
 
 /* Orthographic Camera */
 
-__device void camera_sample_orthographic(KernelGlobals *kg, float raster_x, float raster_y, Ray *ray)
+__device void camera_sample_orthographic(KernelGlobals *kg, float raster_x, float raster_y, float lens_u, float lens_v, Ray *ray)
 {
        /* create ray form raster position */
        Transform rastertocamera = kernel_data.cam.rastertocamera;
@@ -103,6 +103,22 @@ __device void camera_sample_orthographic(KernelGlobals *kg, float raster_x, floa
        ray->P = Pcamera;
        ray->D = make_float3(0.0f, 0.0f, 1.0f);
 
+       /* modify ray for depth of field */
+       float aperturesize = kernel_data.cam.aperturesize;
+
+       if(aperturesize > 0.0f) {
+               /* sample point on aperture */
+               float2 lensuv = camera_sample_aperture(kg, lens_u, lens_v)*aperturesize;
+
+               /* compute point on plane of focus */
+               float ft = kernel_data.cam.focaldistance/ray->D.z;
+               float3 Pfocus = ray->P + ray->D*ft;
+
+               /* update ray for effect of lens */
+               ray->P = make_float3(lensuv.x, lensuv.y, 0.0f);
+               ray->D = normalize(Pfocus - ray->P);
+       }
+
        /* transform ray from camera to world */
        Transform cameratoworld = kernel_data.cam.cameratoworld;
 
@@ -223,7 +239,7 @@ __device void camera_sample(KernelGlobals *kg, int x, int y, float filter_u, flo
        if(kernel_data.cam.type == CAMERA_PERSPECTIVE)
                camera_sample_perspective(kg, raster_x, raster_y, lens_u, lens_v, ray);
        else if(kernel_data.cam.type == CAMERA_ORTHOGRAPHIC)
-               camera_sample_orthographic(kg, raster_x, raster_y, ray);
+               camera_sample_orthographic(kg, raster_x, raster_y, lens_u, lens_v, ray);
        else
                camera_sample_panorama(kg, raster_x, raster_y, lens_u, lens_v, ray);
 }