Commit: f5d27d6a7cb68e1ccddf34090ee23f97db200ff6
Author: Lukas Stockner
Date: Sun Feb 12 05:18:00 2017 +0100
Branches: temp-cycles-denoising
https://developer.blender.org/rBf5d27d6a7cb68e1ccddf34090ee23f97db200ff6
Cycles Denoising: Use Shadowcatcher code for the denoising visibility feature
===================================================================
M intern/cycles/kernel/kernel_accumulate.h
M intern/cycles/kernel/kernel_passes.h
M intern/cycles/kernel/kernel_path.h
M intern/cycles/kernel/kernel_path_branched.h
M intern/cycles/kernel/kernel_path_state.h
M intern/cycles/kernel/kernel_path_surface.h
M intern/cycles/kernel/kernel_path_volume.h
M intern/cycles/kernel/kernel_types.h
===================================================================
diff --git a/intern/cycles/kernel/kernel_accumulate.h
b/intern/cycles/kernel/kernel_accumulate.h
index 0f19b7f8ab..880e568248 100644
--- a/intern/cycles/kernel/kernel_accumulate.h
+++ b/intern/cycles/kernel/kernel_accumulate.h
@@ -277,15 +277,15 @@ ccl_device_inline void
path_radiance_accum_emission(PathRadiance *L, float3 thro
}
ccl_device_inline void path_radiance_accum_ao(PathRadiance *L,
+ PathState *state,
float3 throughput,
float3 alpha,
float3 bsdf,
- float3 ao,
- int bounce)
+ float3 ao)
{
#ifdef __PASSES__
if(L->use_light_pass) {
- if(bounce == 0) {
+ if(state->bounce == 0) {
/* directly visible lighting */
L->direct_diffuse += throughput*bsdf*ao;
L->ao += alpha*throughput*ao;
@@ -302,31 +302,43 @@ ccl_device_inline void
path_radiance_accum_ao(PathRadiance *L,
}
#ifdef __SHADOW_TRICKS__
- float3 light = throughput * bsdf;
- L->path_total += light;
- L->path_total_shaded += ao * light;
+ if(state->flag & PATH_RAY_STORE_SHADOW_INFO) {
+ float3 light = throughput * bsdf;
+ L->path_total += light;
+ L->path_total_shaded += ao * light;
+ }
#endif
}
ccl_device_inline void path_radiance_accum_total_ao(
PathRadiance *L,
+ PathState *state,
float3 throughput,
float3 bsdf)
{
#ifdef __SHADOW_TRICKS__
- L->path_total += throughput * bsdf;
+ if(state->flag & PATH_RAY_STORE_SHADOW_INFO) {
+ L->path_total += throughput * bsdf;
+ }
#else
(void) L;
+ (void) state;
(void) throughput;
(void) bsdf;
#endif
}
-ccl_device_inline void path_radiance_accum_light(PathRadiance *L, float3
throughput, BsdfEval *bsdf_eval, float3 shadow, float shadow_fac, int bounce,
bool is_lamp)
+ccl_device_inline void path_radiance_accum_light(PathRadiance *L,
+ PathState *state,
+ float3 throughput,
+ BsdfEval *bsdf_eval,
+ float3 shadow,
+ float shadow_fac,
+ bool is_lamp)
{
#ifdef __PASSES__
if(L->use_light_pass) {
- if(bounce == 0) {
+ if(state->bounce == 0) {
/* directly visible lighting */
L->direct_diffuse +=
throughput*bsdf_eval->diffuse*shadow;
L->direct_glossy += throughput*bsdf_eval->glossy*shadow;
@@ -352,21 +364,27 @@ ccl_device_inline void
path_radiance_accum_light(PathRadiance *L, float3 through
}
#ifdef __SHADOW_TRICKS__
- float3 light = throughput * bsdf_eval->sum_no_mis;
- L->path_total += light;
- L->path_total_shaded += shadow * light;
+ if(state->flag & PATH_RAY_STORE_SHADOW_INFO) {
+ float3 light = throughput * bsdf_eval->sum_no_mis;
+ L->path_total += light;
+ L->path_total_shaded += shadow * light;
+ }
#endif
}
ccl_device_inline void path_radiance_accum_total_light(
PathRadiance *L,
+ PathState *state,
float3 throughput,
const BsdfEval *bsdf_eval)
{
#ifdef __SHADOW_TRICKS__
- L->path_total += throughput * bsdf_eval->sum_no_mis;
+ if(state->flag & PATH_RAY_STORE_SHADOW_INFO) {
+ L->path_total += throughput * bsdf_eval->sum_no_mis;
+ }
#else
(void) L;
+ (void) state;
(void) throughput;
(void) bsdf_eval;
#endif
@@ -394,12 +412,11 @@ ccl_device_inline void
path_radiance_accum_background(PathRadiance *L,
}
#ifdef __SHADOW_TRICKS__
- if(state->flag & PATH_RAY_SHADOW_CATCHER_ONLY) {
- L->path_total += throughput * value;
- L->path_total_shaded += throughput * value;
- }
- else {
+ if(state->flag & PATH_RAY_STORE_SHADOW_INFO) {
L->path_total += throughput * value;
+ if(state->flag & PATH_RAY_SHADOW_CATCHER_ONLY) {
+ L->path_total_shaded += throughput * value;
+ }
}
#endif
}
diff --git a/intern/cycles/kernel/kernel_passes.h
b/intern/cycles/kernel/kernel_passes.h
index 7afc124544..d6bfdeb6ff 100644
--- a/intern/cycles/kernel/kernel_passes.h
+++ b/intern/cycles/kernel/kernel_passes.h
@@ -121,7 +121,7 @@ ccl_device_inline void kernel_write_pass_float4(ccl_global
float *buffer, int sa
}
ccl_device_inline void kernel_write_denoising_shadow(KernelGlobals *kg,
ccl_global float *buffer,
- int sample, float2 shadow_info)
+ int sample, float path_total, float path_total_shaded)
{
if(kernel_data.film.pass_denoising_data == 0)
return;
@@ -130,16 +130,16 @@ ccl_device_inline void
kernel_write_denoising_shadow(KernelGlobals *kg, ccl_glob
buffer += kernel_data.film.pass_denoising_data + 14;
if(sample < 2) {
- buffer[0] = shadow_info.x; /* Unoccluded lighting */
- buffer[1] = shadow_info.y; /* Occluded lighting */
+ buffer[0] = path_total;
+ buffer[1] = path_total_shaded;
buffer[2] = 0.0f; /* Sample variance */
}
else {
float old_shadowing = buffer[1] / max(buffer[0], 1e-7f);
- buffer[0] += shadow_info.x;
- buffer[1] += shadow_info.y;
+ buffer[0] += path_total;
+ buffer[1] += path_total_shaded;
float new_shadowing = buffer[1] / max(buffer[0], 1e-7f);
- float cur_shadowing = shadow_info.y / max(shadow_info.x, 1e-7f);
+ float cur_shadowing = path_total_shaded / max(path_total,
1e-7f);
buffer[2] += (cur_shadowing - old_shadowing) * (cur_shadowing -
new_shadowing);
}
}
@@ -376,6 +376,8 @@ ccl_device_inline void kernel_write_result(KernelGlobals
*kg, ccl_global float *
kernel_write_light_passes(kg, buffer, L, sample);
+ kernel_write_denoising_shadow(kg, buffer, sample,
average(L->path_total), average(L->path_total_shaded));
+
if(kernel_data.film.pass_denoising_data) {
if(kernel_data.film.pass_denoising_clean) {
float3 noisy, clean;
diff --git a/intern/cycles/kernel/kernel_path.h
b/intern/cycles/kernel/kernel_path.h
index eddd0f5017..bafe5cdfcd 100644
--- a/intern/cycles/kernel/kernel_path.h
+++ b/intern/cycles/kernel/kernel_path.h
@@ -89,10 +89,10 @@ ccl_device_noinline void kernel_path_ao(KernelGlobals *kg,
light_ray.dD = differential3_zero();
if(!shadow_blocked(kg, emission_sd, state, &light_ray,
&ao_shadow)) {
- path_radiance_accum_ao(L, throughput, ao_alpha,
ao_bsdf, ao_shadow, state->bounce);
+ path_radiance_accum_ao(L, state, throughput, ao_alpha,
ao_bsdf, ao_shadow);
}
else {
- path_radiance_accum_total_ao(L, throughput, ao_bsdf);
+ path_radiance_accum_total_ao(L, state, throughput,
ao_bsdf);
}
}
}
@@ -914,6 +914,10 @@ ccl_device_inline float
kernel_path_integrate(KernelGlobals *kg,
/* direct lighting */
kernel_path_surface_connect_light(kg, rng, &sd, &emission_sd,
throughput, &state, L);
+ if(write_denoising_shadow && !(state.flag &
PATH_RAY_SHADOW_CATCHER)) {
+ state.flag &= ~PATH_RAY_STORE_SHADOW_INFO;
+ }
+
/* compute direct lighting and next bounce */
if(!kernel_path_surface_bounce(kg, rng, &sd, &throughput,
&state, L, &ray))
break;
diff --git a/intern/cycles/kernel/kernel_path_branched.h
b/intern/cycles/kernel/kernel_path_branched.h
index e6e1f998e0..fd95a20e12 100644
--- a/intern/cycles/kernel/kernel_path_branched.h
+++ b/intern/cycles/kernel/kernel_path_branched.h
@@ -56,10 +56,10 @@ ccl_device_inline void
kernel_branched_path_ao(KernelGlobals *kg,
light_ray.dD = differential3_zero();
if(!shadow_blocked(kg, emission_sd, state, &light_ray,
&ao_shadow)) {
- path_radiance_accum_ao(L,
throughput*num_samples_inv, ao_alpha, ao_bsdf, ao_shadow, state->bounce);
+ path_radiance_accum_ao(L, state,
throughput*num_samples_inv, ao_alpha, ao_bsdf, ao_shadow);
}
else {
- path_radiance_accum_total_ao(L,
throughput*num_samples_inv, ao_bsdf);
+ path_radiance_accum_total_ao(L, state,
throughput*num_samples_inv, ao_bsdf);
}
}
}
@@ -479,7 +479,7 @@ ccl_device float
kernel_branched_path_integrate(KernelGlobals *kg, RNG *rng, int
shader_eval_surface(kg, &sd, rng, &state, 0.0f, state.flag,
SHADER_CONTEXT_MAIN);
shader_merge_closures(&sd);
- kernel_write_denoising_passes(kg, buffer, &state, &sd, sample,
make_float3(0.0f, 0.0f, 0.0f));
+ bool write_denoising_shadow = kernel_write_denoising_passes(kg,
buffer, &state, &sd, sample, make_float3(0.0f, 0.0f, 0.0f));
#ifdef __SHADOW_TRICKS__
if((sd.object_flag & SD_OBJECT_SHADOW_CATCHER)) {
@@ -575,6 +575,10 @@ ccl_device float
kernel_branched_path_integrate(KernelGlobals *kg, RNG *rng, int
}
#endif /* __EMISSION__ */
+ if(write_denoising_shadow && !(state.flag &
PATH_RAY_SHADOW_CATCHER)) {
+ state.flag &= ~PATH_RAY_STORE_SHADOW_INFO;
+ }
+
/* indirect light */
kernel_branched_path_surface_indirect_light(kg, rng,
&sd, &indirect_sd, &emission_sd, throughput,
1.0f, &hit_state, L);
diff --git a/intern/cycles/kernel/kernel_path_state.h
b/intern/cycles/kernel/kernel_path_state.h
index c2c277128d..e92d8022e7 100644
--- a/intern/cycles/kernel/kernel_path_state.h
+++ b/intern/cycles/kernel/kernel_path_state.h
@@ -23,7 +23,7 @@ ccl_device_inline void path_state_init(KernelGlobals *kg,
int sample,
ccl_addr_space Ray *ray)
{
- state->flag = PATH_RAY_CAMERA|PATH_RAY_MIS_SKIP;
+ state->flag =
PATH_RAY_CAMERA|PATH_RAY_MIS_SKIP|PATH_RAY_STORE_SHADOW_INFO;
state->rng_offset = PRNG_BASE_NUM;
state->sample = sample;
diff --git a/intern/cycles/kernel/kernel_path_surface.h
b/intern/cycles/kernel/kernel_path_surface.h
index 94d4638c39..cf38597240 100644
--- a/intern/cycles/kernel/kernel_path_surface.h
+++ b/intern/cycles/kernel/kernel_path_surface.h
@@ -64,10 +64,10 @@ ccl_device_noinline void
kernel_branched_path_surface_connect_light(KernelGlobal
if(!shadow_blocked(kg,
emission_sd, state, &light_ray, &shadow)) {
/* accumulate */
-
path_radiance_accum_light(L, throughput*num_samples_inv, &L_light, shadow,
num_samples_inv, state->bounce, is_lamp);
+
path_radiance_accum_light(L, state, throughput*num_samples_inv, &L_light,
shadow, num_samples_inv, is_lamp);
}
else {
- path_rad
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs