Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do not merge] Add Guided Path Tracing lighting engine #312

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
368 changes: 287 additions & 81 deletions src/appleseed-max-impl/appleseedrenderer/appleseedrenderer.cpp

Large diffs are not rendered by default.

55 changes: 54 additions & 1 deletion src/appleseed-max-impl/appleseedrenderer/appleseedrenderer.rc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ BEGIN
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,4,162,124,10
END

IDD_FORMVIEW_RENDERERPARAMS_PATH_TRACING DIALOGEX 0, 0, 200, 210
IDD_FORMVIEW_RENDERERPARAMS_PATH_TRACING DIALOGEX 0, 0, 200, 408
STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
Expand Down Expand Up @@ -174,6 +174,42 @@ BEGIN
"SpinnerControl",WS_TABSTOP,124,115,6,10
CONTROL "Optimize For Lights Outside Volumes",IDC_CHECK_LIGHT_OUTSIDE_VOLUMES,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,0,132,130,10
LTEXT "Samples Per Pass:",IDC_STATIC_GPT_SAMPLES_PER_PASS,7,241,65,8
CONTROL "Samples Per Pass",IDC_TEXT_GPT_SAMPLES_PER_PASS,
"CustEdit",WS_TABSTOP,107,240,22,10
CONTROL "Samples Per Pass",IDC_SPINNER_GPT_SAMPLES_PER_PASS,
"SpinnerControl",WS_TABSTOP,131,240,6,10
CONTROL "Max. Guided Path Length",IDC_TEXT_GPT_GUIDED_PATH_LENGTH,
"CustEdit",WS_TABSTOP,107,328,21,10
CONTROL "Max. Guided Path Length",IDC_SPINNER_GPT_GUIDED_PATH_LENGTH,
"SpinnerControl",WS_TABSTOP,131,328,6,10
CONTROL "Max Guided Bounces:",IDC_CHECK_GPT_GUIDED_PATH_LENGTH,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,329,95,8
LTEXT "Spatial Filter:",IDC_STATIC,7,257,56,8
COMBOBOX IDC_COMBO_GPT_SPATIAL_FILTER_TYPE,107,254,71,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Directional Filter:",IDC_STATIC,7,272,55,8
COMBOBOX IDC_COMBO_GPT_DIRECTIONAL_FILTER_TYPE,107,270,71,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Guided Bounce Mode:",IDC_STATIC,7,313,73,8
COMBOBOX IDC_COMBO_GPT_GUIDED_BOUNCE_MODE_TYPE,107,311,83,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Learning Rate:",IDC_STATIC_GPT_SAMPLING_FRACTION_LEARNING_RATE,7,374,48,8
CONTROL "BSDF Sampling Fraction Learning Rate",IDC_TEXT_GPT_SAMPLING_FRACTION_LEARNING_RATE,
"CustEdit",WS_TABSTOP,107,373,30,10
CONTROL "BSDF Sampling Fraction Learning Rate",IDC_SPINNER_GPT_SAMPLING_FRACTION_LEARNING_RATE,
"SpinnerControl",WS_TABSTOP,138,373,6,10
LTEXT "Iteration Progression:",IDC_STATIC,7,288,83,8
COMBOBOX IDC_COMBO_GPT_ITERATION_PROGRESSION_TYPE,107,286,84,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Mode:",IDC_STATIC,7,359,102,8
COMBOBOX IDC_COMBO_GPT_SAMPLING_FRACTION_MODE_TYPE,107,356,39,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Fixed Fraction:",IDC_STATIC_GPT_FIXED_BSDF_SAMPLING_FRACTION,7,388,101,8
CONTROL "Fixed BSDF Sampling Fraction",IDC_TEXT_GPT_FIXED_BSDF_SAMPLING_FRACTION,
"CustEdit",WS_TABSTOP,107,388,30,10
CONTROL "Fixed BSDF Sampling Fraction",IDC_SPINNER_GPT_FIXED_BSDF_SAMPLING_FRACTION,
"SpinnerControl",WS_TABSTOP,138,388,6,10
GROUPBOX "BSDF / SD-Tree Sampling Fraction",IDC_STATIC,4,345,190,56
GROUPBOX "Path Continuation",IDC_STATIC,4,300,190,42
CONTROL "Enable Guided Path Tracing",IDC_CHECK_GPT_ENABLE_PATH_GUIDING,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,227,105,10
GROUPBOX "Guided Path Tracing",IDC_STATIC,0,215,198,190
END

IDD_FORMVIEW_RENDERERPARAMS_SYSTEM DIALOGEX 0, 0, 200, 96
Expand Down Expand Up @@ -350,6 +386,12 @@ BEGIN
"SpinnerControl",WS_TABSTOP,125,140,6,10
END

IDD_FORMVIEW_RENDERERPARAMS_GUIDED_PATH_TRACING DIALOGEX 0, 0, 200, 17
STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
END


/////////////////////////////////////////////////////////////////////////////
//
Expand All @@ -371,6 +413,7 @@ BEGIN

IDD_FORMVIEW_RENDERERPARAMS_PATH_TRACING, DIALOG
BEGIN
BOTTOMMARGIN, 228
END

IDD_FORMVIEW_RENDERERPARAMS_SYSTEM, DIALOG
Expand Down Expand Up @@ -401,6 +444,11 @@ BEGIN
BEGIN
BOTTOMMARGIN, 288
END

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

Expand Down Expand Up @@ -450,6 +498,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 @@ -646,6 +646,7 @@ struct AppleseedRendererParamDlg::Impl

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

}
};

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;
161 changes: 156 additions & 5 deletions src/appleseed-max-impl/appleseedrenderer/renderersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ namespace
m_max_ray_intensity = 1.0f;
m_clamp_roughness = false;

m_gpt_enable_path_guiding = 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 +204,8 @@ 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
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,18 +328,26 @@ 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();

params.insert_path("sampling_mode", "qmc");
params.insert_path("lighting_engine", get_lighting_engine_type(m_lighting_algorithm));

if (m_gpt_enable_path_guiding)
params.insert_path("lighting_engine", "gpt");
else params.insert_path("lighting_engine", get_lighting_engine_type(m_lighting_algorithm));


if (m_enable_light_importance_sampling)
params.insert_path("light_sampler.enable_importance_sampling", m_enable_light_importance_sampling);

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 @@ -292,11 +376,16 @@ void RendererSettings::apply_common_settings(asr::Project& project, const char*
params.insert_path("pt.rr_min_path_length", m_rr_min_path_length);
params.insert_path("pt.volume_distance_samples", m_volume_distance_samples);
params.insert_path("pt.optimize_for_lights_outside_volumes", m_optimize_for_lights_outside_volumes);
params.insert_path("pt.clamp_roughness", m_clamp_roughness);

// Disable roughness clamping for guided path tracing.
if (!m_gpt_enable_path_guiding)
params.insert_path("pt.clamp_roughness", m_clamp_roughness);

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 +411,57 @@ 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.enable_caustics", m_enable_caustics);
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 +473,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 +507,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
16 changes: 16 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,22 @@ class RendererSettings
int m_rr_min_path_length;
bool m_optimize_for_lights_outside_volumes;

//
// Guided Path Tracer.
//

bool m_gpt_enable_path_guiding;
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