version 1.2.1

spot light without shadows and with texture fix
mesh information
points width and points-only meshes support
This commit is contained in:
2023-05-25 15:50:07 +03:00
parent 85bc739987
commit dfc4c718e8
15 changed files with 180 additions and 56 deletions

View File

@@ -27,7 +27,7 @@ else()
set(QGLEngine_MAJOR 1) set(QGLEngine_MAJOR 1)
set(QGLEngine_MINOR 2) set(QGLEngine_MINOR 2)
set(QGLEngine_REVISION 0) set(QGLEngine_REVISION 1)
set(QGLEngine_SUFFIX "rc") set(QGLEngine_SUFFIX "rc")
set(QGLEngine_COMPANY SHS) set(QGLEngine_COMPANY SHS)
set(QGLEngine_DOMAIN org.SHS) set(QGLEngine_DOMAIN org.SHS)

View File

@@ -172,12 +172,24 @@ bool Mesh::rebuffer(QOpenGLExtraFunctions * f) {
buffer_geom.load(f, data_.constData(), gsize); buffer_geom.load(f, data_.constData(), gsize);
buffer_ind.bind(f); buffer_ind.bind(f);
if (geom_type == GL_TRIANGLES) { switch (geom_type) {
case GL_TRIANGLES:
buffer_ind.resize(f, tsize); buffer_ind.resize(f, tsize);
buffer_ind.load(f, triangles_.constData(), tsize); buffer_ind.load(f, triangles_.constData(), tsize);
} else { break;
case GL_LINES:
buffer_ind.resize(f, lsize); buffer_ind.resize(f, lsize);
buffer_ind.load(f, lines_.constData(), lsize); buffer_ind.load(f, lines_.constData(), lsize);
break;
case GL_POINTS: {
QVector<GLint> points;
points.resize(vertices_.size());
for (int i = 0; i < vertices_.size(); ++i)
points[i] = i;
int psize = points.size() * sizeof(GLint);
buffer_ind.resize(f, psize);
buffer_ind.load(f, points.constData(), psize);
} break;
} }
return !isEmpty(); return !isEmpty();
@@ -192,10 +204,12 @@ void Mesh::draw(QOpenGLExtraFunctions * f, int count, int type) {
VertexObject * vao = vaoByType(type); VertexObject * vao = vaoByType(type);
vao->bindBuffers(f, buffer_geom, buffer_ind); vao->bindBuffers(f, buffer_geom, buffer_ind);
if (geom_type == GL_TRIANGLES) switch (geom_type) {
vao->draw(f, geom_type, triangles_.size() * 3, count); case GL_TRIANGLES: vao->draw(f, geom_type, triangles_.size() * 3, count); break;
else case GL_LINES: vao->draw(f, geom_type, lines_.size() * 2, count); break;
vao->draw(f, geom_type, lines_.size() * 2, count); case GL_POINTS: vao->draw(f, geom_type, vertices_.size(), count); break;
default: break;
}
} }

View File

@@ -304,6 +304,24 @@ void Renderer::fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass) {
} }
void Renderer::setConeShadowMatrix() {
auto cone_ll = cur_lights.value(Light::Cone);
for (int i = 0; i < cone_ll.size(); ++i) {
Light * l = cone_ll[i];
QMatrix4x4 pm = glMatrixPerspective(l->angle_end, 1., 0.1), om, vm;
om.translate(-l->worldAim());
vm.translate(0., 0., -l->distance());
// vm.rotate(-roll_, 0., 0., 1.);
QMatrix4x4 pmat = l->worldTransform();
pmat(0, 3) = pmat(1, 3) = pmat(2, 3) = 0.;
vm *= pmat.inverted();
auto vpm = pm * (vm * om);
l->view_proj_matrix = vpm;
l->shadow_matrix = mat_norm_to_tex_coord * vpm * mat_camera_fullview_inv;
}
}
void Renderer::renderObjects(Scene & scene, RenderPass pass) { void Renderer::renderObjects(Scene & scene, RenderPass pass) {
QOpenGLExtraFunctions * f = view; QOpenGLExtraFunctions * f = view;
QMapIterator<Mesh *, ObjectBaseList> it(scene.geometries_used[pass]); QMapIterator<Mesh *, ObjectBaseList> it(scene.geometries_used[pass]);
@@ -403,20 +421,11 @@ void Renderer::renderConeShadows() {
} }
depth_maps_cone.resize(f, view->shadow_map_size, cone_ll.size()); depth_maps_cone.resize(f, view->shadow_map_size, cone_ll.size());
for (int i = 0; i < cone_ll.size(); ++i) { for (int i = 0; i < cone_ll.size(); ++i) {
Light * l = cone_ll[i]; Light * l = cone_ll[i];
QMatrix4x4 pm = glMatrixPerspective(l->angle_end, 1., 0.1), om, vm;
om.translate(-l->worldAim());
vm.translate(0., 0., -l->distance());
// vm.rotate(-roll_, 0., 0., 1.);
QMatrix4x4 pmat = l->worldTransform();
pmat(0, 3) = pmat(1, 3) = pmat(2, 3) = 0.;
vm *= pmat.inverted();
auto vpm = pm * (vm * om);
if (l->isCastShadows()) { if (l->isCastShadows()) {
prog->setUniformValue("qgl_ViewProjMatrix", vpm); prog->setUniformValue("qgl_ViewProjMatrix", l->view_proj_matrix);
renderConeShadow(i, l); renderConeShadow(i, l);
} }
l->shadow_matrix = mat_norm_to_tex_coord * vpm * mat_camera_fullview_inv;
} }
} }
} }
@@ -533,6 +542,9 @@ void Renderer::renderScene() {
} }
phase.end(); phase.end();
/// setup cone lights matrices
setConeShadowMatrix();
if (view->shadows()) { if (view->shadows()) {
/// cone shadows and shadow matrix /// cone shadows and shadow matrix
phase.begin("shadows cone"); phase.begin("shadows cone");

View File

@@ -116,6 +116,7 @@ public:
protected: protected:
void fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass); void fillObjectsBuffer(const ObjectBaseList & ol, RenderPass pass);
void setConeShadowMatrix();
void renderObjects(Scene & scene, RenderPass pass); void renderObjects(Scene & scene, RenderPass pass);
void renderLight(int first_wr_buff, bool clear_only); void renderLight(int first_wr_buff, bool clear_only);
void renderConeShadows(); void renderConeShadows();

View File

@@ -319,7 +319,7 @@ public:
float size; float size;
Type light_type; Type light_type;
Framebuffer shadow_map; Framebuffer shadow_map;
QMatrix4x4 shadow_matrix; QMatrix4x4 shadow_matrix, view_proj_matrix;
Map light_map; Map light_map;
}; };

View File

@@ -163,6 +163,8 @@ void QGLView::render() {
if (!framebuffer_size.isEmpty()) render_size = framebuffer_size; if (!framebuffer_size.isEmpty()) render_size = framebuffer_size;
resizeGL(render_size.width(), render_size.height()); resizeGL(render_size.width(), render_size.height());
emit glBeginPaint(); emit glBeginPaint();
glPointSize(lineWidth_);
glLineWidth(lineWidth_);
QSizeF fbo_sz = renderer_.fbo_ds.size(); QSizeF fbo_sz = renderer_.fbo_ds.size();
renderer_.rend_selection.size_coeff = {double(fbo_sz.width()) / pixelWidth(), double(fbo_sz.height()) / pixelHeight()}; renderer_.rend_selection.size_coeff = {double(fbo_sz.width()) / pixelWidth(), double(fbo_sz.height()) / pixelHeight()};
renderer_.mouse_pos = mapFromGlobal(QCursor::pos()) * devicePixelRatio(); renderer_.mouse_pos = mapFromGlobal(QCursor::pos()) * devicePixelRatio();

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

@@ -118,6 +118,7 @@ void MaterialsEditor::materialsChanged() {
return; return;
} }
Material * cm = currentMaterial(); Material * cm = currentMaterial();
ui->comboMaterial->blockSignals(true);
ui->comboMaterial->clear(); ui->comboMaterial->clear();
if (!view) return; if (!view) return;
QVector<Material *> mats = view->scene()->getMaterials(); QVector<Material *> mats = view->scene()->getMaterials();
@@ -128,6 +129,8 @@ void MaterialsEditor::materialsChanged() {
ui->comboMaterial->setItemIcon(i, QIcon(QPixmap::fromImage(view->materialThumbnail(m)))); ui->comboMaterial->setItemIcon(i, QIcon(QPixmap::fromImage(view->materialThumbnail(m))));
if (cm == m) ui->comboMaterial->setCurrentIndex(i); if (cm == m) ui->comboMaterial->setCurrentIndex(i);
} }
ui->comboMaterial->blockSignals(false);
if (currentMaterial() != cm) on_comboMaterial_currentIndexChanged(ui->comboMaterial->currentIndex());
} }

View File

@@ -19,11 +19,13 @@
#include "scene_tree.h" #include "scene_tree.h"
#include "glcamera.h" #include "glcamera.h"
#include "glmesh.h"
#include "qglview.h" #include "qglview.h"
#include "ui_scene_tree.h" #include "ui_scene_tree.h"
#include <QAction> #include <QAction>
#include <QEvent> #include <QEvent>
#include <QMessageBox>
#include <QScrollBar> #include <QScrollBar>
#include <QTreeWidget> #include <QTreeWidget>
#include <qad_types.h> #include <qad_types.h>
@@ -110,9 +112,9 @@ QList<QAction *> SceneTree::actionsAdd() {
QList<QAction *> SceneTree::actionsSelection() { QList<QAction *> SceneTree::actionsSelection() {
QList<QAction *> ret; QList<QAction *> ret;
ret << ui->actionFocus << newSeparator() << ui->actionGroup << ui->actionClone << newSeparator() << ui->actionSelect_parent ret << ui->actionFocus << newSeparator() << ui->actionGroup << ui->actionClone << newSeparator() << ui->actionSelect_parent
<< ui->actionSelect_by_mesh << ui->actionSelect_by_material << newSeparator() << ui->actionMove_to_parent << ui->actionSelect_by_mesh << ui->actionSelect_by_material << newSeparator() << ui->actionMesh_info << newSeparator()
<< ui->actionTransfer_transform_to_children << newSeparator() << ui->actionActive_camera << ui->actionDefault_camera << ui->actionMove_to_parent << ui->actionTransfer_transform_to_children << newSeparator() << ui->actionActive_camera
<< newSeparator() << ui->actionRemove; << ui->actionDefault_camera << newSeparator() << ui->actionRemove;
return ret; return ret;
} }
@@ -310,6 +312,7 @@ void SceneTree::checkActions() {
ui->actionSelect_parent->setEnabled(has_1); ui->actionSelect_parent->setEnabled(has_1);
ui->actionSelect_by_mesh->setEnabled(has_mesh); ui->actionSelect_by_mesh->setEnabled(has_mesh);
ui->actionSelect_by_material->setEnabled(has_mesh); ui->actionSelect_by_material->setEnabled(has_mesh);
ui->actionMesh_info->setEnabled(has_mesh);
ui->actionActive_camera->setEnabled(has_cam); ui->actionActive_camera->setEnabled(has_cam);
ui->actionDefault_camera->setEnabled(!is_def_cam); ui->actionDefault_camera->setEnabled(!is_def_cam);
} }
@@ -507,6 +510,31 @@ void SceneTree::on_actionSelect_by_material_triggered() {
} }
void SceneTree::on_actionMesh_info_triggered() {
if (!view) return;
ObjectBaseList sol = view->scene()->selectedObjects(true);
for (auto o: sol) {
if (o->mesh()) {
auto m = o->mesh();
int objects = 0;
ObjectBaseList aol = view->scene()->objects(true);
for (auto i: aol)
if (i->mesh() == m) ++objects;
auto bb = o->mesh()->boundingBox();
QString info;
QTextStream ts(&info);
ts << "Vertices: " << m->verticesCount() << "\n";
ts << "Triangles: " << m->trianglesCount() << "\n";
ts << "Bounding box: " << bb.length << "x" << bb.width << "x" << bb.height << "\n";
ts << "Objects with this mesh: " << objects << "\n";
QMessageBox::information(nullptr, tr("Mesh info"), info);
break;
}
}
}
void SceneTree::removeObjects() { void SceneTree::removeObjects() {
if (!view) return; if (!view) return;
QAD::CursorOverrider curov; QAD::CursorOverrider curov;

View File

@@ -88,6 +88,8 @@ private slots:
void on_actionSelect_by_mesh_triggered(); void on_actionSelect_by_mesh_triggered();
void on_actionSelect_by_material_triggered(); void on_actionSelect_by_material_triggered();
void on_actionMesh_info_triggered();
void objectsTreeChanged(); void objectsTreeChanged();
void selectionChanged(); void selectionChanged();
void materialsChanged(); void materialsChanged();

View File

@@ -130,7 +130,7 @@
</layout> </layout>
<action name="actionFocus"> <action name="actionFocus">
<property name="icon"> <property name="icon">
<iconset resource="../../../qad/libs/qglview/qglview.qrc"> <iconset resource="../core/qglengine_core.qrc">
<normaloff>:/icons/type-camera.png</normaloff>:/icons/type-camera.png</iconset> <normaloff>:/icons/type-camera.png</normaloff>:/icons/type-camera.png</iconset>
</property> </property>
<property name="text"> <property name="text">
@@ -175,7 +175,7 @@
</action> </action>
<action name="actionSelect_by_mesh"> <action name="actionSelect_by_mesh">
<property name="icon"> <property name="icon">
<iconset resource="../../../qad/libs/qglview/qglview.qrc"> <iconset resource="../core/qglengine_core.qrc">
<normaloff>:/icons/type-geo.png</normaloff>:/icons/type-geo.png</iconset> <normaloff>:/icons/type-geo.png</normaloff>:/icons/type-geo.png</iconset>
</property> </property>
<property name="text"> <property name="text">
@@ -235,7 +235,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../../../qad/libs/qglview/qglview.qrc"> <iconset resource="../core/qglengine_core.qrc">
<normaloff>:/icons/type-geo.png</normaloff>:/icons/type-geo.png</iconset> <normaloff>:/icons/type-geo.png</normaloff>:/icons/type-geo.png</iconset>
</property> </property>
<property name="text"> <property name="text">
@@ -247,7 +247,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../../../qad/libs/qglview/qglview.qrc"> <iconset resource="../core/qglengine_core.qrc">
<normaloff>:/icons/type-light.png</normaloff>:/icons/type-light.png</iconset> <normaloff>:/icons/type-light.png</normaloff>:/icons/type-light.png</iconset>
</property> </property>
<property name="text"> <property name="text">
@@ -259,7 +259,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../../../qad/libs/qglview/qglview.qrc"> <iconset resource="../core/qglengine_core.qrc">
<normaloff>:/icons/type-camera.png</normaloff>:/icons/type-camera.png</iconset> <normaloff>:/icons/type-camera.png</normaloff>:/icons/type-camera.png</iconset>
</property> </property>
<property name="text"> <property name="text">
@@ -273,7 +273,7 @@
</action> </action>
<action name="actionActive_camera"> <action name="actionActive_camera">
<property name="icon"> <property name="icon">
<iconset resource="../../../qad/libs/qglview/qglview.qrc"> <iconset resource="../core/qglengine_core.qrc">
<normaloff>:/icons/type-camera.png</normaloff>:/icons/type-camera.png</iconset> <normaloff>:/icons/type-camera.png</normaloff>:/icons/type-camera.png</iconset>
</property> </property>
<property name="text"> <property name="text">
@@ -282,7 +282,7 @@
</action> </action>
<action name="actionDefault_camera"> <action name="actionDefault_camera">
<property name="icon"> <property name="icon">
<iconset resource="../../../qad/libs/qglview/qglview.qrc"> <iconset resource="../core/qglengine_core.qrc">
<normaloff>:/icons/type-camera.png</normaloff>:/icons/type-camera.png</iconset> <normaloff>:/icons/type-camera.png</normaloff>:/icons/type-camera.png</iconset>
</property> </property>
<property name="text"> <property name="text">
@@ -298,6 +298,15 @@
<string>Move to parent</string> <string>Move to parent</string>
</property> </property>
</action> </action>
<action name="actionMesh_info">
<property name="icon">
<iconset resource="../../../cd/utils/pult/cdpult.qrc">
<normaloff>:/icons/dialog-information.png</normaloff>:/icons/dialog-information.png</iconset>
</property>
<property name="text">
<string>Mesh info ...</string>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
@@ -312,9 +321,9 @@
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../../../cd/utils/pult/cdpult.qrc"/>
<include location="../../../qad/libs/application/qad_application.qrc"/> <include location="../../../qad/libs/application/qad_application.qrc"/>
<include location="../../../qad/libs/blockview/qad_blockview.qrc"/> <include location="../../../qad/libs/blockview/qad_blockview.qrc"/>
<include location="../../../qad/libs/qglview/qglview.qrc"/>
<include location="../core/qglengine_core.qrc"/> <include location="../core/qglengine_core.qrc"/>
<include location="widgets.qrc"/> <include location="widgets.qrc"/>
</resources> </resources>

View File

@@ -70,6 +70,7 @@ void ViewEditor::assignQGLView(QGLView * v) {
ui->checkSoftShadows->setChecked(view->softShadows()); ui->checkSoftShadows->setChecked(view->softShadows());
ui->spinSoftShadowSamples->setValue(view->softShadowsSamples()); ui->spinSoftShadowSamples->setValue(view->softShadowsSamples());
ui->spinSoftShadowQuality->setValue(view->softShadowsQuality()); ui->spinSoftShadowQuality->setValue(view->softShadowsQuality());
ui->spinLineWidth->setValue(view->lineWidth());
auto setMapSize = [](QComboBox * combo, QSize sz) { auto setMapSize = [](QComboBox * combo, QSize sz) {
for (int i = 0; i < combo->count(); ++i) { for (int i = 0; i < combo->count(); ++i) {
if (combo->itemData(i).toSize() == sz) { if (combo->itemData(i).toSize() == sz) {
@@ -268,6 +269,12 @@ void ViewEditor::on_spinSoftShadowQuality_valueChanged(double arg1) {
} }
void ViewEditor::on_spinLineWidth_valueChanged(double v) {
if (!view || !active) return;
view->setLineWidth(v);
}
void ViewEditor::on_checkVSync_clicked(bool val) { void ViewEditor::on_checkVSync_clicked(bool val) {
if (!view || !active) return; if (!view || !active) return;
view->setVSync(val); view->setVSync(val);

View File

@@ -72,6 +72,7 @@ private slots:
void on_checkSoftShadows_clicked(bool arg1); void on_checkSoftShadows_clicked(bool arg1);
void on_spinSoftShadowSamples_valueChanged(double arg1); void on_spinSoftShadowSamples_valueChanged(double arg1);
void on_spinSoftShadowQuality_valueChanged(double arg1); void on_spinSoftShadowQuality_valueChanged(double arg1);
void on_spinLineWidth_valueChanged(double v);
}; };
#endif // VIEW_EDITOR_H #endif // VIEW_EDITOR_H

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>479</width> <width>479</width>
<height>897</height> <height>976</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
@@ -37,7 +37,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>479</width> <width>479</width>
<height>897</height> <height>976</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
@@ -161,6 +161,30 @@
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QCheckBox" name="checkFXAA">
<property name="text">
<string>FXAA</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkVSync">
<property name="text">
<string>VSync</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkAutoExposure">
<property name="text">
<string>Auto exposure</string>
</property>
</widget>
</item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QCheckBox" name="checkCameraLight"> <widget class="QCheckBox" name="checkCameraLight">
<property name="text"> <property name="text">
@@ -181,30 +205,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkFXAA">
<property name="text">
<string>FXAA</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkAutoExposure">
<property name="text">
<string>Auto exposure</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkVSync">
<property name="text">
<string>VSync</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QWidget" name="widget_2" native="true"> <widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
@@ -253,6 +253,50 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="3" column="0">
<widget class="QWidget" name="widget_3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_12">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Line width:</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinLineWidth">
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>

View File

@@ -15,5 +15,6 @@
<file>../icons/group.png</file> <file>../icons/group.png</file>
<file>../icons/legend.png</file> <file>../icons/legend.png</file>
<file>../icons/format-fill-color.png</file> <file>../icons/format-fill-color.png</file>
<file>../icons/dialog-information.png</file>
</qresource> </qresource>
</RCC> </RCC>