[Bf-blender-cvs] [133f770] master: Code cleanup: move shadow_blocked function into separate file.

Brecht Van Lommel noreply at git.blender.org
Sat Dec 28 17:40:29 CET 2013


Commit: 133f770ab3e7a6db49562cb73cb7aa5f75cf13f8
Author: Brecht Van Lommel
Date:   Sat Dec 28 02:56:53 2013 +0100
https://developer.blender.org/rB133f770ab3e7a6db49562cb73cb7aa5f75cf13f8

Code cleanup: move shadow_blocked function into separate file.

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

M	intern/cycles/kernel/CMakeLists.txt
M	intern/cycles/kernel/kernel_path.h
A	intern/cycles/kernel/kernel_shadow.h

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

diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index 39444b9..6363799 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -46,6 +46,7 @@ set(SRC_HEADERS
 	kernel_projection.h
 	kernel_random.h
 	kernel_shader.h
+	kernel_shadow.h
 	kernel_subsurface.h
 	kernel_textures.h
 	kernel_triangle.h
diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h
index 4f3957b..903efc9 100644
--- a/intern/cycles/kernel/kernel_path.h
+++ b/intern/cycles/kernel/kernel_path.h
@@ -40,85 +40,9 @@
 #include "kernel_subsurface.h"
 #endif
 
-CCL_NAMESPACE_BEGIN
-
-ccl_device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *ray, float3 *shadow)
-{
-	*shadow = make_float3(1.0f, 1.0f, 1.0f);
-
-	if(ray->t == 0.0f)
-		return false;
-	
-	Intersection isect;
-#ifdef __HAIR__
-	bool result = scene_intersect(kg, ray, PATH_RAY_SHADOW_OPAQUE, &isect, NULL, 0.0f, 0.0f);
-#else
-	bool result = scene_intersect(kg, ray, PATH_RAY_SHADOW_OPAQUE, &isect);
-#endif
-
-#ifdef __TRANSPARENT_SHADOWS__
-	if(result && kernel_data.integrator.transparent_shadows) {
-		/* transparent shadows work in such a way to try to minimize overhead
-		 * in cases where we don't need them. after a regular shadow ray is
-		 * cast we check if the hit primitive was potentially transparent, and
-		 * only in that case start marching. this gives on extra ray cast for
-		 * the cases were we do want transparency.
-		 *
-		 * also note that for this to work correct, multi close sampling must
-		 * be used, since we don't pass a random number to shader_eval_surface */
-		if(shader_transparent_shadow(kg, &isect)) {
-			float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
-			float3 Pend = ray->P + ray->D*ray->t;
-			int bounce = state->transparent_bounce;
-
-			for(;;) {
-				if(bounce >= kernel_data.integrator.transparent_max_bounce) {
-					return true;
-				}
-				else if(bounce >= kernel_data.integrator.transparent_min_bounce) {
-					/* todo: get random number somewhere for probabilistic terminate */
-#if 0
-					float probability = average(throughput);
-					float terminate = 0.0f;
-
-					if(terminate >= probability)
-						return true;
-
-					throughput /= probability;
-#endif
-				}
-
-#ifdef __HAIR__
-				if(!scene_intersect(kg, ray, PATH_RAY_SHADOW_TRANSPARENT, &isect, NULL, 0.0f, 0.0f)) {
-#else
-				if(!scene_intersect(kg, ray, PATH_RAY_SHADOW_TRANSPARENT, &isect)) {
-#endif
-					*shadow *= throughput;
-					return false;
-				}
-
-				if(!shader_transparent_shadow(kg, &isect))
-					return true;
-
-				ShaderData sd;
-				shader_setup_from_ray(kg, &sd, &isect, ray, state->bounce+1);
-				shader_eval_surface(kg, &sd, 0.0f, PATH_RAY_SHADOW, SHADER_CONTEXT_SHADOW);
-
-				throughput *= shader_bsdf_transparency(kg, &sd);
-
-				ray->P = ray_offset(sd.P, -sd.Ng);
-				if(ray->t != FLT_MAX)
-					ray->D = normalize_len(Pend - ray->P, &ray->t);
-
-				bounce++;
-			}
-		}
-	}
-#endif
-
-	return result;
-}
+#include "kernel_shadow.h"
 
+CCL_NAMESPACE_BEGIN
 
 #if defined(__BRANCHED_PATH__) || defined(__SUBSURFACE__)
 
diff --git a/intern/cycles/kernel/kernel_shadow.h b/intern/cycles/kernel/kernel_shadow.h
new file mode 100644
index 0000000..4c1548a
--- /dev/null
+++ b/intern/cycles/kernel/kernel_shadow.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2011-2013 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+CCL_NAMESPACE_BEGIN
+
+ccl_device_inline bool shadow_blocked(KernelGlobals *kg, PathState *state, Ray *ray, float3 *shadow)
+{
+	*shadow = make_float3(1.0f, 1.0f, 1.0f);
+
+	if(ray->t == 0.0f)
+		return false;
+	
+	Intersection isect;
+#ifdef __HAIR__
+	bool result = scene_intersect(kg, ray, PATH_RAY_SHADOW_OPAQUE, &isect, NULL, 0.0f, 0.0f);
+#else
+	bool result = scene_intersect(kg, ray, PATH_RAY_SHADOW_OPAQUE, &isect);
+#endif
+
+#ifdef __TRANSPARENT_SHADOWS__
+	if(result && kernel_data.integrator.transparent_shadows) {
+		/* transparent shadows work in such a way to try to minimize overhead
+		 * in cases where we don't need them. after a regular shadow ray is
+		 * cast we check if the hit primitive was potentially transparent, and
+		 * only in that case start marching. this gives on extra ray cast for
+		 * the cases were we do want transparency.
+		 *
+		 * also note that for this to work correct, multi close sampling must
+		 * be used, since we don't pass a random number to shader_eval_surface */
+		if(shader_transparent_shadow(kg, &isect)) {
+			float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
+			float3 Pend = ray->P + ray->D*ray->t;
+			int bounce = state->transparent_bounce;
+
+			for(;;) {
+				if(bounce >= kernel_data.integrator.transparent_max_bounce) {
+					return true;
+				}
+				else if(bounce >= kernel_data.integrator.transparent_min_bounce) {
+					/* todo: get random number somewhere for probabilistic terminate */
+#if 0
+					float probability = average(throughput);
+					float terminate = 0.0f;
+
+					if(terminate >= probability)
+						return true;
+
+					throughput /= probability;
+#endif
+				}
+
+#ifdef __HAIR__
+				if(!scene_intersect(kg, ray, PATH_RAY_SHADOW_TRANSPARENT, &isect, NULL, 0.0f, 0.0f)) {
+#else
+				if(!scene_intersect(kg, ray, PATH_RAY_SHADOW_TRANSPARENT, &isect)) {
+#endif
+					*shadow *= throughput;
+					return false;
+				}
+
+				if(!shader_transparent_shadow(kg, &isect))
+					return true;
+
+				ShaderData sd;
+				shader_setup_from_ray(kg, &sd, &isect, ray, state->bounce+1);
+				shader_eval_surface(kg, &sd, 0.0f, PATH_RAY_SHADOW, SHADER_CONTEXT_SHADOW);
+
+				throughput *= shader_bsdf_transparency(kg, &sd);
+
+				ray->P = ray_offset(sd.P, -sd.Ng);
+				if(ray->t != FLT_MAX)
+					ray->D = normalize_len(Pend - ray->P, &ray->t);
+
+				bounce++;
+			}
+		}
+	}
+#endif
+
+	return result;
+}
+
+CCL_NAMESPACE_END
+




More information about the Bf-blender-cvs mailing list