From c0d824a6bd48ab7fe5aee9658a6c6c1923d4b6a1 Mon Sep 17 00:00:00 2001 From: milek7 Date: Sun, 9 Dec 2018 21:14:31 +0100 Subject: [PATCH] tune headlight parameters, refactor config window --- gl/glsl_common.cpp | 2 ++ gl/ubo.h | 2 +- renderer.cpp | 46 +++++++++++++++++++++++++-------------- renderer.h | 18 ++++++++++++++- shaders/light_common.glsl | 1 + uilayer.cpp | 2 ++ 6 files changed, 53 insertions(+), 18 deletions(-) diff --git a/gl/glsl_common.cpp b/gl/glsl_common.cpp index c818dc1d..fd2bfd69 100644 --- a/gl/glsl_common.cpp +++ b/gl/glsl_common.cpp @@ -31,6 +31,8 @@ void gl::glsl_common_setup() float linear; float quadratic; + + float intensity; float ambient; }; diff --git a/gl/ubo.h b/gl/ubo.h index eb95c379..781e57a3 100644 --- a/gl/ubo.h +++ b/gl/ubo.h @@ -88,8 +88,8 @@ namespace gl float linear; float quadratic; + float intensity; float ambient; - UBS_PAD(4); }; static_assert(sizeof(light_element_ubs) == 64, "bad size of ubs"); diff --git a/renderer.cpp b/renderer.cpp index 6f1933ff..fb191219 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -442,6 +442,28 @@ void opengl_renderer::SwapBuffers() Timer::subsystem.gfx_swap.stop(); } +void opengl_renderer::draw_debug_ui() +{ + if (!debug_ui_active) + return; + + if (ImGui::Begin("headlight config", &debug_ui_active)) + { + ImGui::SetWindowSize(ImVec2(0, 0)); + + headlight_config_s &conf = headlight_config; + ImGui::SliderFloat("in_cutoff", &conf.in_cutoff, 0.9f, 1.1f); + ImGui::SliderFloat("out_cutoff", &conf.out_cutoff, 0.9f, 1.1f); + + ImGui::SliderFloat("falloff_linear", &conf.falloff_linear, 0.0f, 1.0f, "%.3f", 2.0f); + ImGui::SliderFloat("falloff_quadratic", &conf.falloff_quadratic, 0.0f, 1.0f, "%.3f", 2.0f); + + ImGui::SliderFloat("ambient", &conf.ambient, 0.0f, 3.0f); + ImGui::SliderFloat("intensity", &conf.intensity, 0.0f, 10.0f); + } + ImGui::End(); +} + // runs jobs needed to generate graphics for specified render pass void opengl_renderer::Render_pass(rendermode const Mode) { @@ -633,18 +655,8 @@ void opengl_renderer::Render_pass(rendermode const Mode) if (!Global.gfx_usegles && !Global.gfx_shadergamma) glDisable(GL_FRAMEBUFFER_SRGB); - if (DebugModeFlag) - { - ImGui::Begin("light conf"); - ImGui::SliderFloat("in_cutoff", &in_cutoff, 0.9f, 1.1f); - ImGui::SliderFloat("out_cutoff", &out_cutoff, 0.9f, 1.1f); - ImGui::SliderFloat("linear", &linear, 0.0f, 1.0f, "%.3f", 2.0f); - ImGui::SliderFloat("quadratic", &quadratic, 0.0f, 1.0f, "%.3f", 2.0f); - ImGui::SliderFloat("ambient", &ambient, 0.0f, 1.0f); - ImGui::End(); - } - glDebug("uilayer render"); + draw_debug_ui(); Application.render_ui(); // restore binding @@ -3711,12 +3723,13 @@ void opengl_renderer::Update_Lights(light_array &Lights) l->pos = mv * glm::vec4(renderlight->position, 1.0f); l->dir = mv * glm::vec4(renderlight->direction, 0.0f); l->type = gl::light_element_ubs::SPOT; - l->in_cutoff = in_cutoff; - l->out_cutoff = out_cutoff; + l->in_cutoff = headlight_config.in_cutoff; + l->out_cutoff = headlight_config.out_cutoff; l->color = renderlight->diffuse * renderlight->factor; - l->linear = linear / 10.0f; - l->quadratic = quadratic / 100.0f; - l->ambient = ambient; + l->linear = headlight_config.falloff_linear / 10.0f; + l->quadratic = headlight_config.falloff_quadratic / 100.0f; + l->ambient = headlight_config.ambient; + l->intensity = headlight_config.intensity; light_i++; ++renderlight; @@ -3727,6 +3740,7 @@ void opengl_renderer::Update_Lights(light_array &Lights) light_ubs.lights[0].dir = mv * glm::vec4(m_sunlight.direction, 0.0f); light_ubs.lights[0].color = m_sunlight.diffuse * m_sunlight.factor; light_ubs.lights[0].ambient = 0.0f; + light_ubs.lights[0].intensity = 1.0f; light_ubs.lights_count = light_i; light_ubs.fog_color = Global.FogColor; diff --git a/renderer.h b/renderer.h index 85bb2963..ffa355b2 100644 --- a/renderer.h +++ b/renderer.h @@ -194,6 +194,8 @@ class opengl_renderer GLenum static const sunlight{0}; std::size_t m_drawcount{0}; + bool debug_ui_active = false; + private: // types enum class rendermode @@ -277,6 +279,8 @@ class opengl_renderer void draw(const gfx::geometry_handle &handle); void draw(std::vector::iterator begin, std::vector::iterator end); + void draw_debug_ui(); + // members GLFWwindow *m_window{nullptr}; gfx::geometrybank_manager m_geometry; @@ -412,7 +416,19 @@ class opengl_renderer bool m_widelines_supported; - float in_cutoff=0.997f, out_cutoff=0.99f, linear=0.07f, quadratic=0.02f, ambient=0.25f; + struct headlight_config_s + { + float in_cutoff = 1.005f; + float out_cutoff = 0.993f; + + float falloff_linear = 0.069f; + float falloff_quadratic = 0.03f; + + float intensity = 1.0f; + float ambient = 0.184f; + }; + + headlight_config_s headlight_config; }; extern opengl_renderer GfxRenderer; diff --git a/shaders/light_common.glsl b/shaders/light_common.glsl index d70a5c67..f4a9ec78 100644 --- a/shaders/light_common.glsl +++ b/shaders/light_common.glsl @@ -56,6 +56,7 @@ vec2 calc_point_light(light_s light) vec3 light_dir = normalize(light.pos - f_pos.xyz); vec2 val = calc_light(light_dir); val.x += light.ambient; + val *= light.intensity; float distance = length(light.pos - f_pos.xyz); float atten = 1.0f / (1.0f + light.linear * distance + light.quadratic * (distance * distance)); diff --git a/uilayer.cpp b/uilayer.cpp index 7ecc0d3f..f1ab3498 100644 --- a/uilayer.cpp +++ b/uilayer.cpp @@ -368,6 +368,8 @@ void ui_layer::render_menu_contents() ImGui::MenuItem(LOC_STR(ui_log), "F9", &m_logpanel.is_open); if (Global.map_enabled && m_map) ImGui::MenuItem(LOC_STR(ui_map), "Tab", &m_map->map_opened); + if (DebugModeFlag) + ImGui::MenuItem("Headlight config", nullptr, &GfxRenderer.debug_ui_active); ImGui::EndMenu(); } }