[Bf-blender-cvs] [97d4e3f0e73] cycles_embree: Cycles: Fixes for transparent shadows and SSS when using Embree.

Stefan Werner noreply at git.blender.org
Tue Aug 14 14:51:23 CEST 2018


Commit: 97d4e3f0e739423c542cd33d2a5de2ede32623b9
Author: Stefan Werner
Date:   Tue Aug 14 14:51:12 2018 +0200
Branches: cycles_embree
https://developer.blender.org/rB97d4e3f0e739423c542cd33d2a5de2ede32623b9

Cycles: Fixes for transparent shadows and SSS when using Embree.

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

M	intern/cycles/bvh/bvh_embree.cpp
M	intern/cycles/kernel/bvh/bvh.h

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

diff --git a/intern/cycles/bvh/bvh_embree.cpp b/intern/cycles/bvh/bvh_embree.cpp
index 75f69f67363..415f2e56559 100644
--- a/intern/cycles/bvh/bvh_embree.cpp
+++ b/intern/cycles/bvh/bvh_embree.cpp
@@ -59,7 +59,7 @@ void rtc_filter_func(const RTCFilterFunctionNArguments* args)
 	   && !(kernel_data.curve.curveflags & CURVE_KN_BACKFACING)
 	   && !(kernel_data.curve.curveflags & CURVE_KN_RIBBONS) && hit->geomID & 1) {
 		if(dot(make_float3(ray->dir_x, ray->dir_y, ray->dir_z), make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z)) > 0.0f) {
-			hit->geomID = RTC_INVALID_GEOMETRY_ID;
+			*args->valid = 0;
 			return;
 		}
 	}
@@ -70,9 +70,20 @@ void rtc_filter_func(const RTCFilterFunctionNArguments* args)
 	else if(ctx->type == CCLIntersectContext::RAY_SHADOW_ALL) {
 		/* Append the intersection to the end of the array. */
 		if(ctx->num_hits < ctx->max_hits) {
+			Intersection current_isect;
+			kernel_embree_convert_hit(kg, ray, hit, &current_isect);
+			for(size_t i = 0; i < ctx->max_hits; ++i) {
+				if(current_isect.object == ctx->isect_s[i].object &&
+				   current_isect.prim == ctx->isect_s[i].prim &&
+				   current_isect.t == ctx->isect_s[i].t) {
+					/* This intersection was already recorded, skip it. */
+					*args->valid = 0;
+					return;
+				}
+			}
 			Intersection *isect = &ctx->isect_s[ctx->num_hits];
 			ctx->num_hits++;
-			kernel_embree_convert_hit(kg, ray, hit, isect);
+			*isect = current_isect;
 			int prim = kernel_tex_fetch(__prim_index, isect->prim);
 			int shader = 0;
 			if(kernel_tex_fetch(__prim_type, isect->prim) & PRIMITIVE_ALL_TRIANGLE) {
@@ -86,10 +97,7 @@ void rtc_filter_func(const RTCFilterFunctionNArguments* args)
 			/* If no transparent shadows, all light is blocked. */
 			if(flag & (SD_HAS_TRANSPARENT_SHADOW)) {
 				/* This tells Embree to continue tracing. */
-				hit->geomID = RTC_INVALID_GEOMETRY_ID;
-			}
-			else {
-				ctx->num_hits = ctx->max_hits+1;
+				*args->valid = 0;
 			}
 		}
 		else {
@@ -101,13 +109,13 @@ void rtc_filter_func(const RTCFilterFunctionNArguments* args)
 	}
 	else if(ctx->type == CCLIntersectContext::RAY_SSS) {
 		/* No intersection information requested, just return a hit. */
-		if(ctx->ss_isect->num_hits == 0) {
+		if(ctx->max_hits == 0) {
 			return;
 		}
 		/* Only accept hits from the same object and triangles. */
 		if(hit->instID[0]/2 != ctx->sss_object_id || hit->geomID & 1) {
 			/* This tells Embree to continue tracing. */
-			hit->geomID = RTC_INVALID_GEOMETRY_ID;
+			*args->valid = 0;
 			return;
 		}
 
@@ -115,7 +123,7 @@ void rtc_filter_func(const RTCFilterFunctionNArguments* args)
 		for(int i = min(ctx->max_hits, ctx->ss_isect->num_hits) - 1; i >= 0; --i) {
 			if(ctx->ss_isect->hits[i].t == ray->tfar) {
 				/* This tells Embree to continue tracing. */
-				hit->geomID = RTC_INVALID_GEOMETRY_ID;
+				*args->valid = 0;
 				return;
 			}
 		}
@@ -133,7 +141,7 @@ void rtc_filter_func(const RTCFilterFunctionNArguments* args)
 
 			if(hit_idx >= ctx->max_hits) {
 				/* This tells Embree to continue tracing. */
-				hit->geomID = RTC_INVALID_GEOMETRY_ID;
+				*args->valid = 0;
 				return;
 			}
 		}
@@ -144,15 +152,26 @@ void rtc_filter_func(const RTCFilterFunctionNArguments* args)
 		ctx->ss_isect->Ng[hit_idx].z = hit->Ng_z;
 		ctx->ss_isect->Ng[hit_idx] = normalize(ctx->ss_isect->Ng[hit_idx]);
 		/* this tells Embree to continue tracing */
-		hit->geomID = RTC_INVALID_GEOMETRY_ID;
+		*args->valid = 0;
 		return;
 	}
 	else if(ctx->type == CCLIntersectContext::RAY_VOLUME_ALL) {
 		/* Append the intersection to the end of the array. */
 		if(ctx->num_hits < ctx->max_hits) {
+			Intersection current_isect;
+			kernel_embree_convert_hit(kg, ray, hit, &current_isect);
+			for(size_t i = 0; i < ctx->max_hits; ++i) {
+				if(current_isect.object == ctx->isect_s[i].object &&
+				   current_isect.prim == ctx->isect_s[i].prim &&
+				   current_isect.t == ctx->isect_s[i].t) {
+					/* This intersection was already recorded, skip it. */
+					*args->valid = 0;
+					return;
+				}
+			}
 			Intersection *isect = &ctx->isect_s[ctx->num_hits];
 			ctx->num_hits++;
-			kernel_embree_convert_hit(kg, ray, hit, isect);
+			*isect = current_isect;
 			/* Only primitives from volume object. */
 			uint tri_object = (isect->object == OBJECT_NONE) ?kernel_tex_fetch(__prim_object, isect->prim) : isect->object;
 			int object_flag = kernel_tex_fetch(__object_flag, tri_object);
@@ -160,7 +179,7 @@ void rtc_filter_func(const RTCFilterFunctionNArguments* args)
 				ctx->num_hits--;
 			}
 			/* This tells Embree to continue tracing. */
-			hit->geomID = RTC_INVALID_GEOMETRY_ID;
+			*args->valid = 0;
 			return;
 		}
 		return;
diff --git a/intern/cycles/kernel/bvh/bvh.h b/intern/cycles/kernel/bvh/bvh.h
index 54865062a84..14e791d2239 100644
--- a/intern/cycles/kernel/bvh/bvh.h
+++ b/intern/cycles/kernel/bvh/bvh.h
@@ -242,7 +242,7 @@ ccl_device_intersect bool scene_intersect_local(KernelGlobals *kg,
 		kernel_embree_setup_ray(ray, rtc_ray, PATH_RAY_ALL_VISIBILITY);
 		rtcOccluded1(kernel_data.bvh.scene, &rtc_ctx.context, &rtc_ray);
 
-		return rtc_ray.tfar < 0.0f;
+		return local_isect->num_hits > 0;
 	}
 #endif /* __EMBREE__ */
 #ifdef __OBJECT_MOTION__
@@ -286,12 +286,8 @@ ccl_device_intersect bool scene_intersect_shadow_all(KernelGlobals *kg,
 		if(ctx.num_hits > max_hits) {
 			return true;
 		}
-		if(ctx.num_hits > 0) {
-			*num_hits = ctx.num_hits;
-			return (rtc_ray.tfar < 0.0f);
-		}
-		*num_hits = 0;
-		return false;
+		*num_hits = ctx.num_hits;
+		return rtc_ray.tfar == -INFINITY;
 	}
 #endif
 #  ifdef __OBJECT_MOTION__
@@ -391,7 +387,7 @@ ccl_device_intersect uint scene_intersect_volume_all(KernelGlobals *kg,
 		RTCRay rtc_ray;
 		kernel_embree_setup_ray(*ray, rtc_ray, visibility);
 		rtcOccluded1(kernel_data.bvh.scene, &rtc_ctx.context, &rtc_ray);
-		return rtc_ray.tfar < 0.0f;
+		return rtc_ray.tfar == -INFINITY;
 	}
 #endif
 #  ifdef __OBJECT_MOTION__



More information about the Bf-blender-cvs mailing list