From b27c6600227fa4aca648baf831100fc60469a7bb Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Mon, 22 May 2023 12:20:48 -0600 Subject: [PATCH] lightpreview: add fullbright checkbox --- lightpreview/glview.cpp | 11 ++++++++++- lightpreview/glview.h | 3 +++ lightpreview/mainwindow.cpp | 5 ++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lightpreview/glview.cpp b/lightpreview/glview.cpp index 3f9fee7d..27d78485 100644 --- a/lightpreview/glview.cpp +++ b/lightpreview/glview.cpp @@ -79,10 +79,11 @@ uniform sampler2D texture_sampler; uniform sampler2D lightmap_sampler; uniform float opacity; uniform bool lightmap_only; +uniform bool fullbright; void main() { vec3 texcolor = lightmap_only ? vec3(0.5) : texture(texture_sampler, uv).rgb; - vec3 lmcolor = texture(lightmap_sampler, lightmap_uv).rgb; + vec3 lmcolor = fullbright ? vec3(0.5) : texture(lightmap_sampler, lightmap_uv).rgb; // 2.0 for overbright color = vec4(texcolor * lmcolor * 2.0, opacity); @@ -126,6 +127,7 @@ void GLView::initializeGL() m_program_lightmap_sampler_location = m_program->uniformLocation("lightmap_sampler"); m_program_opacity_location = m_program->uniformLocation("opacity"); m_program_lightmap_only_location = m_program->uniformLocation("lightmap_only"); + m_program_fullbright_location = m_program->uniformLocation("fullbright"); m_vao.create(); glEnable(GL_DEPTH_TEST); @@ -154,6 +156,7 @@ void GLView::paintGL() m_program->setUniformValue(m_program_lightmap_sampler_location, 1 /* texture unit */); m_program->setUniformValue(m_program_opacity_location, 1.0f); m_program->setUniformValue(m_program_lightmap_only_location, m_lighmapOnly); + m_program->setUniformValue(m_program_fullbright_location, m_fullbright); // opaque draws for (auto &draw : m_drawcalls) { @@ -207,6 +210,12 @@ void GLView::setLighmapOnly(bool lighmapOnly) update(); } +void GLView::setFullbright(bool fullbright) +{ + m_fullbright = fullbright; + update(); +} + void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const std::vector &entities) { // FIXME: move to a lightpreview_settings diff --git a/lightpreview/glview.h b/lightpreview/glview.h index 05c6855a..65b74c74 100644 --- a/lightpreview/glview.h +++ b/lightpreview/glview.h @@ -73,6 +73,7 @@ private: // render options bool m_lighmapOnly = false; + bool m_fullbright = false; QOpenGLVertexArrayObject m_vao; QOpenGLBuffer m_vbo; @@ -96,6 +97,7 @@ private: int m_program_lightmap_sampler_location = 0; int m_program_opacity_location = 0; int m_program_lightmap_only_location = 0; + int m_program_fullbright_location = 0; public: GLView(QWidget *parent = nullptr); @@ -104,6 +106,7 @@ public: void renderBSP(const QString &file, const mbsp_t &bsp, const std::vector &entities); void setCamera(const qvec3d &origin, const qvec3d &fwd); void setLighmapOnly(bool lighmapOnly); + void setFullbright(bool fullbright); protected: void initializeGL() override; diff --git a/lightpreview/mainwindow.cpp b/lightpreview/mainwindow.cpp index 593a766b..556bcdb0 100644 --- a/lightpreview/mainwindow.cpp +++ b/lightpreview/mainwindow.cpp @@ -56,12 +56,14 @@ MainWindow::MainWindow(QWidget *parent) light_options = new QLineEdit(); auto *reload_button = new QPushButton(tr("Reload")); auto *lightmap_only = new QCheckBox(tr("Lightmap Only")); + auto *fullbright = new QCheckBox(tr("Fullbright")); formLayout->addRow(tr("qbsp"), qbsp_options); formLayout->addRow(vis_checkbox, vis_options); formLayout->addRow(tr("light"), light_options); formLayout->addRow(reload_button); formLayout->addRow(lightmap_only); + formLayout->addRow(fullbright); auto *form = new QWidget(); form->setLayout(formLayout); @@ -86,7 +88,8 @@ MainWindow::MainWindow(QWidget *parent) connect(reload_button, &QAbstractButton::clicked, this, &MainWindow::reload); connect( - lightmap_only, &QCheckBox::stateChanged, this, [&]() { glView->setLighmapOnly(lightmap_only->isChecked()); }); + lightmap_only, &QCheckBox::stateChanged, this, [=]() { glView->setLighmapOnly(lightmap_only->isChecked()); }); + connect(fullbright, &QCheckBox::stateChanged, this, [=]() { glView->setFullbright(fullbright->isChecked()); }); } MainWindow::~MainWindow() { }