[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55454] trunk/blender/intern/cycles: Fix #34700: cycles depth of field now works with orthographic cameras too.

Brecht Van Lommel brechtvanlommel at pandora.be
Thu Mar 21 03:38:16 CET 2013


Revision: 55454
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55454
Author:   blendix
Date:     2013-03-21 02:38:11 +0000 (Thu, 21 Mar 2013)
Log Message:
-----------
Fix #34700: cycles depth of field now works with orthographic cameras too.

Modified Paths:
--------------
    trunk/blender/intern/cycles/blender/blender_camera.cpp
    trunk/blender/intern/cycles/kernel/kernel_camera.h

Modified: trunk/blender/intern/cycles/blender/blender_camera.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_camera.cpp	2013-03-20 23:14:18 UTC (rev 55453)
+++ trunk/blender/intern/cycles/blender/blender_camera.cpp	2013-03-21 02:38:11 UTC (rev 55454)
@@ -156,7 +156,12 @@
 
 		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");

Modified: trunk/blender/intern/cycles/kernel/kernel_camera.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_camera.h	2013-03-20 23:14:18 UTC (rev 55453)
+++ trunk/blender/intern/cycles/kernel/kernel_camera.h	2013-03-21 02:38:11 UTC (rev 55454)
@@ -94,7 +94,7 @@
 
 /* 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 @@
 	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 @@
 	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);
 }




More information about the Bf-blender-cvs mailing list