diff --git a/lightpreview/glview.cpp b/lightpreview/glview.cpp index a26f4a72..3f9fee7d 100644 --- a/lightpreview/glview.cpp +++ b/lightpreview/glview.cpp @@ -78,9 +78,10 @@ out vec4 color; uniform sampler2D texture_sampler; uniform sampler2D lightmap_sampler; uniform float opacity; +uniform bool lightmap_only; void main() { - vec3 texcolor = texture(texture_sampler, uv).rgb; + vec3 texcolor = lightmap_only ? vec3(0.5) : texture(texture_sampler, uv).rgb; vec3 lmcolor = texture(lightmap_sampler, lightmap_uv).rgb; // 2.0 for overbright @@ -124,6 +125,7 @@ void GLView::initializeGL() m_program_texture_sampler_location = m_program->uniformLocation("texture_sampler"); 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_vao.create(); glEnable(GL_DEPTH_TEST); @@ -151,6 +153,7 @@ void GLView::paintGL() m_program->setUniformValue(m_program_texture_sampler_location, 0 /* texture unit */); 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); // opaque draws for (auto &draw : m_drawcalls) { @@ -198,6 +201,12 @@ void GLView::setCamera(const qvec3d &origin, const qvec3d &fwd) m_cameraFwd = {(float)fwd[0], (float)fwd[1], (float)fwd[2]}; } +void GLView::setLighmapOnly(bool lighmapOnly) +{ + m_lighmapOnly = lighmapOnly; + 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 3a8bb9ea..05c6855a 100644 --- a/lightpreview/glview.h +++ b/lightpreview/glview.h @@ -71,6 +71,9 @@ private: return v; } + // render options + bool m_lighmapOnly = false; + QOpenGLVertexArrayObject m_vao; QOpenGLBuffer m_vbo; QOpenGLBuffer m_indexBuffer; @@ -92,6 +95,7 @@ private: int m_program_texture_sampler_location = 0; int m_program_lightmap_sampler_location = 0; int m_program_opacity_location = 0; + int m_program_lightmap_only_location = 0; public: GLView(QWidget *parent = nullptr); @@ -99,6 +103,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); protected: void initializeGL() override; diff --git a/lightpreview/mainwindow.cpp b/lightpreview/mainwindow.cpp index fa4a163f..593a766b 100644 --- a/lightpreview/mainwindow.cpp +++ b/lightpreview/mainwindow.cpp @@ -55,11 +55,13 @@ MainWindow::MainWindow(QWidget *parent) vis_options = new QLineEdit(); light_options = new QLineEdit(); auto *reload_button = new QPushButton(tr("Reload")); + auto *lightmap_only = new QCheckBox(tr("Lightmap Only")); 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); auto *form = new QWidget(); form->setLayout(formLayout); @@ -83,6 +85,8 @@ MainWindow::MainWindow(QWidget *parent) // setup event handlers connect(reload_button, &QAbstractButton::clicked, this, &MainWindow::reload); + connect( + lightmap_only, &QCheckBox::stateChanged, this, [&]() { glView->setLighmapOnly(lightmap_only->isChecked()); }); } MainWindow::~MainWindow() { } @@ -254,24 +258,19 @@ void MainWindow::loadFileInternal(const QString &file, bool is_reload) glView->renderBSP(file, bsp, ents); - if (!is_reload) - { - for (auto &ent : ents) - { - if (ent.get("classname") == "info_player_start") - { + if (!is_reload) { + for (auto &ent : ents) { + if (ent.get("classname") == "info_player_start") { qvec3d origin; ent.get_vector("origin", origin); - qvec3d angles {}; + qvec3d angles{}; - if (ent.has("angles")) - { + if (ent.has("angles")) { ent.get_vector("angles", angles); - angles = { angles[1], -angles[0], angles[2] }; // -pitch yaw roll -> yaw pitch roll - } - else if (ent.has("angle")) - angles = { ent.get_float("angle"), 0, 0 }; + angles = {angles[1], -angles[0], angles[2]}; // -pitch yaw roll -> yaw pitch roll + } else if (ent.has("angle")) + angles = {ent.get_float("angle"), 0, 0}; else if (ent.has("mangle")) ent.get_vector("mangle", angles);