[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46329] trunk/blender/intern/cycles/kernel : Cycles: minor refactoring of fisheye code to fit code style.

Brecht Van Lommel brechtvanlommel at pandora.be
Sat May 5 21:44:35 CEST 2012


Revision: 46329
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46329
Author:   blendix
Date:     2012-05-05 19:44:35 +0000 (Sat, 05 May 2012)
Log Message:
-----------
Cycles: minor refactoring of fisheye code to fit code style.

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

Modified: trunk/blender/intern/cycles/kernel/kernel_camera.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_camera.h	2012-05-05 19:44:33 UTC (rev 46328)
+++ trunk/blender/intern/cycles/kernel/kernel_camera.h	2012-05-05 19:44:35 UTC (rev 46329)
@@ -134,19 +134,16 @@
 
 /* Panorama Camera */
 
-__device float3 panorama_to_direction(KernelGlobals *kg, float u, float v, Ray *ray)
+__device float3 panorama_to_direction(KernelGlobals *kg, float u, float v)
 {
-	switch (kernel_data.cam.panorama_type) {
-	case PANORAMA_EQUIRECTANGULAR:
-		return equirectangular_to_direction(u, v);
-		break;
-	case PANORAMA_FISHEYE_EQUIDISTANT:
-		return fisheye_to_direction(u, v, kernel_data.cam.fisheye_fov, ray);
-		break;
-	case PANORAMA_FISHEYE_EQUISOLID:
-	default:
-		return fisheye_equisolid_to_direction(u, v, kernel_data.cam.fisheye_lens, kernel_data.cam.fisheye_fov, kernel_data.cam.sensorwidth, kernel_data.cam.sensorheight, ray);
-		break;
+	switch(kernel_data.cam.panorama_type) {
+		case PANORAMA_EQUIRECTANGULAR:
+			return equirectangular_to_direction(u, v);
+		case PANORAMA_FISHEYE_EQUIDISTANT:
+			return fisheye_to_direction(u, v, kernel_data.cam.fisheye_fov);
+		case PANORAMA_FISHEYE_EQUISOLID:
+		default:
+			return fisheye_equisolid_to_direction(u, v, kernel_data.cam.fisheye_lens, kernel_data.cam.fisheye_fov, kernel_data.cam.sensorwidth, kernel_data.cam.sensorheight);
 	}
 }
 
@@ -165,8 +162,14 @@
 	ray->t = FLT_MAX;
 #endif
 
-	ray->D = panorama_to_direction(kg, Pcamera.x, Pcamera.y, ray);
+	ray->D = panorama_to_direction(kg, Pcamera.x, Pcamera.y);
 
+	/* indicates ray should not receive any light, outside of the lens */
+	if(len_squared(ray->D) == 0.0f) {
+		ray->t = 0.0f;
+		return;
+	}
+
 	/* transform ray from camera to world */
 	Transform cameratoworld = kernel_data.cam.cameratoworld;
 
@@ -185,10 +188,10 @@
 	ray->dP.dy = make_float3(0.0f, 0.0f, 0.0f);
 
 	Pcamera = transform_perspective(&rastertocamera, make_float3(raster_x + 1.0f, raster_y, 0.0f));
-	ray->dD.dx = normalize(transform_direction(&cameratoworld, panorama_to_direction(kg, Pcamera.x, Pcamera.y, ray))) - ray->D;
+	ray->dD.dx = normalize(transform_direction(&cameratoworld, panorama_to_direction(kg, Pcamera.x, Pcamera.y))) - ray->D;
 
 	Pcamera = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y + 1.0f, 0.0f));
-	ray->dD.dy = normalize(transform_direction(&cameratoworld, panorama_to_direction(kg, Pcamera.x, Pcamera.y, ray))) - ray->D;
+	ray->dD.dy = normalize(transform_direction(&cameratoworld, panorama_to_direction(kg, Pcamera.x, Pcamera.y))) - ray->D;
 
 #endif
 }

Modified: trunk/blender/intern/cycles/kernel/kernel_montecarlo.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_montecarlo.h	2012-05-05 19:44:33 UTC (rev 46328)
+++ trunk/blender/intern/cycles/kernel/kernel_montecarlo.h	2012-05-05 19:44:35 UTC (rev 46329)
@@ -91,8 +91,8 @@
 											 float3 *omega_in, float *pdf)
 {
 	float z = randu;
-	float r = sqrtf(max(0.f, 1.f - z*z));
-	float phi = 2.f * M_PI_F * randv;
+	float r = sqrtf(max(0.0f, 1.0f - z*z));
+	float phi = 2.0f * M_PI_F * randv;
 	float x = r * cosf(phi);
 	float y = r * sinf(phi);
 
@@ -226,22 +226,20 @@
 
 /* Fisheye <- Cartesian direction */
 
-__device float3 fisheye_to_direction(float u, float v, float fov, Ray *ray)
+__device float3 fisheye_to_direction(float u, float v, float fov)
 {
-	u = (u - 0.5f) * 2.f;
-	v = (v - 0.5f) * 2.f;
+	u = (u - 0.5f) * 2.0f;
+	v = (v - 0.5f) * 2.0f;
 
 	float r = sqrt(u*u + v*v);
 
-	if (r > 1.0) {
-		ray->t = 0.f;
-		return make_float3(0.f,0.f,0.f);
-	}
+	if(r > 1.0f)
+		return make_float3(0.0f, 0.0f, 0.0f);
 
-	float phi = acosf((r!=0.f)?u/r:0.f);
+	float phi = acosf((r != 0.0f)? u/r: 0.0f);
 	float theta = asinf(r) * (fov / M_PI_F);
 
-	if (v < 0.f) phi = -phi;
+	if(v < 0.0f) phi = -phi;
 
 	return make_float3(
 		 cosf(theta),
@@ -250,23 +248,21 @@
 	);
 }
 
-__device float3 fisheye_equisolid_to_direction(float u, float v, float lens, float fov, float width, float height, Ray *ray)
+__device float3 fisheye_equisolid_to_direction(float u, float v, float lens, float fov, float width, float height)
 {
 	u = (u - 0.5f) * width;
 	v = (v - 0.5f) * height;
 
-	float rmax = 2.f * lens * sinf(fov * 0.25f);
+	float rmax = 2.0f * lens * sinf(fov * 0.25f);
 	float r = sqrt(u*u + v*v);
 
-	if (r > rmax) {
-		ray->t = 0.f;
-		return make_float3(0.f,0.f,0.f);
-	}
+	if(r > rmax)
+		return make_float3(0.0f, 0.0f, 0.0f);
 
-	float phi = acosf((r!=0.f)?u/r:0.f);
-	float theta = 2.f * asinf(r/(2.f * lens));
+	float phi = acosf((r != 0.0f)? u/r: 0.0f);
+	float theta = 2.0f * asinf(r/(2.0f * lens));
 
-	if (v < 0.f) phi = -phi;
+	if(v < 0.0f) phi = -phi;
 
 	return make_float3(
 		 cosf(theta),




More information about the Bf-blender-cvs mailing list