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.
This commit is contained in:
Sergey Sharybin 2015-02-18 01:57:56 +05:00
parent a9dbaf3755
commit ef11be0e77
1 changed files with 6 additions and 3 deletions

View File

@ -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;