From ef11be0e77461a7b5d657c365bac2b7746ca47bf Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 18 Feb 2015 01:57:56 +0500 Subject: [PATCH] Cycles: Avoid over-allocation in decouple ray marching It could have happened with really long rays and small steps. Step size will be adjusted to the clamped number of steps in order to preserve render result compatibility as much as possible. We should probably reformulate this a bit, so it will give the same looking results without step tweaks. But this new behavior should already be much better that it was before. --- intern/cycles/kernel/kernel_volume.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/intern/cycles/kernel/kernel_volume.h b/intern/cycles/kernel/kernel_volume.h index 9d6c233f5b2..8e67ad5464c 100644 --- a/intern/cycles/kernel/kernel_volume.h +++ b/intern/cycles/kernel/kernel_volume.h @@ -623,13 +623,16 @@ ccl_device void kernel_volume_decoupled_record(KernelGlobals *kg, PathState *sta float step_size, random_jitter_offset; if(heterogeneous) { - max_steps = kernel_data.integrator.volume_max_steps; + const int global_max_steps = kernel_data.integrator.volume_max_steps; step_size = kernel_data.integrator.volume_step_size; - random_jitter_offset = lcg_step_float(&state->rng_congruential) * step_size; - /* compute exact steps in advance for malloc */ max_steps = max((int)ceilf(ray->t/step_size), 1); + if (max_steps > global_max_steps) { + max_steps = global_max_steps; + step_size = ray->t / (float)max_steps; + } segment->steps = (VolumeStep*)malloc(sizeof(VolumeStep)*max_steps); + random_jitter_offset = lcg_step_float(&state->rng_congruential) * step_size; } else { max_steps = 1;