forked from bartvdbraak/blender
Code cleanup: store branch factor in PathState.
This commit is contained in:
parent
9e258fc641
commit
32449e1b21
@ -102,7 +102,6 @@ ccl_device_inline void compute_light_pass(KernelGlobals *kg,
|
||||
&emission_sd,
|
||||
&ray,
|
||||
throughput,
|
||||
state.num_samples,
|
||||
&state,
|
||||
&L_sample);
|
||||
kernel_path_subsurface_accum_indirect(&ss_indirect, &L_sample);
|
||||
@ -121,7 +120,7 @@ ccl_device_inline void compute_light_pass(KernelGlobals *kg,
|
||||
state.ray_t = 0.0f;
|
||||
#endif
|
||||
/* compute indirect light */
|
||||
kernel_path_indirect(kg, &indirect_sd, &emission_sd, &ray, throughput, 1, &state, &L_sample);
|
||||
kernel_path_indirect(kg, &indirect_sd, &emission_sd, &ray, throughput, &state, &L_sample);
|
||||
|
||||
/* sum and reset indirect light pass variables for the next samples */
|
||||
path_radiance_sum_indirect(&L_sample);
|
||||
|
@ -388,7 +388,6 @@ ccl_device void kernel_path_indirect(KernelGlobals *kg,
|
||||
ShaderData *emission_sd,
|
||||
Ray *ray,
|
||||
float3 throughput,
|
||||
int num_samples,
|
||||
PathState *state,
|
||||
PathRadiance *L)
|
||||
{
|
||||
@ -455,10 +454,7 @@ ccl_device void kernel_path_indirect(KernelGlobals *kg,
|
||||
/* path termination. this is a strange place to put the termination, it's
|
||||
* mainly due to the mixed in MIS that we use. gives too many unneeded
|
||||
* shader evaluations, only need emission if we are going to terminate */
|
||||
float probability =
|
||||
path_state_continuation_probability(kg,
|
||||
state,
|
||||
throughput*num_samples);
|
||||
float probability = path_state_continuation_probability(kg, state, throughput);
|
||||
|
||||
if(probability == 0.0f) {
|
||||
break;
|
||||
|
@ -142,7 +142,6 @@ ccl_device_noinline void kernel_branched_path_surface_indirect_light(KernelGloba
|
||||
emission_sd,
|
||||
&bsdf_ray,
|
||||
tp*num_samples_inv,
|
||||
num_samples,
|
||||
&ps,
|
||||
L);
|
||||
|
||||
@ -359,7 +358,6 @@ ccl_device void kernel_branched_path_integrate(KernelGlobals *kg,
|
||||
&emission_sd,
|
||||
&pray,
|
||||
tp*num_samples_inv,
|
||||
num_samples,
|
||||
&ps,
|
||||
L);
|
||||
|
||||
@ -415,7 +413,6 @@ ccl_device void kernel_branched_path_integrate(KernelGlobals *kg,
|
||||
&emission_sd,
|
||||
&pray,
|
||||
tp,
|
||||
num_samples,
|
||||
&ps,
|
||||
L);
|
||||
|
||||
|
@ -29,6 +29,7 @@ ccl_device_inline void path_state_init(KernelGlobals *kg,
|
||||
state->rng_offset = PRNG_BASE_NUM;
|
||||
state->sample = sample;
|
||||
state->num_samples = kernel_data.integrator.aa_samples;
|
||||
state->branch_factor = 1.0f;
|
||||
|
||||
state->bounce = 0;
|
||||
state->diffuse_bounce = 0;
|
||||
@ -157,7 +158,9 @@ ccl_device_inline uint path_state_ray_visibility(KernelGlobals *kg, ccl_addr_spa
|
||||
return flag;
|
||||
}
|
||||
|
||||
ccl_device_inline float path_state_continuation_probability(KernelGlobals *kg, ccl_addr_space PathState *state, const float3 throughput)
|
||||
ccl_device_inline float path_state_continuation_probability(KernelGlobals *kg,
|
||||
ccl_addr_space PathState *state,
|
||||
const float3 throughput)
|
||||
{
|
||||
if(state->flag & PATH_RAY_TRANSPARENT) {
|
||||
/* Transparent rays are treated separately with own max bounces. */
|
||||
@ -201,7 +204,7 @@ ccl_device_inline float path_state_continuation_probability(KernelGlobals *kg, c
|
||||
|
||||
/* Probalistic termination: use sqrt() to roughly match typical view
|
||||
* transform and do path termination a bit later on average. */
|
||||
return min(sqrtf(max3(fabs(throughput))), 1.0f);
|
||||
return min(sqrtf(max3(fabs(throughput)) * state->branch_factor), 1.0f);
|
||||
}
|
||||
|
||||
/* TODO(DingTo): Find more meaningful name for this */
|
||||
@ -224,5 +227,20 @@ ccl_device_inline bool path_state_ao_bounce(KernelGlobals *kg, ccl_addr_space Pa
|
||||
return (bounce > kernel_data.integrator.ao_bounces);
|
||||
}
|
||||
|
||||
ccl_device_inline void path_state_branch(ccl_addr_space PathState *state,
|
||||
int branch,
|
||||
int num_branches)
|
||||
{
|
||||
state->rng_offset += PRNG_BOUNCE_NUM;
|
||||
|
||||
if(num_branches > 1) {
|
||||
/* Path is splitting into a branch, adjust so that each branch
|
||||
* still gets a unique sample from the same sequence. */
|
||||
state->sample = state->sample*num_branches + branch;
|
||||
state->num_samples = state->num_samples*num_branches;
|
||||
state->branch_factor *= num_branches;
|
||||
}
|
||||
}
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
||||
|
@ -296,17 +296,6 @@ ccl_device_inline float path_branched_rng_light_termination(
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
ccl_device_inline void path_state_branch(ccl_addr_space PathState *state,
|
||||
int branch,
|
||||
int num_branches)
|
||||
{
|
||||
/* path is splitting into a branch, adjust so that each branch
|
||||
* still gets a unique sample from the same sequence */
|
||||
state->rng_offset += PRNG_BOUNCE_NUM;
|
||||
state->sample = state->sample*num_branches + branch;
|
||||
state->num_samples = state->num_samples*num_branches;
|
||||
}
|
||||
|
||||
ccl_device_inline uint lcg_state_init(PathState *state,
|
||||
uint scramble)
|
||||
{
|
||||
|
@ -1008,9 +1008,10 @@ typedef struct PathState {
|
||||
|
||||
/* random number generator state */
|
||||
uint rng_hash; /* per pixel hash */
|
||||
int rng_offset; /* dimension offset */
|
||||
int sample; /* path sample number */
|
||||
int num_samples; /* total number of times this path will be sampled */
|
||||
int rng_offset; /* dimension offset */
|
||||
int sample; /* path sample number */
|
||||
int num_samples; /* total number of times this path will be sampled */
|
||||
float branch_factor; /* number of branches in indirect paths */
|
||||
|
||||
/* bounce counting */
|
||||
int bounce;
|
||||
|
@ -188,7 +188,6 @@ ccl_device_noinline bool kernel_split_branched_path_surface_indirect_light_iter(
|
||||
/* update state for next iteration */
|
||||
branched_state->next_closure = i;
|
||||
branched_state->next_sample = j+1;
|
||||
branched_state->num_samples = num_samples;
|
||||
|
||||
/* start the indirect path */
|
||||
*tp *= num_samples_inv;
|
||||
|
@ -72,7 +72,6 @@ ccl_device_noinline bool kernel_split_branched_path_volume_indirect_light_iter(K
|
||||
/* start the indirect path */
|
||||
branched_state->next_closure = 0;
|
||||
branched_state->next_sample = j+1;
|
||||
branched_state->num_samples = num_samples;
|
||||
|
||||
/* Attempting to share too many samples is slow for volumes as it causes us to
|
||||
* loop here more and have many calls to kernel_volume_integrate which evaluates
|
||||
|
@ -134,38 +134,22 @@ ccl_device void kernel_holdout_emission_blurring_pathtermination_ao(
|
||||
* mainly due to the mixed in MIS that we use. gives too many unneeded
|
||||
* shader evaluations, only need emission if we are going to terminate.
|
||||
*/
|
||||
#ifndef __BRANCHED_PATH__
|
||||
float probability = path_state_continuation_probability(kg, state, throughput);
|
||||
#else
|
||||
float probability = 1.0f;
|
||||
|
||||
if(!kernel_data.integrator.branched) {
|
||||
probability = path_state_continuation_probability(kg, state, throughput);
|
||||
}
|
||||
else if(IS_FLAG(ray_state, ray_index, RAY_BRANCHED_INDIRECT)) {
|
||||
int num_samples = kernel_split_state.branched_state[ray_index].num_samples;
|
||||
probability = path_state_continuation_probability(kg, state, throughput*num_samples);
|
||||
}
|
||||
else if(state->flag & PATH_RAY_TRANSPARENT) {
|
||||
probability = path_state_continuation_probability(kg, state, throughput);
|
||||
}
|
||||
#endif
|
||||
|
||||
if(probability == 0.0f) {
|
||||
kernel_split_path_end(kg, ray_index);
|
||||
}
|
||||
else if(probability < 1.0f) {
|
||||
float terminate = path_state_rng_1D_for_decision(kg, state, PRNG_TERMINATE);
|
||||
if(terminate >= probability) {
|
||||
kernel_split_path_end(kg, ray_index);
|
||||
}
|
||||
else {
|
||||
kernel_split_state.throughput[ray_index] = throughput/probability;
|
||||
}
|
||||
}
|
||||
|
||||
if(IS_STATE(ray_state, ray_index, RAY_ACTIVE)) {
|
||||
if(probability != 1.0f) {
|
||||
float terminate = path_state_rng_1D_for_decision(kg, state, PRNG_TERMINATE);
|
||||
if(terminate >= probability) {
|
||||
kernel_split_path_end(kg, ray_index);
|
||||
}
|
||||
else {
|
||||
kernel_split_state.throughput[ray_index] = throughput/probability;
|
||||
}
|
||||
}
|
||||
|
||||
PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
|
||||
kernel_update_denoising_features(kg, sd, state, L);
|
||||
}
|
||||
|
@ -72,7 +72,6 @@ typedef ccl_global struct SplitBranchedState {
|
||||
/* indirect loop state */
|
||||
int next_closure;
|
||||
int next_sample;
|
||||
int num_samples;
|
||||
|
||||
#ifdef __SUBSURFACE__
|
||||
int ss_next_closure;
|
||||
|
Loading…
Reference in New Issue
Block a user