[Bf-blender-cvs] [a8c87ba] master: Cycles: Cleanup, spherical_stereo_direction will return normalized direction

Sergey Sharybin noreply at git.blender.org
Sat Mar 12 11:15:53 CET 2016


Commit: a8c87bad22e618fab19521b4e2d162d19946db98
Author: Sergey Sharybin
Date:   Fri Mar 11 21:22:19 2016 +0500
Branches: master
https://developer.blender.org/rBa8c87bad22e618fab19521b4e2d162d19946db98

Cycles: Cleanup, spherical_stereo_direction will return normalized direction

Previously each call of this function was followed by a normaliztion, now it
is done in the function itself with an according note around the function.

===================================================================

M	intern/cycles/kernel/kernel_camera.h
M	intern/cycles/kernel/kernel_projection.h

===================================================================

diff --git a/intern/cycles/kernel/kernel_camera.h b/intern/cycles/kernel/kernel_camera.h
index 6b8f18e3..db2f45c 100644
--- a/intern/cycles/kernel/kernel_camera.h
+++ b/intern/cycles/kernel/kernel_camera.h
@@ -109,7 +109,6 @@ ccl_device void camera_sample_perspective(KernelGlobals *kg, float raster_x, flo
 	float3 tD = transform_direction(&cameratoworld, ray->D);
 	ray->P = spherical_stereo_position(kg, tD, tP);
 	ray->D = spherical_stereo_direction(kg, tD, tP, ray->P);
-	ray->D = normalize(ray->D);
 
 #ifdef __RAY_DIFFERENTIALS__
 	/* ray differential */
@@ -117,18 +116,18 @@ ccl_device void camera_sample_perspective(KernelGlobals *kg, float raster_x, flo
 
 	tD = transform_direction(&cameratoworld, Pcamera);
 	float3 Pdiff = spherical_stereo_position(kg, tD, Pcamera);
-	float3 Ddiff = normalize(spherical_stereo_direction(kg, tD, Pcamera, Pdiff));
+	float3 Ddiff = spherical_stereo_direction(kg, tD, Pcamera, Pdiff);
 
 	tP = transform_perspective(&rastertocamera, make_float3(raster_x + 1.0f, raster_y, 0.0f));
 	tD = transform_direction(&cameratoworld, tP);
 	Pcamera = spherical_stereo_position(kg, tD, tP);
-	ray->dD.dx = normalize(spherical_stereo_direction(kg, tD, tP, Pcamera)) - Ddiff;
+	ray->dD.dx = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff;
 	ray->dP.dx = Pcamera - Pdiff;
 
 	tP = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y + 1.0f, 0.0f));
 	tD = transform_direction(&cameratoworld, tP);
 	Pcamera = spherical_stereo_position(kg, tD, tP);
-	ray->dD.dy = normalize(spherical_stereo_direction(kg, tD, tP, Pcamera)) - Ddiff;
+	ray->dD.dy = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff;
 	/* dP.dy is zero, since the omnidirectional panorama only shift the eyes horizontally */
 #endif
 
@@ -276,7 +275,6 @@ ccl_device void camera_sample_panorama(KernelGlobals *kg, float raster_x, float
 	float3 tD = transform_direction(&cameratoworld, ray->D);
 	ray->P = spherical_stereo_position(kg, tD, tP);
 	ray->D = spherical_stereo_direction(kg, tD, tP, ray->P);
-	ray->D = normalize(ray->D);
 
 #ifdef __RAY_DIFFERENTIALS__
 	/* ray differential */
@@ -285,18 +283,18 @@ ccl_device void camera_sample_panorama(KernelGlobals *kg, float raster_x, float
 	tP = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y, 0.0f));
 	tD = transform_direction(&cameratoworld, panorama_to_direction(kg, tP.x, tP.y));
 	float3 Pdiff = spherical_stereo_position(kg, tD, tP);
-	float3 Ddiff = normalize(spherical_stereo_direction(kg, tD, tP, Pdiff));
+	float3 Ddiff = spherical_stereo_direction(kg, tD, tP, Pdiff);
 
 	tP = transform_perspective(&rastertocamera, make_float3(raster_x + 1.0f, raster_y, 0.0f));
 	tD = transform_direction(&cameratoworld, panorama_to_direction(kg, tP.x, tP.y));
 	Pcamera = spherical_stereo_position(kg, tD, tP);
-	ray->dD.dx = normalize(spherical_stereo_direction(kg, tD, tP, Pcamera)) - Ddiff;
+	ray->dD.dx = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff;
 	ray->dP.dx = Pcamera - Pdiff;
 
 	tP = transform_perspective(&rastertocamera, make_float3(raster_x, raster_y + 1.0f, 0.0f));
 	tD = transform_direction(&cameratoworld, panorama_to_direction(kg, tP.x, tP.y));
 	Pcamera = spherical_stereo_position(kg, tD, tP);
-	ray->dD.dy = normalize(spherical_stereo_direction(kg, tD, tP, Pcamera)) - Ddiff;
+	ray->dD.dy = spherical_stereo_direction(kg, tD, tP, Pcamera) - Ddiff;
 	/* dP.dy is zero, since the omnidirectional panorama only shift the eyes horizontally */
 #endif
 }
diff --git a/intern/cycles/kernel/kernel_projection.h b/intern/cycles/kernel/kernel_projection.h
index aedcbdd..e561cfa 100644
--- a/intern/cycles/kernel/kernel_projection.h
+++ b/intern/cycles/kernel/kernel_projection.h
@@ -241,20 +241,22 @@ ccl_device float3 spherical_stereo_position(KernelGlobals *kg,
 	return pos + (side * interocular_offset);
 }
 
+/* NOTE: Ensures direction is normalized. */
 ccl_device float3 spherical_stereo_direction(KernelGlobals *kg,
                                              float3 dir,
                                              float3 pos,
                                              float3 newpos)
 {
+	const float3 normalized_dir = normalize(dir);
 	/* Interocular offset of zero means either no stereo, or stereo without
 	 * spherical stereo.
 	 */
 	if(kernel_data.cam.interocular_offset == 0.0f) {
-		return dir;
+		return normalized_dir;
 	}
 
-	float3 screenpos = pos + (normalize(dir) * kernel_data.cam.convergence_distance);
-	return screenpos - newpos;
+	float3 screenpos = pos + (normalized_dir * kernel_data.cam.convergence_distance);
+	return normalize(screenpos - newpos);
 }
 
 CCL_NAMESPACE_END




More information about the Bf-blender-cvs mailing list