From bd8c5ed59a705619ea72363e06c5c5d6ab5547a5 Mon Sep 17 00:00:00 2001 From: milek7 Date: Sun, 9 Dec 2018 19:55:53 +0100 Subject: [PATCH] debug configurable headlight --- gl/glsl_common.cpp | 1 + gl/ubo.h | 3 ++- renderer.cpp | 21 +++++++++++++++++---- renderer.h | 2 ++ shaders/light_common.glsl | 3 ++- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/gl/glsl_common.cpp b/gl/glsl_common.cpp index a65931c6..c818dc1d 100644 --- a/gl/glsl_common.cpp +++ b/gl/glsl_common.cpp @@ -31,6 +31,7 @@ void gl::glsl_common_setup() float linear; float quadratic; + float ambient; }; layout(std140) uniform light_ubo diff --git a/gl/ubo.h b/gl/ubo.h index 690f7c3e..eb95c379 100644 --- a/gl/ubo.h +++ b/gl/ubo.h @@ -88,7 +88,8 @@ namespace gl float linear; float quadratic; - UBS_PAD(8); + 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 5e6c8b5a..6f1933ff 100644 --- a/renderer.cpp +++ b/renderer.cpp @@ -633,6 +633,17 @@ 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"); Application.render_ui(); @@ -3700,11 +3711,12 @@ 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 = 0.997f; - l->out_cutoff = 0.99f; + l->in_cutoff = in_cutoff; + l->out_cutoff = out_cutoff; l->color = renderlight->diffuse * renderlight->factor; - l->linear = 0.007f; - l->quadratic = 0.0002f; + l->linear = linear / 10.0f; + l->quadratic = quadratic / 100.0f; + l->ambient = ambient; light_i++; ++renderlight; @@ -3714,6 +3726,7 @@ void opengl_renderer::Update_Lights(light_array &Lights) light_ubs.lights[0].type = gl::light_element_ubs::DIR; 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_count = light_i; light_ubs.fog_color = Global.FogColor; diff --git a/renderer.h b/renderer.h index 2a42624b..85bb2963 100644 --- a/renderer.h +++ b/renderer.h @@ -411,6 +411,8 @@ class opengl_renderer bool m_blendingenabled; bool m_widelines_supported; + + float in_cutoff=0.997f, out_cutoff=0.99f, linear=0.07f, quadratic=0.02f, ambient=0.25f; }; extern opengl_renderer GfxRenderer; diff --git a/shaders/light_common.glsl b/shaders/light_common.glsl index 2f68bbee..d70a5c67 100644 --- a/shaders/light_common.glsl +++ b/shaders/light_common.glsl @@ -44,7 +44,7 @@ vec2 calc_light(vec3 light_dir) #endif vec3 view_dir = normalize(vec3(0.0f, 0.0f, 0.0f) - f_pos.xyz); vec3 halfway_dir = normalize(light_dir + view_dir); - + float diffuse_v = max(dot(normal, light_dir), 0.0); float specular_v = pow(max(dot(normal, halfway_dir), 0.0), 15.0); @@ -55,6 +55,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; float distance = length(light.pos - f_pos.xyz); float atten = 1.0f / (1.0f + light.linear * distance + light.quadratic * (distance * distance));