diff options
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/blender/blender_camera.cpp | 7 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_camera.h | 20 |
2 files changed, 24 insertions, 3 deletions
diff --git a/intern/cycles/blender/blender_camera.cpp b/intern/cycles/blender/blender_camera.cpp index b06ece049f1..6797ed6b71e 100644 --- a/intern/cycles/blender/blender_camera.cpp +++ b/intern/cycles/blender/blender_camera.cpp @@ -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"); diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h index f9d5bd3dd3f..02f64cd649a 100644 --- a/intern/cycles/kernel/kernel_camera.h +++ b/intern/cycles/kernel/kernel_camera.h @@ -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); } |