[Bf-blender-cvs] [fed101a7be1] master: Cycles: always perform backface culling for curve, remove option

Brecht Van Lommel noreply at git.blender.org
Mon Jun 22 13:28:15 CEST 2020


Commit: fed101a7be119f2e0c4ed64d13fd65f7a1c16118
Author: Brecht Van Lommel
Date:   Wed Jun 10 18:34:18 2020 +0200
Branches: master
https://developer.blender.org/rBfed101a7be119f2e0c4ed64d13fd65f7a1c16118

Cycles: always perform backface culling for curve, remove option

The hair BSDFs are already designed to assume this, and disabling backface
culling would break them in some cases.

Ref T73778

Depends on D8009

Maniphest Tasks: T73778

Differential Revision: https://developer.blender.org/D8010

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

M	intern/cycles/blender/addon/properties.py
M	intern/cycles/blender/addon/ui.py
M	intern/cycles/blender/blender_curves.cpp
M	intern/cycles/bvh/bvh_embree.cpp
M	intern/cycles/kernel/geom/geom_curve_intersect.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/kernel/svm/svm_closure.h
M	intern/cycles/render/curves.cpp
M	intern/cycles/render/curves.h

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

diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index 29ef1814294..89ed059af21 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -1236,11 +1236,6 @@ class CyclesCurveRenderSettings(bpy.types.PropertyGroup):
         items=enum_curve_shape,
         default='THICK',
     )
-    cull_backfacing: BoolProperty(
-        name="Cull Back-faces",
-        description="Do not test the back-face of each hair",
-        default=True,
-    )
     use_curves: BoolProperty(
         name="Use Cycles Hair Rendering",
         description="Activate Cycles hair rendering for particle system",
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index b6d19b1d4a7..9680bd04751 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -409,8 +409,6 @@ class CYCLES_RENDER_PT_hair(CyclesButtonsPanel, Panel):
         if ccscene.shape == 'RIBBONS':
             # TODO: use for embree
             col.prop(ccscene, "subdivisions", text="Curve subdivisions")
-        else:
-            col.prop(ccscene, "cull_backfacing", text="Cull back-faces")
 
 
 class CYCLES_RENDER_PT_volumes(CyclesButtonsPanel, Panel):
diff --git a/intern/cycles/blender/blender_curves.cpp b/intern/cycles/blender/blender_curves.cpp
index 43fe653fda4..a2a0392d4d5 100644
--- a/intern/cycles/blender/blender_curves.cpp
+++ b/intern/cycles/blender/blender_curves.cpp
@@ -519,7 +519,6 @@ void BlenderSync::sync_curve_settings(BL::Depsgraph &b_depsgraph)
   curve_system_manager->curve_shape = (CurveShapeType)get_enum(
       csscene, "shape", CURVE_NUM_SHAPE_TYPES, CURVE_THICK);
   curve_system_manager->subdivisions = get_int(csscene, "subdivisions");
-  curve_system_manager->use_backfacing = !get_boolean(csscene, "cull_backfacing");
 
   if (curve_system_manager->modified_mesh(prev_curve_system_manager)) {
     BL::Depsgraph::objects_iterator b_ob;
diff --git a/intern/cycles/bvh/bvh_embree.cpp b/intern/cycles/bvh/bvh_embree.cpp
index 4e064f54742..eb103b4e712 100644
--- a/intern/cycles/bvh/bvh_embree.cpp
+++ b/intern/cycles/bvh/bvh_embree.cpp
@@ -67,29 +67,9 @@ static_assert(Object::MAX_MOTION_STEPS == Geometry::MAX_MOTION_STEPS,
  * as well as filtering for volume objects happen here.
  * Cycles' own BVH does that directly inside the traversal calls.
  */
-static void rtc_filter_func(const RTCFilterFunctionNArguments *args)
-{
-  /* Current implementation in Cycles assumes only single-ray intersection queries. */
-  assert(args->N == 1);
-
-  const RTCRay *ray = (RTCRay *)args->ray;
-  const RTCHit *hit = (RTCHit *)args->hit;
-  CCLIntersectContext *ctx = ((IntersectContext *)args->context)->userRayExt;
-  KernelGlobals *kg = ctx->kg;
-
-  /* Check if there is backfacing hair to ignore. */
-  if (IS_HAIR(hit->geomID) && !(kernel_data.curve.curveflags & CURVE_KN_BACKFACING) &&
-      !(kernel_data.curve.curveflags & CURVE_KN_RIBBONS)) {
-    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) {
-      *args->valid = 0;
-      return;
-    }
-  }
-}
-
 static void rtc_filter_occluded_func(const RTCFilterFunctionNArguments *args)
 {
+  /* Current implementation in Cycles assumes only single-ray intersection queries. */
   assert(args->N == 1);
 
   const RTCRay *ray = (RTCRay *)args->ray;
@@ -97,16 +77,6 @@ static void rtc_filter_occluded_func(const RTCFilterFunctionNArguments *args)
   CCLIntersectContext *ctx = ((IntersectContext *)args->context)->userRayExt;
   KernelGlobals *kg = ctx->kg;
 
-  /* For all ray types: Check if there is backfacing hair to ignore */
-  if (IS_HAIR(hit->geomID) && !(kernel_data.curve.curveflags & CURVE_KN_BACKFACING) &&
-      !(kernel_data.curve.curveflags & CURVE_KN_RIBBONS)) {
-    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) {
-      *args->valid = 0;
-      return;
-    }
-  }
-
   switch (ctx->type) {
     case CCLIntersectContext::RAY_SHADOW_ALL: {
       /* Append the intersection to the end of the array. */
@@ -168,7 +138,7 @@ static void rtc_filter_occluded_func(const RTCFilterFunctionNArguments *args)
       }
 
       /* Ignore curves. */
-      if (hit->geomID & 1) {
+      if (IS_HAIR(hit->geomID)) {
         /* This tells Embree to continue tracing. */
         *args->valid = 0;
         break;
@@ -249,6 +219,34 @@ static void rtc_filter_occluded_func(const RTCFilterFunctionNArguments *args)
   }
 }
 
+static void rtc_filter_func_thick_curve(const RTCFilterFunctionNArguments *args)
+{
+  const RTCRay *ray = (RTCRay *)args->ray;
+  RTCHit *hit = (RTCHit *)args->hit;
+
+  /* Always ignore backfacing intersections. */
+  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) {
+    *args->valid = 0;
+    return;
+  }
+}
+
+static void rtc_filter_occluded_func_thick_curve(const RTCFilterFunctionNArguments *args)
+{
+  const RTCRay *ray = (RTCRay *)args->ray;
+  RTCHit *hit = (RTCHit *)args->hit;
+
+  /* Always ignore backfacing intersections. */
+  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) {
+    *args->valid = 0;
+    return;
+  }
+
+  rtc_filter_occluded_func(args);
+}
+
 static size_t unaccounted_mem = 0;
 
 static bool rtc_memory_monitor_func(void *userPtr, const ssize_t bytes, const bool)
@@ -652,7 +650,6 @@ void BVHEmbree::add_triangles(const Object *ob, const Mesh *mesh, int i)
   }
 
   rtcSetGeometryUserData(geom_id, (void *)prim_offset);
-  rtcSetGeometryIntersectFilterFunction(geom_id, rtc_filter_func);
   rtcSetGeometryOccludedFilterFunction(geom_id, rtc_filter_occluded_func);
   rtcSetGeometryMask(geom_id, ob->visibility_for_tracing());
 
@@ -825,8 +822,13 @@ void BVHEmbree::add_curves(const Object *ob, const Hair *hair, int i)
   update_curve_vertex_buffer(geom_id, hair);
 
   rtcSetGeometryUserData(geom_id, (void *)prim_offset);
-  rtcSetGeometryIntersectFilterFunction(geom_id, rtc_filter_func);
-  rtcSetGeometryOccludedFilterFunction(geom_id, rtc_filter_occluded_func);
+  if (use_ribbons) {
+    rtcSetGeometryOccludedFilterFunction(geom_id, rtc_filter_occluded_func);
+  }
+  else {
+    rtcSetGeometryIntersectFilterFunction(geom_id, rtc_filter_func_thick_curve);
+    rtcSetGeometryOccludedFilterFunction(geom_id, rtc_filter_occluded_func_thick_curve);
+  }
   rtcSetGeometryMask(geom_id, ob->visibility_for_tracing());
 
   rtcCommitGeometry(geom_id);
diff --git a/intern/cycles/kernel/geom/geom_curve_intersect.h b/intern/cycles/kernel/geom/geom_curve_intersect.h
index 971f194a7dd..402b4f73597 100644
--- a/intern/cycles/kernel/geom/geom_curve_intersect.h
+++ b/intern/cycles/kernel/geom/geom_curve_intersect.h
@@ -27,14 +27,14 @@ ccl_device_inline ssef transform_point_T3(const ssef t[3], const ssef &a)
 
 /* On CPU pass P and dir by reference to aligned vector. */
 ccl_device_forceinline bool curve_intersect(KernelGlobals *kg,
-                                                     Intersection *isect,
-                                                     const float3 ccl_ref P,
-                                                     const float3 ccl_ref dir,
-                                                     uint visibility,
-                                                     int object,
-                                                     int curveAddr,
-                                                     float time,
-                                                     int type)
+                                            Intersection *isect,
+                                            const float3 ccl_ref P,
+                                            const float3 ccl_ref dir,
+                                            uint visibility,
+                                            int object,
+                                            int curveAddr,
+                                            float time,
+                                            int type)
 {
   const bool is_curve_primitive = (type & PRIMITIVE_CURVE);
 
@@ -82,8 +82,7 @@ ccl_device_forceinline bool curve_intersect(KernelGlobals *kg,
     }
     else {
       int fobject = (object == OBJECT_NONE) ? kernel_tex_fetch(__prim_object, curveAddr) : object;
-      motion_curve_keys_avx(
-          kg, fobject, prim, time, ka, k0, k1, kb, &P_curve_0_1, &P_curve_2_3);
+      motion_curve_keys_avx(kg, fobject, prim, time, ka, k0, k1, kb, &P_curve_0_1, &P_curve_2_3);
     }
 #    else  /* __KERNEL_AVX2__ */
     ssef P_curve[4];
@@ -217,8 +216,7 @@ ccl_device_forceinline bool curve_intersect(KernelGlobals *kg,
 
   float r_curr = max(r_st, r_en);
 
-  if ((flags & CURVE_KN_RIBBONS) || !(flags & CURVE_KN_BACKFACING))
-    epsilon = 2 * r_curr;
+  epsilon = 2 * r_curr;
 
   /* find bounds - this is slow for cubic curves */
   float upper, lower;
@@ -439,13 +437,6 @@ ccl_device_forceinline bool curve_intersect(KernelGlobals *kg,
         if (dot(tg, dp_en) < 0)
           dp_en *= -1;
 
-        if (flags & CURVE_KN_BACKFACING &&
-            (dot(dp_st, -p_st) + t * dp_st.z < 0 || dot(dp_en, p_en) - t * dp_en.z < 0 ||
-             isect->t < t || t <= 0.0f)) {
-          correction = (-tb + rootd) * 0.5f * invcyla;
-          t = tcentre + correction;
-        }
-
         if (dot(dp_st, -p_st) + t * dp_st.z < 0 || dot(dp_en, p_en) - t * dp_en.z < 0 ||
             isect->t < t || t <= 0.0f) {
           tree++;
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 75d988365a2..4cb4bbcda43 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -1428,8 +1428,7 @@ static_assert_align(KernelBVH, 16);
 
 typedef enum CurveFlag {
   /* runtime flags */
-  CURVE_KN_BACKFACING = 1, /* backside of cylinder? */
-  CURVE_KN_RIBBONS = 2,    /* use flat curve ribbons */
+  CURVE_KN_RIBBONS = 1, /* use flat curve ribbons */
 } CurveFlag;
 
 typedef struct KernelCurves {
diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h
i

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list