diff --git a/src/image.cpp b/src/image.cpp index 24f94f51f4..7954857423 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -959,6 +959,10 @@ void Image::compute_SSAO() int pixelstart = static_cast (1.0*me/nprocs * npixels); int pixelstop = static_cast (1.0*(me+1)/nprocs * npixels); + // file buffer with random numbers to avoid race conditions + double *uniform = new double[pixelstop - pixelstart]; + for (int i = 0; i < pixelstop - pixelstart; ++i) uniform[i] = random->uniform(); + #if defined(_OPENMP) #pragma omp parallel for #endif @@ -973,7 +977,7 @@ void Image::compute_SSAO() double sy = surfaceBuffer[index * 2 + 1]; double sin_t = -sqrt(sx*sx + sy*sy); - double mytheta = random->uniform() * SSAOJitter; + double mytheta = uniform[index - pixelstart] * SSAOJitter; double ao = 0.0; for (int s = 0; s < SSAOSamples; s ++) { @@ -1063,6 +1067,7 @@ void Image::compute_SSAO() imageBuffer[index * 3 + 1] = (int) c[1]; imageBuffer[index * 3 + 2] = (int) c[2]; } + delete[] uniform; } /* ---------------------------------------------------------------------- */