Skip to content

Commit

Permalink
Add Guided Path Tracing lighting engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Mango-3 committed Aug 30, 2019
1 parent 4676d13 commit 204226b
Show file tree
Hide file tree
Showing 7 changed files with 768 additions and 313 deletions.
363 changes: 280 additions & 83 deletions src/appleseed-max-impl/appleseedrenderer/appleseedrenderer.cpp

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions src/appleseed-max-impl/appleseedrenderer/appleseedrenderer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,45 @@ BEGIN
"SpinnerControl",WS_TABSTOP,125,140,6,10
END

IDD_FORMVIEW_RENDERERPARAMS_GUIDED_PATH_TRACING DIALOGEX 0, 0, 200, 163
STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
LTEXT "Samples Per Pass:",IDC_STATIC_GPT_SAMPLES_PER_PASS,0,1,65,8
CONTROL "Samples Per Pass",IDC_TEXT_GPT_SAMPLES_PER_PASS,
"CustEdit",WS_TABSTOP,107,0,22,10
CONTROL "Samples Per Pass",IDC_SPINNER_GPT_SAMPLES_PER_PASS,
"SpinnerControl",WS_TABSTOP,131,0,6,10
CONTROL "Max. Guided Path Length",IDC_TEXT_GPT_GUIDED_PATH_LENGTH,
"CustEdit",WS_TABSTOP,107,87,21,10
CONTROL "Max. Guided Path Length",IDC_SPINNER_GPT_GUIDED_PATH_LENGTH,
"SpinnerControl",WS_TABSTOP,131,87,6,10
CONTROL "Max. Guided Bounces:",IDC_CHECK_GPT_GUIDED_PATH_LENGTH,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,88,95,8
LTEXT "Spatial Filter:",IDC_STATIC,0,17,56,8
COMBOBOX IDC_COMBO_GPT_SPATIAL_FILTER_TYPE,107,14,71,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Directional Filter:",IDC_STATIC,0,32,55,8
COMBOBOX IDC_COMBO_GPT_DIRECTIONAL_FILTER_TYPE,107,30,71,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Guided Bounce Mode:",IDC_STATIC,4,72,73,8
COMBOBOX IDC_COMBO_GPT_GUIDED_BOUNCE_MODE_TYPE,107,70,92,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Learning Rate:",IDC_STATIC_GPT_SAMPLING_FRACTION_LEARNING_RATE,3,132,48,8
CONTROL "BSDF Sampling Fraction Learning Rate",IDC_TEXT_GPT_SAMPLING_FRACTION_LEARNING_RATE,
"CustEdit",WS_TABSTOP,107,131,30,10
CONTROL "BSDF Sampling Fraction Learning Rate",IDC_SPINNER_GPT_SAMPLING_FRACTION_LEARNING_RATE,
"SpinnerControl",WS_TABSTOP,138,131,6,10
LTEXT "Iteration Progression:",IDC_STATIC,0,48,100,8
COMBOBOX IDC_COMBO_GPT_ITERATION_PROGRESSION_TYPE,107,46,92,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Mode:",IDC_STATIC,3,117,102,8
COMBOBOX IDC_COMBO_GPT_SAMPLING_FRACTION_MODE_TYPE,107,114,39,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Fixed Fraction:",IDC_STATIC_GPT_FIXED_BSDF_SAMPLING_FRACTION,3,146,101,8
CONTROL "Fixed BSDF Sampling Fraction",IDC_TEXT_GPT_FIXED_BSDF_SAMPLING_FRACTION,
"CustEdit",WS_TABSTOP,107,146,30,10
CONTROL "Fixed BSDF Sampling Fraction",IDC_SPINNER_GPT_FIXED_BSDF_SAMPLING_FRACTION,
"SpinnerControl",WS_TABSTOP,138,146,6,10
GROUPBOX "BSDF / SD-Tree Sampling Fraction",IDC_STATIC,0,105,199,54
GROUPBOX "Path Continuation",IDC_STATIC,0,61,199,39
END


/////////////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -401,6 +440,11 @@ BEGIN
BEGIN
BOTTOMMARGIN, 288
END

IDD_FORMVIEW_RENDERERPARAMS_GUIDED_PATH_TRACING, DIALOG
BEGIN
BOTTOMMARGIN, 156
END
END
#endif // APSTUDIO_INVOKED

Expand Down Expand Up @@ -450,6 +494,11 @@ BEGIN
0
END

IDD_FORMVIEW_RENDERERPARAMS_GUIDED_PATH_TRACING AFX_DIALOG_LAYOUT
BEGIN
0
END


/////////////////////////////////////////////////////////////////////////////
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ struct AppleseedRendererParamDlg::Impl
IParamMap2* m_pmap_image_sampling;
IParamMap2* m_pmap_lighting;
IParamMap2* m_pmap_pathtracer;
IParamMap2* m_pmap_guided_pathtracer;
IParamMap2* m_pmap_sppm;
IParamMap2* m_pmap_postprocessing;
IParamMap2* m_pmap_system;
Expand All @@ -548,6 +549,7 @@ struct AppleseedRendererParamDlg::Impl
, m_pmap_image_sampling(nullptr)
, m_pmap_lighting(nullptr)
, m_pmap_pathtracer(nullptr)
, m_pmap_guided_pathtracer(nullptr)
, m_pmap_sppm(nullptr)
, m_pmap_postprocessing(nullptr)
, m_pmap_system(nullptr)
Expand Down Expand Up @@ -595,6 +597,15 @@ struct AppleseedRendererParamDlg::Impl
L"Path Tracing",
0);

m_pmap_guided_pathtracer = CreateRParamMap2(
7,
renderer->GetParamBlock(0),
rend_params,
g_module,
MAKEINTRESOURCE(IDD_FORMVIEW_RENDERERPARAMS_GUIDED_PATH_TRACING),
L"Guided Path Tracing",
0);

m_pmap_sppm = CreateRParamMap2(
4,
renderer->GetParamBlock(0),
Expand Down Expand Up @@ -646,6 +657,10 @@ struct AppleseedRendererParamDlg::Impl

if (m_pmap_output != nullptr)
DestroyRParamMap2(m_pmap_output);

if (m_pmap_guided_pathtracer != nullptr)
DestroyRParamMap2(m_pmap_guided_pathtracer);

}
};

Expand Down
2 changes: 2 additions & 0 deletions src/appleseed-max-impl/appleseedrenderer/datachunks.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,5 @@ const USHORT ChunkSettingsSPPMViewPhotons = 0x1710;
const USHORT ChunkSettingsSPPMViewPhotonsRadius = 0x1711;
const USHORT ChunkSettingsSPPMMaxRayIntensitySet = 0x1712;
const USHORT ChunkSettingsSPPMMaxRayIntensity = 0x1713;

const USHORT ChunkSettingsGuidedPathtracer = 0x1800;
149 changes: 146 additions & 3 deletions src/appleseed-max-impl/appleseedrenderer/renderersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ namespace
m_max_ray_intensity = 1.0f;
m_clamp_roughness = false;

m_gpt_samples_per_pass = 8;
m_gpt_enable_guided_bounce_limit = true;
m_gpt_max_guided_bounces = 8;
m_gpt_spatial_filter_type = 0;
m_gpt_directional_filter_type = 0;
m_gpt_guided_bounce_mode = 0;
m_gpt_sampling_fraction_learning_rate = 0.01f;
m_gpt_iteration_progression_mode = 0;
m_gpt_bsdf_sampling_fraction_mode = 0;
m_gpt_fixed_bsdf_sampling_fraction = 0.5f;

m_sppm_photon_type = 1;
m_sppm_direct_lighting_mode = 0;
m_sppm_enable_caustics = true;
Expand Down Expand Up @@ -192,8 +203,9 @@ const char* get_lighting_engine_type(const int lighting_engine_type)
{
switch (lighting_engine_type)
{
case 0: return "pt";
case 1: return "sppm";
case 0: return "pt"; // unidirectional path tracing
case 1: return "sppm"; // stochastic progressive photon mapping
case 2: return "gpt"; // guided path tracing
default:
assert(!"Invalid lighting engine type.");
return "pt";
Expand Down Expand Up @@ -237,6 +249,70 @@ const char* get_sppm_direct_lighting_mode(const int lighting_mode)
}
}

const char* get_gpt_spatial_filter_type(const int filter_type)
{
switch (filter_type)
{
case 0: return "stochastic";
case 1: return "box";
case 2: return "nearest";
default:
assert(!"Invalid spatial filter type.");
return "stochastic";
}
}

const char* get_gpt_directional_filter_type(const int filter_type)
{
switch (filter_type)
{
case 0: return "box";
case 1: return "nearest";
default:
assert(!"Invalid directional filter type.");
return "box";
}
}

const char* get_gpt_guided_bounce_mode(const int bounce_mode)
{
switch (bounce_mode)
{
case 0: return "learn";
case 1: return "strictly_diffuse";
case 2: return "strictly_glossy";
case 3: return "prefer_diffuse";
case 4: return "prefer_glossy";
default:
assert(!"Invalid guided bounce mode.");
return "learn";
}
}

const char* get_gpt_iteration_progression_mode(const int mode_type)
{
switch (mode_type)
{
case 0: return "combine";
case 1: return "automatic";
default:
assert(!"Unknown parameter for iteration progression.");
return "combine";
}
}

const char* get_gpt_sampling_fraction_mode(const int mode_type)
{
switch (mode_type)
{
case 0: return "learn";
case 1: return "fixed";
default:
assert(!"Unknown parameter for bsdf sampling fraction mode.");
return "learn";
}
}

const RendererSettings& RendererSettings::defaults()
{
static DefaultRendererSettings default_settings;
Expand All @@ -252,6 +328,8 @@ void RendererSettings::apply(asr::Project& project) const
apply_settings_to_interactive_config(project);
}

// Common render settings.

void RendererSettings::apply_common_settings(asr::Project& project, const char* config_name) const
{
asr::ParamArray& params = project.configurations().get_by_name(config_name)->get_parameters();
Expand All @@ -264,6 +342,8 @@ void RendererSettings::apply_common_settings(asr::Project& project, const char*

params.insert_path("light_sampler.algorithm", get_lighting_algorithm_type(m_light_sampling_algorithm));

// Path tracing.

params.insert_path("pt.max_bounces", m_global_bounces);

if (m_diffuse_bounces_enabled)
Expand Down Expand Up @@ -297,6 +377,8 @@ void RendererSettings::apply_common_settings(asr::Project& project, const char*
if (m_max_ray_intensity_set)
params.insert_path("pt.max_ray_intensity", m_max_ray_intensity);

// SPPM.

params.insert_path("sppm.photon_type", get_sppm_photon_type(m_sppm_photon_type));
params.insert_path("sppm.dl_mode", get_sppm_direct_lighting_mode(m_sppm_direct_lighting_mode));
params.insert_path("sppm.enable_caustics", m_sppm_enable_caustics);
Expand All @@ -322,6 +404,56 @@ void RendererSettings::apply_common_settings(asr::Project& project, const char*
params.insert_path("sppm.view_photons", m_sppm_view_photons);
params.insert_path("sppm.view_photons_radius", m_sppm_view_photons_radius);

// Guided path tracing.

params.insert_path("gpt.bsdf_sampling_fraction", get_gpt_sampling_fraction_mode(m_gpt_bsdf_sampling_fraction_mode));
params.insert_path("gpt.fixed_bsdf_sampling_fraction_value", m_gpt_fixed_bsdf_sampling_fraction);
params.insert_path("gpt.guided_bounce_mode", get_gpt_guided_bounce_mode(m_gpt_guided_bounce_mode));
params.insert_path("gpt.iteration_progression", get_gpt_iteration_progression_mode(m_gpt_iteration_progression_mode));
params.insert_path("gpt.learning_rate", m_gpt_sampling_fraction_learning_rate);
params.insert_path("gpt.spatial_filter", get_gpt_spatial_filter_type(m_gpt_spatial_filter_type));
params.insert_path("gpt.samples_per_pass", m_gpt_samples_per_pass);
params.insert_path("gpt.directional_filter", get_gpt_directional_filter_type(m_gpt_directional_filter_type));
params.insert_path("gpt.rr_min_path_length", m_rr_min_path_length);
params.insert_path("gpt.next_event_estimation", "true");

if (m_gpt_enable_guided_bounce_limit)
params.insert_path("gpt.max_guided_bounces", m_gpt_max_guided_bounces);
else params.insert_path("gpt.max_guided_bounces", -1);

if (!m_dl_enable_dl)
params.insert_path("gpt.enable_dl", false);

params.insert_path("gpt.dl_light_samples", m_dl_light_samples);
params.insert_path("gpt.dl_low_light_threshold", m_dl_low_light_threshold);
params.insert_path("gpt.ibl_env_samples", m_ibl_env_samples);
params.insert_path("gpt.enable_ibl", m_background_emits_light);
params.insert_path("gpt.max_bounces", m_global_bounces);

if (m_diffuse_bounces_enabled)
params.insert_path("gpt.max_diffuse_bounces", m_diffuse_bounces);

if (!m_enable_gi)
params.insert_path("gpt.max_diffuse_bounces", 0);

if (m_glossy_bounces_enabled)
params.insert_path("gpt.max_glossy_bounces", m_glossy_bounces);

if (m_specular_bounces_enabled)
params.insert_path("gpt.max_specular_bounces", m_specular_bounces);

if (m_volume_bounces_enabled)
params.insert_path("gpt.max_volume_bounces", m_volume_bounces);

params.insert_path("gpt.volume_distance_samples", m_volume_distance_samples);
params.insert_path("gpt.optimize_for_lights_outside_volumes", m_optimize_for_lights_outside_volumes);
params.insert_path("gpt.clamp_roughness", m_clamp_roughness);

if (m_max_ray_intensity_set)
params.insert_path("gpt.max_ray_intensity", m_max_ray_intensity);

// System.

params.insert_path("use_embree", m_enable_embree);
params.insert_path("texture_store.max_size", m_texture_cache_size * 1024 * 1024);

Expand All @@ -333,13 +465,22 @@ void RendererSettings::apply_common_settings(asr::Project& project, const char*
params.insert_path("shading_engine.override_shading.mode", get_shader_override_type(m_shader_override));
}

// Final render settings.

void RendererSettings::apply_settings_to_final_config(asr::Project& project) const
{
asr::ParamArray& params = project.configurations().get_by_name("final")->get_parameters();

params.insert_path("generic_frame_renderer.tile_ordering", "spiral");
params.insert_path("passes", m_passes);
params.insert_path("shading_result_framebuffer", m_passes == 1 ? "ephemeral" : "permanent");
if (m_passes == 1 && m_lighting_algorithm == 0)
{
params.insert_path("shading_result_framebuffer", "ephemeral");
}
else
{
params.insert_path("shading_result_framebuffer", "permanent");
}

if (m_sampler_type == 0)
{
Expand All @@ -358,6 +499,8 @@ void RendererSettings::apply_settings_to_final_config(asr::Project& project) con
}
}

// Interactive render settings.

void RendererSettings::apply_settings_to_interactive_config(asr::Project& project) const
{
asr::ParamArray& params = project.configurations().get_by_name("interactive")->get_parameters();
Expand Down
15 changes: 15 additions & 0 deletions src/appleseed-max-impl/appleseedrenderer/renderersettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ class RendererSettings
int m_rr_min_path_length;
bool m_optimize_for_lights_outside_volumes;

//
// Guided Path Tracer.
//

int m_gpt_samples_per_pass;
bool m_gpt_enable_guided_bounce_limit;
int m_gpt_max_guided_bounces;
int m_gpt_spatial_filter_type;
int m_gpt_directional_filter_type;
int m_gpt_guided_bounce_mode;
float m_gpt_sampling_fraction_learning_rate;
int m_gpt_iteration_progression_mode;
int m_gpt_bsdf_sampling_fraction_mode;
float m_gpt_fixed_bsdf_sampling_fraction;

//
// Stochastic Progressive Photon Mapping.
//
Expand Down
Loading

0 comments on commit 204226b

Please sign in to comment.