Add factor to adjust brightness of the distribution.
This commit is contained in:
parent
d53b39f932
commit
5958307f13
2 changed files with 34 additions and 1 deletions
|
|
@ -6,6 +6,8 @@
|
|||
#include "random_sampler.hpp"
|
||||
#include "random_sampler_wrapper.hpp"
|
||||
#include "tasking/taskschedulerinternal.h"
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
ApplicationIntegrator::ApplicationIntegrator(int argc, char **argv,
|
||||
|
|
@ -47,6 +49,11 @@ inline float luminance(Vec3fa v) {
|
|||
void ApplicationIntegrator::resetRender() {
|
||||
Application::resetRender();
|
||||
|
||||
accepted.store(0, std::memory_order_relaxed);
|
||||
luminance_count.store(0, std::memory_order_relaxed);
|
||||
std::lock_guard<std::mutex> guard(large_step_global_luminance_mutex);
|
||||
large_step_global_luminance = 0.0;
|
||||
|
||||
if (bMetropolis) {
|
||||
data.film.count = false;
|
||||
} else {
|
||||
|
|
@ -175,14 +182,18 @@ void ApplicationIntegrator::mltRender(int *pixels, int width, int height,
|
|||
// float integral = d.funcInt;
|
||||
// int index_of_the_sampled_bin = d.SampleDiscrete(rng.get1D());
|
||||
|
||||
|
||||
parallel_for(size_t(0), size_t(num_chains), [&](const range<size_t> &range) {
|
||||
const int threadIndex = (int)TaskScheduler::threadIndex();
|
||||
float large_luminance_outer_sum = 0.0;
|
||||
for (size_t i = range.begin(); i < range.end(); i++) {
|
||||
MLTRandomSampler sampler(small_step_size, large_step_probability);
|
||||
sampler.init(data.frame_count * num_chains + i);
|
||||
|
||||
float last_l = 0.0;
|
||||
|
||||
float large_luminance_sum = 0.0;
|
||||
|
||||
for (size_t j = 0; j < chain_lengths; j++) {
|
||||
|
||||
sampler.new_ray(RandomSampler_get1D(sampler.sampler) < large_step_probability);
|
||||
|
|
@ -196,15 +207,32 @@ void ApplicationIntegrator::mltRender(int *pixels, int width, int height,
|
|||
Vec3f f = renderPixel(x, y, camera, g_stats[threadIndex], sampler);
|
||||
float l = luminance(f);
|
||||
|
||||
if (sampler.is_large_step()) {
|
||||
large_luminance_sum += l;
|
||||
luminance_count.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
if ((last_l == 0.0 && l > 0.0) || (last_l > 0.0 && RandomSampler_get1D(sampler.sampler) < l / last_l)) {
|
||||
data.film.addSplat(x_pixel, y_pixel, f / l);
|
||||
sampler.accept();
|
||||
accepted.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
}
|
||||
large_luminance_outer_sum += large_luminance_sum;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(large_step_global_luminance_mutex);
|
||||
large_step_global_luminance += large_luminance_outer_sum;
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
std::lock_guard<std::mutex> guard(large_step_global_luminance_mutex);
|
||||
data.film.scalar = (float)(width * height) * large_step_global_luminance / (accepted.load(std::memory_order_relaxed) * luminance_count.load(std::memory_order_relaxed));
|
||||
|
||||
|
||||
printf("%f\n", data.film.scalar);
|
||||
}
|
||||
|
||||
void ApplicationIntegrator::mcRender(int *pixels, int width, int height,
|
||||
|
|
@ -218,6 +246,7 @@ void ApplicationIntegrator::mcRender(int *pixels, int width, int height,
|
|||
renderTile((int)i, threadIndex, pixels, width, height, time,
|
||||
camera, numTilesX, numTilesY);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/* renders a single screen tile */
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ protected:
|
|||
const unsigned int height, const float time, const ISPCCamera& camera, const int numTilesX,
|
||||
const int numTilesY);
|
||||
|
||||
std::atomic<size_t> accepted = 0;
|
||||
std::atomic<size_t> luminance_count = 0;
|
||||
float large_step_global_luminance = 0.0;
|
||||
std::mutex large_step_global_luminance_mutex;
|
||||
int num_chains = 100;
|
||||
int chain_lengths = 100000;
|
||||
float small_step_size = 0.01;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue