diff options
author | Thomas Dinges <blender@dingto.org> | 2014-08-14 22:21:36 +0400 |
---|---|---|
committer | Thomas Dinges <blender@dingto.org> | 2014-08-14 22:21:36 +0400 |
commit | 32a5313b41701a65b6cb588adef4f295989cd3f8 (patch) | |
tree | 630ac336c67dde5d088163450632e99e08c94b07 /intern | |
parent | 5af00a3d12cbce49cb199509373a252c2a0eda85 (diff) |
Cycles: Optimize Equi-Angular sampling using binary range search.
Patch by Lukas Tönne and myself.
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/kernel/kernel_volume.h | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/intern/cycles/kernel/kernel_volume.h b/intern/cycles/kernel/kernel_volume.h index ed73ac8088c..9e78d43efdf 100644 --- a/intern/cycles/kernel/kernel_volume.h +++ b/intern/cycles/kernel/kernel_volume.h @@ -853,15 +853,33 @@ ccl_device VolumeIntegrateResult kernel_volume_decoupled_scatter( float3 step_pdf_distance = make_float3(1.0f, 1.0f, 1.0f); if(segment->numsteps > 1) { - /* todo: optimize using binary search */ float3 prev_cdf_distance = make_float3(0.0f, 0.0f, 0.0f); - for(int i = 0; i < segment->numsteps-1; i++, step++) { - if(sample_t < step->t) + int numsteps = segment->numsteps; + int high = numsteps - 1; + int low = 0; + int mid; + + while(low < high) { + mid = (low + high) >> 1; + + if(sample_t < step[mid].t) + high = mid; + else if(sample_t >= step[mid + 1].t) + low = mid + 1; + else { + /* found our interval in step[mid] .. step[mid+1] */ + prev_t = step[mid].t; + prev_cdf_distance = step[mid].cdf_distance; + step += mid+1; break; + } + } - prev_t = step->t; - prev_cdf_distance = step->cdf_distance; + if(low >= numsteps - 1) { + prev_t = step[numsteps - 1].t; + prev_cdf_distance = step[numsteps-1].cdf_distance; + step += numsteps - 1; } /* pdf for picking step with distance sampling */ |