Commit f7dc2c68 authored by Florian Oetke's avatar Florian Oetke
Browse files

ui for renderer configuration (fixes #40)

parent a08828a0
......@@ -46,7 +46,13 @@ vec3 expose(vec3 color, float threshold) {
float avg_luminance = max(exp(texture(avg_log_luminance_sampler, vec2(0.5, 0.5)).r), 0.001);
float key = 1.03f - (2.0f / (2 + log(avg_luminance + 1)/log(10)));
float exposure = log2(clamp(key/avg_luminance, 1, 12.0) + 0.5);
float exposure = clamp(key/avg_luminance, 0.1, 12.0) + 0.5;
if(pcs.options.z>0) {
exposure = pcs.options.z;
}
exposure = log2(exposure);
exposure -= threshold;
return color * exp2(exposure);
......
......@@ -24,10 +24,16 @@ vec3 expose(vec3 color, float threshold) {
float avg_luminance = max(exp(texture(avg_log_luminance_sampler, vec2(0.5, 0.5)).r), 0.001);
float key = 1.03f - (2.0f / (2 + log(avg_luminance + 1)/log(10)));
float exposure = log2(clamp(key/avg_luminance, 1, 20.0) + 0.5);
float exposure = clamp(key/avg_luminance, 0.1, 20.0) + 0.5;
if(pcs.options.z>0) {
exposure = pcs.options.z;
}
exposure = log2(exposure);
exposure -= threshold;
return max(color * exp2(exposure), vec3(0));
return color * exp2(exposure);
}
void main() {
......
......@@ -141,7 +141,7 @@ vec3 gi_sample(int lod, int base_mip) {
// float visibility = 1.0 - (samples_used / float(SAMPLES));
if(PRIORITISE_NEAR_SAMPLES==1)
c = c * pow(2.0, clamp((lod-base_mip)*2, 4, 7));
c = c * pow(2.0, clamp((lod-base_mip)*2, 4, 8));
else
c = c * pow(2.0, (lod-base_mip)*2);
......
......@@ -86,7 +86,7 @@ float sample_ao(ivec2 ss_center, vec3 C, vec3 n_C, float ss_disk_radius, int i,
vec3 N = get_normal(ss_p, mip);
float occluder_angle = abs(dot(N, n_C));
float boost = smoothstep(0.01, 0.2, occluder_angle)*0.5+0.5;
float boost = smoothstep(0.01, 0.2, occluder_angle)*0.6+0.4;
boost += smoothstep(0.8, 1.0, occluder_angle)*2;
float f = max(RADIUS*RADIUS - vv, 0.0);
......
......@@ -85,7 +85,6 @@ namespace mirrage {
_meta_system.nims().stop();
_set_preset(1);
} else {
std::terminate();
_engine.screens().leave();
}
break;
......@@ -100,7 +99,7 @@ namespace mirrage {
case "d_disect"_strid: {
auto s = _meta_system.renderer().settings();
s.debug_disect = !s.debug_disect;
_meta_system.renderer().settings(s);
_meta_system.renderer().settings(s, false);
_set_preset(0);
break;
}
......@@ -230,11 +229,9 @@ namespace mirrage {
_sun.get<renderer::Directional_light_comp>().process(
[&](renderer::Directional_light_comp& light) { light.temperature(_sun_color_temperature); });
auto s = _meta_system.renderer().settings();
//if(s.debug_disect != p.disect_model) {
auto s = _meta_system.renderer().settings();
s.debug_disect = p.disect_model;
_meta_system.renderer().settings(s);
//}
_meta_system.renderer().settings(s, false);
_update_sun_position();
}
......@@ -332,18 +329,10 @@ namespace mirrage {
if(nk_begin_titled(ctx,
"debug_controls",
"Debug Controls",
_gui.centered_left(220, 260),
_gui.centered_left(250, 570),
NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_TITLE | NK_WINDOW_MINIMIZABLE)) {
nk_layout_row_dynamic(ctx, 20, 2);
nk_label(ctx, "Debug Layer", NK_TEXT_LEFT);
auto& renderer_settings = _meta_system.renderer().settings();
auto dgil = nk_propertyi(ctx, "gi_layer", -1, renderer_settings.debug_gi_layer, 5, 1, 0.1);
if(dgil != renderer_settings.debug_gi_layer) {
auto rs_copy = renderer_settings;
rs_copy.debug_gi_layer = dgil;
_meta_system.renderer().settings(rs_copy);
}
nk_label(ctx, "Preset", NK_TEXT_LEFT);
auto preset_options = std::array<const char*, 7>{{"Free Motion",
......@@ -361,17 +350,9 @@ namespace mirrage {
nk_vec2(100.f, 200)));
nk_label(ctx, "Indirect illumination", NK_TEXT_LEFT);
int gi_active = renderer_settings.gi ? 1 : 0;
if(nk_checkbox_label(ctx, "GI", &gi_active) && renderer_settings.gi != (gi_active == 1)) {
auto rs_copy = renderer_settings;
rs_copy.gi = gi_active == 1;
_meta_system.renderer().settings(rs_copy);
}
nk_label(ctx, "Show profiler", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 20, 1);
auto show_profiler = _show_profiler ? 1 : 0;
if(nk_checkbox_label(ctx, "Profiler", &show_profiler)) {
if(nk_checkbox_label(ctx, "Show profiler", &show_profiler)) {
_show_profiler = show_profiler == 1;
}
......@@ -418,6 +399,62 @@ namespace mirrage {
}
});
}
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "Graphic Settings", NK_TEXT_LEFT);
auto renderer_settings = _meta_system.renderer().settings();
auto bool_nk_wrapper = 0;
nk_layout_row_dynamic(ctx, 20, 1);
nk_property_int(ctx, "Debug Layer", -1, &renderer_settings.debug_gi_layer, 5, 1, 1);
bool_nk_wrapper = renderer_settings.gi ? 1 : 0;
nk_checkbox_label(ctx, "Indirect Illumination", &bool_nk_wrapper);
renderer_settings.gi = bool_nk_wrapper == 1;
bool_nk_wrapper = renderer_settings.gi_highres ? 1 : 0;
nk_checkbox_label(ctx, "High Resolution GI", &bool_nk_wrapper);
renderer_settings.gi_highres = bool_nk_wrapper == 1;
nk_property_int(ctx, "Minimum GI MIP", 0, &renderer_settings.gi_min_mip_level, 4, 1, 1);
nk_property_int(ctx, "Diffuse GI MIP", 0, &renderer_settings.gi_diffuse_mip_level, 4, 1, 1);
nk_property_int(ctx, "Sample Count", 8, &renderer_settings.gi_samples, 256, 1, 1);
bool_nk_wrapper = renderer_settings.gi_prioritise_near_samples ? 1 : 0;
nk_checkbox_label(ctx, "Prioritise near samples", &bool_nk_wrapper);
renderer_settings.gi_prioritise_near_samples = bool_nk_wrapper == 1;
nk_property_int(
ctx, "Low-Quality MIP-Levels", 0, &renderer_settings.gi_low_quality_mip_levels, 8, 1, 1);
nk_property_float(ctx, "Exposure", 0.f, &renderer_settings.exposure_override, 50.f, 0.01, 0.1);
nk_property_float(
ctx, "Background brightness", 0.f, &renderer_settings.background_intensity, 10.f, 1, 0.1);
bool_nk_wrapper = renderer_settings.ssao ? 1 : 0;
nk_checkbox_label(ctx, "Ambient Occlusion", &bool_nk_wrapper);
renderer_settings.ssao = bool_nk_wrapper == 1;
bool_nk_wrapper = renderer_settings.bloom ? 1 : 0;
nk_checkbox_label(ctx, "Bloom", &bool_nk_wrapper);
renderer_settings.bloom = bool_nk_wrapper == 1;
nk_layout_row_dynamic(ctx, 20, 1);
if(nk_button_label(ctx, "Apply")) {
_meta_system.renderer().settings(renderer_settings, true);
} else {
_meta_system.renderer().settings(renderer_settings, false);
}
if(nk_button_label(ctx, "Reset")) {
_meta_system.renderer().settings(renderer::Renderer_settings{}, true);
}
}
nk_end(ctx);
}
......@@ -478,9 +515,11 @@ namespace mirrage {
_meta_system.renderer().profiler().reset();
}
#if 0
if(_performance_log.is_nothing() && nk_button_label(ctx, "Record")) {
_performance_log = _engine.assets().save_raw("log:perf.log"_aid);
}
#endif
constexpr auto rows = std::array<float, 5>{{0.4f, 0.15f, 0.15f, 0.15f, 0.15f}};
nk_layout_row(ctx, NK_DYNAMIC, 25, rows.size(), rows.data());
......
......@@ -158,7 +158,7 @@ namespace mirrage::graphic {
return _memory_allocator.is_unified_memory_architecture();
}
auto max_frames_in_flight() const noexcept { return _delete_queue.capacity() + 1; }
auto max_frames_in_flight() const noexcept { return _delete_queue.capacity() + 2; }
auto vk_device() const noexcept { return &*_device; }
......
......@@ -33,13 +33,16 @@ namespace mirrage::renderer {
bool gi = true;
bool gi_highres = true;
int gi_diffuse_mip_level = 1;
int gi_specular_mip_level = 0;
int gi_min_mip_level = 0;
int gi_samples = 128;
bool gi_prioritise_near_samples = true;
bool gi_low_quality_mip_levels = 0;
float exposure_override = -1.f;
int gi_low_quality_mip_levels = 0;
float exposure_override = 0.f;
bool ssao = true;
bool ssao = true;
bool bloom = true;
float background_intensity = 1.f;
bool dynamic_shadows = false;
bool debug_disect = false;
......
......@@ -25,7 +25,6 @@ namespace mirrage::renderer {
const int _base_mip_level;
const int _max_mip_level;
const int _diffuse_mip_level;
const int _specular_mip_level;
const int _min_mip_level;
vk::UniqueSampler _gbuffer_sampler;
graphic::Image_descriptor_set_layout _descriptor_set_layout;
......
......@@ -103,9 +103,12 @@ namespace mirrage::renderer {
auto descriptor_sets = std::array<vk::DescriptorSet, 2>{global_uniform_set, *_descriptor_set};
_render_pass.bind_descriptor_sets(0, descriptor_sets);
_render_pass.push_constant(
"settings"_strid,
glm::vec4(_tone_mapping_enabled ? 1 : 0, _bloom_enabled ? 50 : 0, 0, 0));
glm::vec4 settings;
settings.x = _tone_mapping_enabled ? 1 : 0;
settings.y = _bloom_enabled && _renderer.settings().bloom ? 20 : 0;
settings.z = _renderer.settings().exposure_override;
_render_pass.push_constant("settings"_strid, settings);
command_buffer.draw(3, 1, 0, 0);
});
......
......@@ -230,7 +230,8 @@ namespace mirrage::renderer {
std::size_t) {
auto pcs = Push_constants{};
pcs.parameters.x = 8.0f; // TODO: make configurable
pcs.parameters.x = 8.0f; // bloom threshold
pcs.parameters.z = _renderer.settings().exposure_override;
// filter
_filter_renderpass.execute(command_buffer, _filter_framebuffer, [&] {
......
......@@ -150,10 +150,13 @@ namespace mirrage::renderer {
auto render_pass = builder.build();
auto sky_color = util::Rgba{temperature_to_color(25000.f) * 0.1f, 1};
sky_color *= renderer.settings().background_intensity;
auto attachments = std::array<Framebuffer_attachment_desc, 6>{
{{depth_buffer.view(0), 1.f},
{gbuffer.depth.view(0), util::Rgba(1.f)},
{gbuffer.albedo_mat_id.view(0), util::Rgba{temperature_to_color(25000.f) * 0.1f, 1}},
{gbuffer.albedo_mat_id.view(0), sky_color},
{gbuffer.mat_data.view(0), util::Rgba{0, 0, 0, 0}},
{color_target.view(0), util::Rgba{0, 0, 0, 0}},
{color_target_diff.view(0), util::Rgba{0, 0, 0, 0}}}};
......
......@@ -121,9 +121,7 @@ namespace mirrage::renderer {
vk::DescriptorSet global_uniform_set,
std::size_t) {
// importance-based mip-map shader produces slidely more artiacts than hardware mip-mapping (and is slower)
// => disabled for now
const auto low_quality_levels = 2u; //_renderer.gbuffer().mip_levels;//1u;
const auto low_quality_levels = util::max(1, _renderer.settings().gi_low_quality_mip_levels + 1);
if(low_quality_levels > 1) {
// blit the first level
......@@ -148,7 +146,7 @@ namespace mirrage::renderer {
}
// generate mipmaps for GBuffer
for(auto i = low_quality_levels; i < _renderer.gbuffer().mip_levels; i++) {
for(auto i = low_quality_levels; i < gsl::narrow<int>(_renderer.gbuffer().mip_levels); i++) {
auto& fb = _mipmap_gen_framebuffers.at(i - 1);
// barrier against write to previous mipmap level
......
......@@ -191,6 +191,8 @@ namespace mirrage::renderer {
vk::DescriptorSetLayout desc_set_layout,
int min_mip_level,
int max_mip_level,
int sample_count,
bool prioritise_near_samples,
Render_target_2D& gi_buffer,
std::vector<Framebuffer>& out_framebuffers) {
......@@ -223,11 +225,25 @@ namespace mirrage::renderer {
color, graphic::all_color_components, graphic::blend_premultiplied_alpha);
pass.stage("sample"_strid)
.shader("frag_shader:gi_sample"_aid, graphic::Shader_stage::fragment)
.shader("frag_shader:gi_sample"_aid,
graphic::Shader_stage::fragment,
"main",
2,
sample_count,
4,
prioritise_near_samples ? 1 : 0)
.shader("vert_shader:gi_sample"_aid, graphic::Shader_stage::vertex);
pass.stage("sample_last"_strid)
.shader("frag_shader:gi_sample"_aid, graphic::Shader_stage::fragment, "main", 0, 1)
.shader("frag_shader:gi_sample"_aid,
graphic::Shader_stage::fragment,
"main",
0,
1,
2,
sample_count,
4,
prioritise_near_samples ? 1 : 0)
.shader("vert_shader:gi_sample"_aid, graphic::Shader_stage::vertex);
pass.stage("upsample"_strid)
......@@ -508,8 +524,7 @@ namespace mirrage::renderer {
, _base_mip_level(calc_base_mip_level(in_out.width(), in_out.height(), renderer.settings().gi_highres))
, _max_mip_level(calc_max_mip_level(in_out.width(), in_out.height()))
, _diffuse_mip_level(_base_mip_level + renderer.settings().gi_diffuse_mip_level)
, _specular_mip_level(_base_mip_level + renderer.settings().gi_specular_mip_level)
, _min_mip_level(std::min(_diffuse_mip_level, _specular_mip_level))
, _min_mip_level(std::min(_diffuse_mip_level, _base_mip_level + renderer.settings().gi_min_mip_level))
, _gbuffer_sampler(renderer.device().create_sampler(12,
vk::SamplerAddressMode::eClampToEdge,
vk::BorderColor::eIntOpaqueBlack,
......@@ -584,20 +599,21 @@ namespace mirrage::renderer {
_gi_specular,
_history_weight,
_reproject_framebuffer))
, _reproject_descriptor_set(_descriptor_set_layout.create_set(
renderer.descriptor_pool(),
{renderer.gbuffer().depth.view(),
renderer.gbuffer().mat_data.view(),
renderer.gbuffer().albedo_mat_id.view(0),
_gi_diffuse_history.view(),
_gi_specular_history.view(),
renderer.gbuffer().prev_depth.view(),
_integrated_brdf.view()}))
, _reproject_descriptor_set(_descriptor_set_layout.create_set(renderer.descriptor_pool(),
{renderer.gbuffer().depth.view(),
renderer.gbuffer().mat_data.view(),
renderer.gbuffer().albedo_mat_id.view(0),
_gi_diffuse_history.view(),
_gi_specular_history.view(),
renderer.gbuffer().prev_depth.view(),
_integrated_brdf.view()}))
, _sample_renderpass(build_sample_render_pass(renderer,
*_descriptor_set_layout,
_min_mip_level,
_max_mip_level,
renderer.settings().gi_samples,
renderer.settings().gi_prioritise_near_samples,
_gi_diffuse,
_sample_framebuffers))
......@@ -623,16 +639,16 @@ namespace mirrage::renderer {
, _blend_renderpass(
build_blend_render_pass(renderer, *_descriptor_set_layout, _color_in_out, _blend_framebuffer))
, _blend_descriptor_set(_descriptor_set_layout.create_set(
renderer.descriptor_pool(),
{renderer.gbuffer().depth.view(0),
renderer.gbuffer().mat_data.view(0),
renderer.gbuffer().depth.view(_base_mip_level),
renderer.gbuffer().mat_data.view(_base_mip_level),
_gi_diffuse.view(),
_gi_specular.view(),
renderer.gbuffer().albedo_mat_id.view(0),
_integrated_brdf.view()})) {
, _blend_descriptor_set(
_descriptor_set_layout.create_set(renderer.descriptor_pool(),
{renderer.gbuffer().depth.view(0),
renderer.gbuffer().mat_data.view(0),
renderer.gbuffer().depth.view(_base_mip_level),
renderer.gbuffer().mat_data.view(_base_mip_level),
_gi_diffuse.view(),
_gi_specular.view(),
renderer.gbuffer().albedo_mat_id.view(0),
_integrated_brdf.view()})) {
auto end = _max_mip_level;
_sample_descriptor_sets.reserve(end - _min_mip_level);
for(auto i = 0; i < end - _min_mip_level; i++) {
......
......@@ -222,6 +222,16 @@ namespace mirrage::renderer {
vk::DescriptorSet global_uniform_set,
std::size_t) {
if(!_renderer.settings().ssao) {
graphic::clear_texture(command_buffer,
_ao_result_buffer,
util::Rgba{1, 1, 1, 1},
vk::ImageLayout::eUndefined,
vk::ImageLayout::eShaderReadOnlyOptimal);
return;
}
auto descriptor_sets = std::array<vk::DescriptorSet, 2>{global_uniform_set, *_ssao_descriptor_set};
Push_constants pcs;
......
......@@ -5,8 +5,7 @@ namespace mirrage::renderer {
namespace {
struct Push_constants {
glm::vec4 parameters; // tau (controls adjustment speed), active sampler
// TODO
glm::vec4 parameters;
};
auto build_luminance_render_pass(Deferred_renderer& renderer,
......@@ -215,12 +214,14 @@ namespace mirrage::renderer {
std::size_t) {
auto pcs = Push_constants{};
pcs.parameters.x = 0.08f; // TODO: make configurable
pcs.parameters.y = 0.8f; // TODO: make configurable
pcs.parameters.x = 0.08f; // adjustment speed if current luminance > previous
pcs.parameters.y = 0.8f; // adjustment speed if current luminance <= previous
if(_first_frame) {
_first_frame = false;
pcs.parameters.x = pcs.parameters.y = 999.f;
constexpr auto initial_lum = -40.f;
graphic::clear_texture(command_buffer,
_prev_avg_luminance,
......
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