[Bf-blender-cvs] [aba8be7c3e6] temp-trimesh-sculpt: merge

Joseph Eagar noreply at git.blender.org
Wed Oct 14 04:05:39 CEST 2020


Commit: aba8be7c3e6e5cd9c5ae915ca8a01c8076458c33
Author: Joseph Eagar
Date:   Sun Feb 16 23:51:32 2020 -0800
Branches: temp-trimesh-sculpt
https://developer.blender.org/rBaba8be7c3e6e5cd9c5ae915ca8a01c8076458c33

merge

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

M	intern/cycles/blender/addon/properties.py
M	intern/cycles/blender/addon/ui.py
M	intern/cycles/blender/blender_sync.cpp
M	intern/cycles/kernel/kernel_path_surface.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/render/integrator.cpp
M	intern/cycles/render/integrator.h

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

diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index eafe37618b3..2f7a664fed4 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -264,6 +264,16 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
         min=0, max=(1 << 24),
         default=32,
     )
+    preview_pause: BoolProperty(
+        name="Pause Preview",
+        description="Pause all viewport preview renders",
+        default=False,
+    )
+    use_light_bounce: BoolProperty(
+        name="Cache Light Bounce",
+        description="Cache first light bounce",
+        default=False,
+    )
     aa_samples: IntProperty(
         name="AA Samples",
         description="Number of antialiasing samples to render for each pixel",
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index f23d141e3da..61a4c33836b 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -242,13 +242,13 @@ class CYCLES_RENDER_PT_sampling_advanced(CyclesButtonsPanel, Panel):
 
         scene = context.scene
         cscene = scene.cycles
-
+        
         row = layout.row(align=True)
         row.prop(cscene, "seed")
         row.prop(cscene, "use_animated_seed", text="", icon='TIME')
 
+        layout.prop(cscene, "use_light_bounce")
         layout.prop(cscene, "sampling_pattern", text="Pattern")
-
         layout.prop(cscene, "use_square_samples")
 
         layout.separator()
diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index 0412654d3bd..1df5b83c567 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -245,6 +245,8 @@ void BlenderSync::sync_integrator()
   Integrator *integrator = scene->integrator;
   Integrator previntegrator = *integrator;
 
+  integrator->use_light_bounce = get_boolean(cscene, "use_light_bounce");
+
   integrator->min_bounce = get_int(cscene, "min_light_bounces");
   integrator->max_bounce = get_int(cscene, "max_bounces");
 
diff --git a/intern/cycles/kernel/kernel_path_surface.h b/intern/cycles/kernel/kernel_path_surface.h
index ba48c0bdfc4..47679549f6f 100644
--- a/intern/cycles/kernel/kernel_path_surface.h
+++ b/intern/cycles/kernel/kernel_path_surface.h
@@ -266,6 +266,212 @@ ccl_device_inline void kernel_path_surface_connect_light(KernelGlobals *kg,
 #endif
 }
 
+constexpr size_t HCLEN = 1024*16;
+
+typedef struct _hitcache {
+  Ray rays[HCLEN];
+  int cur, used;
+} _hitcache;
+
+static _hitcache hitcache[2] = { 0, };
+
+static void hitcache_add(Ray ray, int thread) {
+  hitcache[thread].rays[hitcache[thread].cur] = ray;
+  hitcache[thread].cur = (hitcache[thread].cur + 1) % HCLEN;
+
+  if (hitcache[thread].used < HCLEN) {
+    hitcache[thread].used++;
+  }
+}
+
+static int hitcache_get(KernelGlobals *kg, PathState* state, int thread) {
+  if (hitcache[thread].used == 0)
+    return -1;
+
+  //is path_state_rng_1D only giving numbers from 0.5-1.0?
+  float r = path_state_rng_1D(kg, state, PRNG_LIGHT_U);
+  r = r > 0.5 ? (r - 0.5) * 2.0 : r;
+
+  int idx = (int)(r * ((float)hitcache[thread].used) * 0.9999);
+
+  return idx;
+}
+
+//bastardized one-bounce bidirection tracing
+ccl_device_inline void kernel_path_surface_connect_light_indirect(KernelGlobals* kg,
+  ShaderData* sd,
+  ShaderData* emission_sd,
+  float3 throughput,
+  ccl_addr_space PathState* state,
+  PathRadiance* L)
+{
+  PROFILING_INIT(kg, PROFILING_CONNECT_LIGHT);
+
+#ifdef __EMISSION__
+  if (!(kernel_data.integrator.use_direct_light && (sd->flag & SD_BSDF_HAS_EVAL)))
+    return;
+
+  /* sample illumination from lights to find path contribution */
+  float light_u, light_v;
+  path_state_rng_2D(kg, state, PRNG_LIGHT_U, &light_u, &light_v);
+
+  Ray light_ray;
+  BsdfEval L_light;
+  PathRadiance L2 = { 0, };
+  bool is_lamp;
+
+#  ifdef __OBJECT_MOTION__
+  light_ray.time = sd->time;
+#  endif
+
+  LightSample ls;
+  if (light_sample(kg, light_u, light_v, sd->time, sd->P, state->bounce, &ls)) {
+    float terminate = path_state_rng_light_termination(kg, state);
+
+    if (1) { //direct_emission(kg, sd, emission_sd, &ls, state, &light_ray, &L_light, &is_lamp, terminate) || true) {
+      Ray ray;
+      float3 omega;
+      float3 Ng;
+      float pdf = 0.0;
+
+      /*trace a ray*/
+      if (ls.type == LIGHT_DISTANT) {
+        const ccl_global KernelLight* klight = &kernel_tex_fetch(__lights, ls.lamp);
+
+        ray.P = make_float3(klight->co[0], klight->co[1], klight->co[2]);
+        Ng = ls.P;
+      } else if (ls.type == LIGHT_POINT) {
+        Ng = -ls.D;
+        ray.P = ls.P + Ng * 0.00015f;
+      } else {
+        Ng = ls.Ng;
+        ray.P = ls.P + Ng * 0.00015f;
+      }
+
+      ray.t = ls.t;
+
+      sample_cos_hemisphere(Ng, light_u, light_v, &omega, &pdf);
+
+      omega = normalize(omega);
+      ray.D = omega;
+
+      float prob = path_state_rng_1D(kg, state, PRNG_LIGHT_U);
+      bool has_cache = prob > 0.75;
+
+      if (has_cache) {
+        int i = hitcache_get(kg, state, 0);
+
+        if (i >= 0) {
+          ray = hitcache[0].rays[i];
+        }
+      }
+
+      /* trace shadow ray */
+      float3 shadow = make_float3(1.0f, 1.0f, 1.0f);
+
+      if (1) { //!shadow_blocked(kg, sd, emission_sd, state, &ray, &shadow)) {
+        Intersection isect, isect2;
+        PathState _state2 = *state, *state2 = &_state2;
+        ShaderData sd2;
+        float3 P, Ng;
+        BsdfEval bsdf_eval;
+        Ray ray2;
+
+        //bool hit = scene_intersect(kg, *ray, visibility, isect);
+        //bool hit = kernel_path_scene_intersect(kg, state2, &ray, &isect, &L2);
+        bool hit = scene_intersect(kg, ray, PATH_RAY_ALL_VISIBILITY, &isect);
+        if (!hit) {
+          return;
+        }
+
+        P = ray.P + ray.D * isect.t;
+        Ng = normalize(isect.Ng);
+
+        float d1 = dot(Ng, -ray.D);
+        d1 = d1 < 0.0 ? 0.0 : d1;
+
+        ray2.P = sd->P + sd->Ng * 0.00015;
+
+        float dis = len(P - ray2.P) * 0.99999;
+
+        ray2.D = normalize(P - ray2.P);
+        ray2.t = dis;
+
+        float3 N2 = ray2.D;
+        
+        bool hit2 = scene_intersect(kg, ray2, PATH_RAY_ALL_VISIBILITY, &isect2);
+        bool bad = false;
+
+        if (hit2) {
+          bad = (isect.object != isect2.object || isect.prim != isect2.prim);
+        } else {
+          //?
+        }
+
+        if (bad) {
+          return;
+        }
+
+        shader_setup_from_ray(kg, &sd2, &isect, &ray);
+
+        /* Evaluate shader. */
+        shader_eval_surface(kg, &sd2, state2, state2->flag);
+        shader_prepare_closures(&sd2, state2);
+
+        float d2 = dot(sd->N, N2);
+
+        d2 = d2 < 0.0 ? 0.0 : d2;
+
+        d1 = d2 = 1.0f;
+        float3 throughput2 = throughput * d2 * d1 * make_float3(1.0f, 1.0f, 1.0f) / (1.0f + dis * dis);
+
+        if (1) { //direct_emission(kg, &sd2, emission_sd, &ls, state2, &light_ray, &L_light, &is_lamp, terminate)) {
+          differential3 dD = differential3_zero();
+
+          /* evaluate light closure */
+          float3 light_eval = direct_emissive_eval(
+              kg, emission_sd, &ls, state, -ls.D, dD, ls.t, sd->time);
+
+          throughput2 *= light_eval / ls.pdf; //L_light.diffuse;
+        }
+
+        if (1) {
+          /* sample BSDF */
+          float bsdf_pdf;
+          BsdfEval bsdf_eval;
+          float3 bsdf_omega_in;
+          differential3 bsdf_domega_in;
+          float bsdf_u, bsdf_v;
+          path_state_rng_2D(kg, state2, PRNG_BSDF_U, &bsdf_u, &bsdf_v);
+          int label;
+
+          label = shader_bsdf_sample(
+            kg, sd, bsdf_u, bsdf_v, &bsdf_eval, &bsdf_omega_in, &bsdf_domega_in, &bsdf_pdf);
+
+          if (!(bsdf_pdf == 0.0f || bsdf_eval_is_zero(&bsdf_eval))) {
+            //throughput2 *= bsdf_eval.sum_no_mis;
+            throughput2 *= bsdf_eval.diffuse;
+            //path_radiance_accum_light(L, state, throughput2, &bsdf_eval, shadow, 1.0f, is_lamp);
+            /* modify throughput */
+            //path_radiance_bsdf_bounce(kg, L, &throughput, &bsdf_eval, bsdf_pdf, state->bounce, label);
+          }
+        }
+
+        //path_radiance_accum_light(&L2, state2, throughput, &L_light, shadow, 1.0f, is_lamp);
+
+        
+        //path_radiance_accum_light(L, state, throughput2, &L_light, shadow, 1.0f, is_lamp);
+        L->emission += throughput2;
+
+        if (!has_cache) {
+          hitcache_add(ray, 0);
+        }
+      }
+    }
+  }
+#endif
+}
+
 /* path tracing: bounce off or through surface to with new direction stored in ray */
 ccl_device bool kernel_path_surface_bounce(KernelGlobals *kg,
                                            ShaderData *sd,
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index bf34450df4b..0ffa32534e0 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -1365,7 +1365,7 @@ typedef struct KernelIntegrator {
 
   int max_closures;
 
-  int pad1;
+  int use_light_bounce;
 } KernelIntegrator;
 static_assert_align(KernelIntegrator, 16);
 
diff --git a/intern/cycles/render/integrator.cpp b/intern/cycles/render/integrator.cpp
index 530c32106b7..8f97ae2b788 100644
--- a/intern/cycles/render/integrator.cpp
+++ b/intern/cycles/render/integrator.cpp
@@ -56,6 +56,8 @@ NODE_DEFINE(Integrator)
   SOCKET_FLOAT(sample_clamp_indirect, "Sample Clamp Indirect", 0.0f);
   SOCKET_BOOLEAN(motion_blur, "Motion Blur", false);
 
+  SOCKET_BOOLEAN(use_light_bounce, "Use Light Bounce", false);
+
   SOCKET_INT(aa_samples, "AA Samples", 0);
   SOCKET_INT(diffuse_samples, "Diffuse Samples", 1);
   SOCKET_INT(glossy_samples, "Glossy Samples", 1);
@@ -174,6 +176,7 @@ void Integrator::device_update(Device *device, DeviceScene *dscene, Scene *scene
 
   kintegrator->sampling_pattern = sampling_pattern;
   kintegrator->aa_samples = aa_samples;
+  kintegrator->use_light_bounce = use_light_bounce;
 
   if (light_sampling_threshold > 0.0f) {
     kintegrator->light_inv_rr_threshold = 1.0f / light_sampling_threshold;
diff --git a/intern/cycles/render/integrator.h b/intern/cycles/render/integrator.h
index 32d84c27072..0f60f3746b8 100644
--- a/int

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list