Commit 9eea57b2 authored by MURRAY David's avatar MURRAY David

wip data export and co

parent ff7b807c
Pipeline #106726 skipped with stage
......@@ -25,6 +25,7 @@ ImGUI_shader::ImGUI_shader(mrf::gui::fb::Loger::LEVEL const & logging_level) :
_alpha_layer = 0;
_use_sample_balancing = true;
_reset_on_iteration = true;
_clamp_alpha = false;
_is_picking = false;
_picking_pos[0] = 0;
_picking_pos[1] = 0;
......@@ -96,6 +97,11 @@ void ImGUI_shader::customUI(ImGUI::UI_MODE mode)
_renderer->setResetOnIteration(_reset_on_iteration);
_camera_changed = true;
}
if (ImGui::Checkbox("Clamp alpha", &_clamp_alpha))
{
_renderer->setClampAlpha(_clamp_alpha);
_camera_changed = true;
}
int samples_alpha = _renderer->getSamplesAlpha();
int sample_step = 128;
......@@ -234,20 +240,28 @@ void ImGUI_shader::display()
_renderer->setStartAlpha(_prev_alpha);
if (((_samples_done - _variance_samples) / _variance_samples) < 3)
if (((_samples_done - _variance_samples) / _variance_samples)%6 < 3)
_reset_on_iteration = true;
else
_reset_on_iteration = false;
_renderer->setResetOnIteration(_reset_on_iteration);
if (((_samples_done - _variance_samples) / _variance_samples) < 6)
_clamp_alpha = false;
else
_clamp_alpha = true;
_renderer->setClampAlpha(_clamp_alpha);
}
_renderer->setBalancing(_use_sample_balancing);
activateVarianceLog();
_camera_changed = true;
}
if ((_samples_done-1) / _variance_samples == 7)
if ((_samples_done-1) / _variance_samples == 13)
{
_log_variance = false;
_log_time = false;
_render_on_pause = true;
}
}
}
......@@ -376,7 +390,7 @@ void ImGUI_shader::mousePress(int button, int action, int mods)
else if (io.MouseDown[0])
{
_picking_pos[0] = io.MouseClickedPos->x;
_picking_pos[1] = _width - io.MouseClickedPos->y;
_picking_pos[1] = _height - io.MouseClickedPos->y;
_is_picking = false;
}
}
......@@ -570,12 +584,18 @@ void ImGUI_shader::saveConfig()
config = config + "_" + std::to_string(_renderer->getSamplesAlpha()) + "x" + std::to_string(_renderer->getAlphaPasses());
if (_reset_on_iteration)
config = config + "_withReset";
else
config = config + "_noReset";
if (_clamp_alpha)
config = config + "_clamp";
else
config = config + "_noClamp";
}
else
config = config + "_noBalance";
config = config + "_noBalance_REF";
filename = dir + "variance_" + config;
_renderer->saveImage(filename + ".png", "variance_buffer");
_renderer->saveImage(filename + ".exr", "variance_buffer");
saveVarianceAtPicked(filename + ".txt");
filename = dir + "radiance_" + config;
......
......@@ -74,6 +74,7 @@ private:
bool _use_sample_balancing;
bool _reset_on_iteration;
bool _clamp_alpha;
int _requestedMode;
......
......@@ -112,7 +112,7 @@ void GUI::createContext(int w, int h)
}
glfwMakeContextCurrent(_window);
glfwSwapInterval(0);// ~V-sync
glfwSwapInterval(0);// ~V-sync disabled
std::cout << "GL version: " << glGetString(GL_VERSION) << std::endl;
......
......@@ -85,6 +85,8 @@ rtDeclareVariable(int, alpha_samples,, );
rtDeclareVariable(int, alpha_passes,, );
rtDeclareVariable(float, start_alpha,, );
rtDeclareVariable(int, reset_iteration,, );
rtDeclareVariable(int, clamp_alpha,, );
rtDeclareVariable(int, use_balancing,, );
#ifdef INTERACTIVE_MODE
rtBuffer<float4, 2> display_buffer;
......@@ -123,21 +125,24 @@ RT_PROGRAM void pathtrace_camera()
unsigned int seed = tea<16>(screen.x*launch_index.y+launch_index.x, frame_number);
for(int i =0; i <= max_path_length;++i)
if(use_balancing == 1)
{
Metrics tmp;
metrics_buffer[make_uint3(launch_index, i)].is_bg = false;
if(frame_number <= 1) //First frame, initialize alpha_0
for(int i =0; i <= max_path_length;++i)
{
alpha_buffer[make_uint3(launch_index, i)] = make_float4(0.f, 0.f, start_alpha, -1.f);
metrics_buffer[make_uint3(launch_index, i)].alpha_comp = make_float2(0.f);
metrics_buffer[make_uint3(launch_index, i)].prev_alpha = start_alpha;
metrics_buffer[make_uint3(launch_index, i)].nb_samples = 0;
Metrics tmp;
metrics_buffer[make_uint3(launch_index, i)].is_bg = false;
if(frame_number <= 1) //First frame, initialize alpha_0
{
alpha_buffer[make_uint3(launch_index, i)] = make_float4(0.f, 0.f, start_alpha, -1.f);
metrics_buffer[make_uint3(launch_index, i)].alpha_comp = make_float2(0.f);
metrics_buffer[make_uint3(launch_index, i)].prev_alpha = start_alpha;
metrics_buffer[make_uint3(launch_index, i)].nb_samples = 0;
}
// metrics_buffer[make_uint3(launch_index, i)] = tmp;
}
// metrics_buffer[make_uint3(launch_index, i)] = tmp;
if(frame_number == 1)
rad_sqr_buffer[launch_index] = make_float4(0.f);
}
if(frame_number == 1)
rad_sqr_buffer[launch_index] = make_float4(0.f);
float3 impactPos = make_float3(0.f, 0.f, 0.f);
for (; samples_per_pixel>0; --samples_per_pixel)
......@@ -239,7 +244,7 @@ RT_PROGRAM void pathtrace_camera()
seed = prd.seed;
Metrics all_metrics = metrics_buffer[make_uint3(launch_index, 0)];
if(all_metrics.nb_samples < alpha_samples * alpha_passes)
if(all_metrics.nb_samples < alpha_samples * alpha_passes && use_balancing == 1)
// if(frame_number < alpha_samples * alpha_passes)
{
int path_depth = 0;
......@@ -268,14 +273,14 @@ RT_PROGRAM void pathtrace_camera()
float alpha = all_metrics.prev_alpha;
if(alpha_comp.y == 0.f || alpha_comp.x == 0.f)
alpha = 0.5f;
else if(isnan(alpha_comp.x))// / alpha_comp.y))
alpha = -2.f;
// else if(isnan(alpha_comp.x))// / alpha_comp.y))
// alpha = -2.f;
else
alpha = clamp(alpha + 0.5f * alpha_comp.x / alpha_comp.y, 0.f, 1.f);
alpha = clamp(alpha + 0.5f * alpha_comp.x / alpha_comp.y, 0.f + clamp_alpha * 0.025f, 1.f - clamp_alpha * 0.025f);
if(alpha == -2.f)
alpha_buffer[make_uint3(launch_index, path_depth)] = make_float4(0.f, 0.f, start_alpha, -2.f);
else
// if(alpha == -2.f)
// alpha_buffer[make_uint3(launch_index, path_depth)] = make_float4(0.f, 0.f, start_alpha, -2.f);
// else
{
float3 color = make_float3(1.f - alpha, alpha, alpha);
float3 green = make_float3(0.f, 1.f, alpha);
......@@ -346,8 +351,7 @@ RT_PROGRAM void pathtrace_camera()
#endif
#else
float3 xiSqr = pixel_color * pixel_color;
float3 xiSqrSum = xiSqr; //init to xiSqr, updated to sum if needed;
float3 xiSqrMean = xiSqr; //init to xiSqr, updated to sum if needed;
int nb_samples = frame_number;//metrics_buffer[make_uint3(launch_index, 0)].nb_samples;
if (nb_samples > 1)
......@@ -356,12 +360,13 @@ RT_PROGRAM void pathtrace_camera()
float3 old_color = make_float3(output_buffer[launch_index]);
pixel_color = lerp( old_color, pixel_color, a ); //pixel_color is now equivalent to radiance_mean
xiSqrSum = make_float3(rad_sqr_buffer[launch_index]);// get sum of sqr xi up to n-1 (=mean of sqr)
xiSqrSum = lerp( xiSqrSum, xiSqr, a); //lerp to add the nth to the mean of sqr
xiSqrMean = make_float3(rad_sqr_buffer[launch_index]);// get sum of sqr xi up to n-1 (=mean of sqr)
xiSqr = lerp( xiSqrMean, xiSqr, a); //lerp to add the nth to the mean of sqr
}
output_buffer[launch_index] = make_float4(pixel_color,1.f);
rad_sqr_buffer[launch_index] = make_float4(xiSqrSum, 1.f);
variance_buffer[launch_index] = make_float4(xiSqrSum - pixel_color * pixel_color, 1.f);
rad_sqr_buffer[launch_index] = make_float4(xiSqr, 1.f);
variance_buffer[launch_index] = make_float4(xiSqr - pixel_color * pixel_color, 1.f);
//interactive rgb mode
#ifdef INTERACTIVE_MODE
......@@ -465,14 +470,17 @@ RT_PROGRAM void miss()
mult_color(temp_bg_color, current_prd.attenuation);
add_color(current_prd.result, temp_bg_color);
if(current_prd.depth == 0)
if(use_balancing == 1)
{
if(current_prd.depth == 0)
metrics_buffer[make_uint3(launch_index, 0)].is_bg = true;
for(int i = 0; i < current_prd.depth; ++i)
{
uint3 index = make_uint3(launch_index, i);
metrics_buffer[index].alpha_comp_num = make_float3(0.f);
metrics_buffer[index].alpha_comp_den = make_float3(0.f);
for(int i = 0; i < current_prd.depth; ++i)
{
uint3 index = make_uint3(launch_index, i);
metrics_buffer[index].alpha_comp_num = make_float3(0.f);
metrics_buffer[index].alpha_comp_den = make_float3(0.f);
}
}
current_prd.done = true;
......
......@@ -30,6 +30,7 @@ rtDeclareVariable(unsigned int, max_path_length,, );
rtDeclareVariable(unsigned int, frame_number,, );
rtDeclareVariable(int, alpha_samples,, );
rtDeclareVariable(int, alpha_passes,, );
rtDeclareVariable(int, use_balancing,, );
RT_PROGRAM void diffuseEmitter()
{
......@@ -64,7 +65,7 @@ RT_PROGRAM void diffuseEmitter()
#endif
float3 total_attenuation = current_prd.attenuation;
if(length(total_attenuation) != 0.0)
if(length(total_attenuation) != 0.0 && use_balancing == 1)
for(int i = 0; i < current_prd.depth; ++i)
{
uint3 index = make_uint3(launch_index, i);
......@@ -78,12 +79,13 @@ RT_PROGRAM void diffuseEmitter()
}
else
{
for(int i = 0; i < current_prd.depth; ++i)
{
uint3 index = make_uint3(launch_index, i);
metrics_buffer[index].alpha_comp_num = make_float3(0.f);
metrics_buffer[index].alpha_comp_den = make_float3(0.f);
}
if(use_balancing == 1)
for(int i = 0; i < current_prd.depth; ++i)
{
uint3 index = make_uint3(launch_index, i);
metrics_buffer[index].alpha_comp_num = make_float3(0.f);
metrics_buffer[index].alpha_comp_den = make_float3(0.f);
}
}
//Stop path when hiting an emissive surface
......
......@@ -13,6 +13,7 @@ rtDeclareVariable(unsigned int, max_path_length,, );
rtBuffer<Metrics, 3> metrics_buffer;
rtDeclareVariable(int, alpha_samples,, );
rtDeclareVariable(int, alpha_passes,, );
rtDeclareVariable(int, use_balancing,, );
using namespace optix;
......@@ -58,24 +59,25 @@ RT_PROGRAM void envmap_miss()
//DEACTIVATE ENVMAP VALUE IT IS ALREADY SAMPLE IN NEXT EVENT
if(current_prd.countEmitted)
{
// mult_color(envmap_color, current_prd.attenuation);
if(current_prd.depth == 0) //Miss at launch
// {
// uint3 index = make_uint3(launch_index, current_prd.depth);
metrics_buffer[make_uint3(launch_index, 0)].is_bg = true;
// }
else
if(use_balancing == 1)
{
float3 total_attenuation = current_prd.attenuation;
if(length(total_attenuation) != 0.0)
for(int i = 0; i < current_prd.depth; ++i)
{
uint3 index = make_uint3(launch_index, i);
float3 factor = total_attenuation / metrics_buffer[index].attenuation;
metrics_buffer[index].alpha_comp_num *= factor*factor*envmap_color*envmap_color;
metrics_buffer[index].alpha_comp_den *= factor*factor*envmap_color*envmap_color;
}
if(current_prd.depth == 0) //Miss at launch
metrics_buffer[make_uint3(launch_index, 0)].is_bg = true;
else
{
float3 total_attenuation = current_prd.attenuation;
if(length(total_attenuation) != 0.0)
for(int i = 0; i < current_prd.depth; ++i)
{
uint3 index = make_uint3(launch_index, i);
float3 factor;
factor.x = max(0.f,total_attenuation.x / metrics_buffer[index].attenuation.x);
factor.y = max(0.f,total_attenuation.y / metrics_buffer[index].attenuation.y);
factor.z = max(0.f,total_attenuation.z / metrics_buffer[index].attenuation.z);
metrics_buffer[index].alpha_comp_num *= factor*factor*envmap_color*envmap_color;
metrics_buffer[index].alpha_comp_den *= factor*factor*envmap_color*envmap_color;
}
}
}
//current_prd.result += envmap_color * current_prd.attenuation;
......
......@@ -677,9 +677,13 @@ RT_PROGRAM void material_eval()
tmp_metrics.attenuation = cumul_brdf;
mult_color(brdf_ndl, balance_heuristic_alpha(alpha, brdf_pdf_v, light_pdf));
// if(balance > alpha)
// mult_color(brdf_ndl, mis_heuristic(1, light_pdf, 1, brdf_pdf_v));
// else
// mult_color(brdf_ndl, mis_heuristic(1, brdf_pdf_v, 1, light_pdf));
mult_color(current_prd.attenuation, brdf_ndl);
}
else //Trying to
else //Light can't reach light or brdf ray does not contribute
current_prd.done;
metrics_buffer[local_index] = tmp_metrics;
......
......@@ -96,14 +96,15 @@ OptixRenderer::OptixRenderer(mrf::gui::fb::Loger const & loger) :
_scene_imported = false;
_samples_alpha = 32;
_alpha_passes = 64;
_samples_alpha = 128;
_alpha_passes = 32;
_start_alpha = 0.5f;
_mrf_scene = nullptr;
_reset_iteration = false;
_use_sample_balancing = true;
_clamp_alpha = false;
#if RENDERER_INTERACTIVE
_exposition = 1.f;
......@@ -546,6 +547,7 @@ void OptixRenderer::createRenderContext(bool interactive_mode)
_context["start_alpha"]->setFloat(_start_alpha);
_context["use_balancing"]->setInt(_use_sample_balancing? 1 : 0);
_context["reset_iteration"]->setInt(_reset_iteration ? 1 : 0);
_context["clamp_alpha"]->setInt(_clamp_alpha ? 1 : 0);
// Setup programs
try
......
......@@ -141,9 +141,11 @@ class MRF_EXPORT OptixRenderer : public Renderer
void setStartAlpha(float start) { _start_alpha = start; if(_context.get()) _context["start_alpha"]->setFloat(_start_alpha); }
void setBalancing(bool state) { _use_sample_balancing = state; if(_context.get()) _context["use_balancing"]->setInt(_use_sample_balancing? 1 : 0); }
void setResetOnIteration(bool state) { _reset_iteration = state; if(_context.get()) _context["reset_iteration"]->setInt(_reset_iteration ? 1 : 0); }
void setClampAlpha(bool state) { _clamp_alpha = state; if(_context.get()) _context["clamp_alpha"]->setInt(_clamp_alpha ? 1 : 0); }
int getSamplesAlpha() { return _samples_alpha; }
int getBalancing() { return _use_sample_balancing; }
int getResetOnIteration() { return _reset_iteration; }
bool getClampAlpha() { return _clamp_alpha; }
bool getBalancing() { return _use_sample_balancing; }
bool getResetOnIteration() { return _reset_iteration; }
int getAlphaPasses() { return _alpha_passes; }
float getStartAlpha() { return _start_alpha; }
optix::Buffer getBuffer(std::string bufferName);
......@@ -302,6 +304,7 @@ public:
optix::Buffer _metric_buffer;
bool _use_sample_balancing;
bool _clamp_alpha;
bool _reset_iteration;
optix::Buffer _alpha_buffer;
optix::Buffer _rad_sqr_buffer;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment