git-svn-id: svn://db.shs.com.ru/libs@49 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2015-11-27 11:35:39 +00:00
parent 59eb135a60
commit 57d7920d8a
6 changed files with 269 additions and 167 deletions

View File

@@ -74,6 +74,8 @@ private slots:
void on_spinCubemapSize_valueChanged(double val) {view->setDynamicReflectionsMapSize(val);} void on_spinCubemapSize_valueChanged(double val) {view->setDynamicReflectionsMapSize(val);}
void on_spinShadowmapSize_valueChanged(double val) {view->setShadowMapSize(val);} void on_spinShadowmapSize_valueChanged(double val) {view->setShadowMapSize(val);}
void on_spinHaloFillAlpha_valueChanged(double val) {view->setSelectionHaloFillAlpha(val);} void on_spinHaloFillAlpha_valueChanged(double val) {view->setSelectionHaloFillAlpha(val);}
void on_spinMotionBlurFactor_valueChanged(double val) {view->setMotionBlurFactor(val);}
void on_spinMotionBlurSteps_valueChanged(int val) {view->setMotionBlurSteps(val);}
//void on_spinSliderShine_valueChanged(double val) {obj->material().shine_strength = val; obj->setMaterial(obj->material(), true);} //void on_spinSliderShine_valueChanged(double val) {obj->material().shine_strength = val; obj->setMaterial(obj->material(), true);}
//void on_spinSliderRough_valueChanged(double val) {obj->material().shine = val; obj->setMaterial(obj->material(), true);} //void on_spinSliderRough_valueChanged(double val) {obj->material().shine = val; obj->setMaterial(obj->material(), true);}
void on_pushButton_clicked() {view->removeLight(view->lightsCount() - 1); setWindowTitle(QString::number(view->lightsCount()));} void on_pushButton_clicked() {view->removeLight(view->lightsCount() - 1); setWindowTitle(QString::number(view->lightsCount()));}
@@ -92,6 +94,7 @@ private slots:
void on_checkShadows_toggled(bool val) {view->setShadowsEnabled(val);} void on_checkShadows_toggled(bool val) {view->setShadowsEnabled(val);}
void on_checkSoftShadows_toggled(bool val) {view->setSoftShadowsEnabled(val);} void on_checkSoftShadows_toggled(bool val) {view->setSoftShadowsEnabled(val);}
void on_checkCameraOrbit_toggled(bool val) {view->setCameraOrbit(val);} void on_checkCameraOrbit_toggled(bool val) {view->setCameraOrbit(val);}
void on_checkMotionBlur_toggled(bool val) {view->setMotionBlurEnabled(val);}
void on_colorAmbient_colorChanged(QColor color) {view->setAmbientColor(color);} void on_colorAmbient_colorChanged(QColor color) {view->setAmbientColor(color);}
void on_colorHalo_colorChanged(QColor color) {view->setSelectionHaloColor(color);} void on_colorHalo_colorChanged(QColor color) {view->setSelectionHaloColor(color);}
void on_view_glKeyPressEvent(QKeyEvent * e); void on_view_glKeyPressEvent(QKeyEvent * e);

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1246</width> <width>1246</width>
<height>856</height> <height>851</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -53,143 +53,217 @@
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QLabel" name="label"> <layout class="QFormLayout" name="formLayout">
<property name="text"> <property name="fieldGrowthPolicy">
<string>FOV</string> <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property> </property>
</widget> <property name="labelAlignment">
</item> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<item>
<widget class="SpinSlider" name="spinFOV">
<property name="minimum">
<double>0.100000000000000</double>
</property> </property>
<property name="maximum"> <item row="0" column="0">
<double>179.900000000000006</double> <widget class="QLabel" name="label">
</property> <property name="text">
<property name="value"> <string>FOV</string>
<double>60.000000000000000</double> </property>
</property> </widget>
</widget> </item>
</item> <item row="0" column="1">
<item> <widget class="SpinSlider" name="spinFOV">
<widget class="QLabel" name="label_2"> <property name="minimum">
<property name="text"> <double>0.100000000000000</double>
<string>accomodation time</string> </property>
</property> <property name="maximum">
</widget> <double>179.900000000000006</double>
</item> </property>
<item> <property name="value">
<widget class="SpinSlider" name="spinAccom"> <double>60.000000000000000</double>
<property name="minimum"> </property>
<double>0.000000000000000</double> </widget>
</property> </item>
<property name="maximum"> <item row="1" column="0">
<double>256.000000000000000</double> <widget class="QLabel" name="label_2">
</property> <property name="text">
<property name="value"> <string>accomodation time</string>
<double>32.000000000000000</double> </property>
</property> </widget>
<property name="squareScale"> </item>
<bool>true</bool> <item row="2" column="0">
</property> <widget class="QLabel" name="label_8">
</widget> <property name="text">
</item> <string>accomodation max speed</string>
<item> </property>
<widget class="QLabel" name="label_8"> </widget>
<property name="text"> </item>
<string>accomodation max speed</string> <item row="3" column="0">
</property> <widget class="QLabel" name="label_9">
</widget> <property name="text">
</item> <string>dynamic cubemap size</string>
<item> </property>
<widget class="SpinSlider" name="spinAccomMS"> </widget>
<property name="minimum"> </item>
<double>0.010000000000000</double> <item row="4" column="0">
</property> <widget class="QLabel" name="label_10">
<property name="maximum"> <property name="text">
<double>1.000000000000000</double> <string>shadowmap size</string>
</property> </property>
<property name="value"> </widget>
<double>0.100000000000000</double> </item>
</property> <item row="5" column="0">
<property name="decimals"> <widget class="QLabel" name="label_12">
<number>3</number> <property name="text">
</property> <string>motion blur factor</string>
<property name="singleStep"> </property>
<double>0.100000000000000</double> </widget>
</property> </item>
<property name="pageStep"> <item row="6" column="0">
<double>1.000000000000000</double> <widget class="QLabel" name="label_13">
</property> <property name="text">
<property name="squareScale"> <string>motion blur steps</string>
<bool>true</bool> </property>
</property> </widget>
</widget> </item>
</item> <item row="1" column="1">
<item> <widget class="SpinSlider" name="spinAccom">
<widget class="QLabel" name="label_9"> <property name="minimum">
<property name="text"> <double>0.000000000000000</double>
<string>dynamic cubemap size</string> </property>
</property> <property name="maximum">
</widget> <double>256.000000000000000</double>
</item> </property>
<item> <property name="value">
<widget class="SpinSlider" name="spinCubemapSize"> <double>32.000000000000000</double>
<property name="minimum"> </property>
<double>16.000000000000000</double> <property name="squareScale">
</property> <bool>true</bool>
<property name="maximum"> </property>
<double>2048.000000000000000</double> </widget>
</property> </item>
<property name="value"> <item row="2" column="1">
<double>512.000000000000000</double> <widget class="SpinSlider" name="spinAccomMS">
</property> <property name="minimum">
<property name="decimals"> <double>0.010000000000000</double>
<number>0</number> </property>
</property> <property name="maximum">
<property name="singleStep"> <double>1.000000000000000</double>
<double>16.000000000000000</double> </property>
</property> <property name="value">
<property name="pageStep"> <double>0.100000000000000</double>
<double>512.000000000000000</double> </property>
</property> <property name="decimals">
<property name="squareScale"> <number>3</number>
<bool>false</bool> </property>
</property> <property name="singleStep">
</widget> <double>0.100000000000000</double>
</item> </property>
<item> <property name="pageStep">
<widget class="QLabel" name="label_10"> <double>1.000000000000000</double>
<property name="text"> </property>
<string>shadowmap size</string> <property name="squareScale">
</property> <bool>true</bool>
</widget> </property>
</item> </widget>
<item> </item>
<widget class="SpinSlider" name="spinShadowmapSize"> <item row="3" column="1">
<property name="minimum"> <widget class="SpinSlider" name="spinCubemapSize">
<double>16.000000000000000</double> <property name="minimum">
</property> <double>16.000000000000000</double>
<property name="maximum"> </property>
<double>2048.000000000000000</double> <property name="maximum">
</property> <double>2048.000000000000000</double>
<property name="value"> </property>
<double>512.000000000000000</double> <property name="value">
</property> <double>512.000000000000000</double>
<property name="decimals"> </property>
<number>0</number> <property name="decimals">
</property> <number>0</number>
<property name="singleStep"> </property>
<double>16.000000000000000</double> <property name="singleStep">
</property> <double>16.000000000000000</double>
<property name="pageStep"> </property>
<double>512.000000000000000</double> <property name="pageStep">
</property> <double>512.000000000000000</double>
<property name="squareScale"> </property>
<bool>true</bool> <property name="squareScale">
</property> <bool>false</bool>
</widget> </property>
</widget>
</item>
<item row="4" column="1">
<widget class="SpinSlider" name="spinShadowmapSize">
<property name="minimum">
<double>16.000000000000000</double>
</property>
<property name="maximum">
<double>2048.000000000000000</double>
</property>
<property name="value">
<double>512.000000000000000</double>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="singleStep">
<double>16.000000000000000</double>
</property>
<property name="pageStep">
<double>512.000000000000000</double>
</property>
<property name="squareScale">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="SpinSlider" name="spinMotionBlurFactor">
<property name="minimum">
<double>0.000000000000000</double>
</property>
<property name="maximum">
<double>10000.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="pageStep">
<double>1.000000000000000</double>
</property>
<property name="squareScale">
<bool>false</bool>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="SpinSlider" name="spinMotionBlurSteps">
<property name="minimum">
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>128.000000000000000</double>
</property>
<property name="value">
<double>8.000000000000000</double>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
<property name="pageStep">
<double>4.000000000000000</double>
</property>
<property name="squareScale">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QPushButton" name="pushButton"> <widget class="QPushButton" name="pushButton">
@@ -363,6 +437,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="checkMotionBlur">
<property name="text">
<string>motion blur</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="checkFXAA"> <widget class="QCheckBox" name="checkFXAA">
<property name="text"> <property name="text">
@@ -502,6 +583,7 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<zorder>tabWidget</zorder>
</widget> </widget>
</item> </item>
</layout> </layout>
@@ -561,12 +643,12 @@
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>92</x> <x>112</x>
<y>580</y> <y>611</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>91</x> <x>111</x>
<y>605</y> <y>632</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@@ -577,12 +659,12 @@
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>147</x> <x>167</x>
<y>580</y> <y>611</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>143</x> <x>163</x>
<y>630</y> <y>653</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@@ -593,12 +675,12 @@
<slot>setEnabled(bool)</slot> <slot>setEnabled(bool)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>106</x> <x>126</x>
<y>705</y> <y>737</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>108</x> <x>128</x>
<y>730</y> <y>758</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>

View File

@@ -57,8 +57,11 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
cur_luminance = 1.; cur_luminance = 1.;
accom_time = 16.; accom_time = 16.;
accom_max_speed = 0.2; accom_max_speed = 0.2;
m_motionBlurFactor = 1.;
m_motionBlurSteps = 8;
mouse_first = mouseSelect_ = accomodation_ = hoverHalo_ = selectionHalo_ = true; mouse_first = mouseSelect_ = accomodation_ = hoverHalo_ = selectionHalo_ = true;
fogEnabled_ = is_init = grabMouse_ = mouseRotate_ = mouseThis_ = shaders_bind = shadows_ = shadows_soft = dynamic_reflections = hdr_ = bloom_ = msaa_ = fxaa_ = changed_ = false; fogEnabled_ = is_init = grabMouse_ = mouseRotate_ = mouseThis_ = shaders_bind = m_motionBlurEnabled =
shadows_ = shadows_soft = dynamic_reflections = hdr_ = bloom_ = msaa_ = fxaa_ = changed_ = false;
rmode = GLObjectBase::Fill; rmode = GLObjectBase::Fill;
sel_mode = QGLView::SingleSelection; sel_mode = QGLView::SingleSelection;
sel_pen = QPen(Qt::black, 1, Qt::DashLine); sel_pen = QPen(Qt::black, 1, Qt::DashLine);

View File

@@ -80,6 +80,9 @@ class QGLView: public QGraphicsView, public QGLViewBase
Q_PROPERTY (bool accomodationEnabled READ isAccomodationEnabled WRITE setAccomodationEnabled) Q_PROPERTY (bool accomodationEnabled READ isAccomodationEnabled WRITE setAccomodationEnabled)
Q_PROPERTY (double accomodationTime READ accomodationTime WRITE setAccomodationTime) Q_PROPERTY (double accomodationTime READ accomodationTime WRITE setAccomodationTime)
Q_PROPERTY (double accomodationMaxSpeed READ accomodationMaxSpeed WRITE setAccomodationMaxSpeed) Q_PROPERTY (double accomodationMaxSpeed READ accomodationMaxSpeed WRITE setAccomodationMaxSpeed)
Q_PROPERTY (bool motionBlurEnabled READ isMotionBlurEnabled WRITE setMotionBlurEnabled)
Q_PROPERTY (double motionBlurFactor READ motionBlurFactor WRITE setMotionBlurFactor)
Q_PROPERTY (int motionBlurSteps READ motionBlurSteps WRITE setMotionBlurSteps)
Q_PROPERTY (Qt::MouseButton selectionButton READ selectionButton WRITE setSelectionButton) Q_PROPERTY (Qt::MouseButton selectionButton READ selectionButton WRITE setSelectionButton)
Q_PROPERTY (Qt::KeyboardModifier selectionModifier READ selectionModifier WRITE setSelectionModifier) Q_PROPERTY (Qt::KeyboardModifier selectionModifier READ selectionModifier WRITE setSelectionModifier)
Q_PROPERTY (SelectionMode selectionMode READ selectionMode WRITE setSelectionMode) Q_PROPERTY (SelectionMode selectionMode READ selectionMode WRITE setSelectionMode)
@@ -138,6 +141,7 @@ public:
bool isSelectionHaloEnabled() const {return selectionHalo_;} bool isSelectionHaloEnabled() const {return selectionHalo_;}
QColor selectionHaloColor() const {return selectionHaloColor_;} QColor selectionHaloColor() const {return selectionHaloColor_;}
double selectionHaloFillAlpha() const {return selectionHaloFill_;} double selectionHaloFillAlpha() const {return selectionHaloFill_;}
bool isMotionBlurEnabled() const {return m_motionBlurEnabled;}
bool isShadowsEnabled() const {return shadows_;} bool isShadowsEnabled() const {return shadows_;}
bool isSoftShadowsEnabled() const {return shadows_soft;} bool isSoftShadowsEnabled() const {return shadows_soft;}
bool isDynamicReflectionsEnabled() const {return dynamic_reflections;} bool isDynamicReflectionsEnabled() const {return dynamic_reflections;}
@@ -152,6 +156,8 @@ public:
double accomodationTime() const {return accom_time;} double accomodationTime() const {return accom_time;}
double accomodationMaxSpeed() const {return accom_max_speed;} double accomodationMaxSpeed() const {return accom_max_speed;}
double motionBlurFactor() const {return m_motionBlurFactor;}
int motionBlurSteps() const {return m_motionBlurSteps;}
void addObject(QGraphicsItem * o) {scene()->addItem(o);} void addObject(QGraphicsItem * o) {scene()->addItem(o);}
void addObject(QWidget * o, Qt::WindowFlags f = Qt::Widget); void addObject(QWidget * o, Qt::WindowFlags f = Qt::Widget);
@@ -256,11 +262,12 @@ private:
Qt::KeyboardModifier sel_mod; Qt::KeyboardModifier sel_mod;
GLRendererBase::RenderingParameters start_rp; GLRendererBase::RenderingParameters start_rp;
double lineWidth_, linearFiltering_, accom_time, accom_max_speed, cur_luminance; double lineWidth_, linearFiltering_, accom_time, accom_max_speed, cur_luminance;
double fogDensity_, fogStart_, fogEnd_, fps_, fps_tm, hoverHaloFill_, selectionHaloFill_; double fogDensity_, fogStart_, fogEnd_, fps_, fps_tm, hoverHaloFill_, selectionHaloFill_, m_motionBlurFactor;
int timer, fps_cnt, sh_id_loc, shadow_map_size, dynamic_cubemap_size; int timer, fps_cnt, sh_id_loc, shadow_map_size, dynamic_cubemap_size, motion_blur_steps, m_motionBlurSteps;
bool is_init, fogEnabled_, lightEnabled_, grabMouse_, mouse_first, mouseRotate_, mouseSelect_, customMouseMove_; bool is_init, fogEnabled_, lightEnabled_, grabMouse_, mouse_first, mouseRotate_, mouseSelect_, customMouseMove_;
bool shaders_supported, changed_, cameraOrbit_;
bool hoverHalo_, selectionHalo_, mouseThis_, shaders_bind, shadows_, shadows_soft, selecting_; bool hoverHalo_, selectionHalo_, mouseThis_, shaders_bind, shadows_, shadows_soft, selecting_;
bool shaders_supported, dynamic_reflections, hdr_, bloom_, msaa_, fxaa_, accomodation_, changed_, cameraOrbit_; bool dynamic_reflections, hdr_, bloom_, msaa_, fxaa_, accomodation_, m_motionBlurEnabled;
public slots: public slots:
void setBackColor(const QColor & arg) {backColor_ = arg;} void setBackColor(const QColor & arg) {backColor_ = arg;}
@@ -302,6 +309,9 @@ public slots:
void setMultisamplingEnabled(const bool & arg) {msaa_ = arg;} void setMultisamplingEnabled(const bool & arg) {msaa_ = arg;}
void setFXAAEnabled(const bool & arg) {fxaa_ = arg;} void setFXAAEnabled(const bool & arg) {fxaa_ = arg;}
void setAccomodationEnabled(const bool & arg) {accomodation_ = arg;} void setAccomodationEnabled(const bool & arg) {accomodation_ = arg;}
void setMotionBlurEnabled(bool motionBlurEnabled) {m_motionBlurEnabled = motionBlurEnabled;}
void setMotionBlurFactor(double motionBlurFactor) {m_motionBlurFactor = motionBlurFactor;}
void setMotionBlurSteps(int motionBlurSteps) {m_motionBlurSteps = motionBlurSteps;}
void reloadShaders() {if (renderer_ != 0) renderer_->reloadShaders(); reloadThisShaders();} void reloadShaders() {if (renderer_ != 0) renderer_->reloadShaders(); reloadThisShaders();}
void deselect() {sel_obj = 0;} void deselect() {sel_obj = 0;}

View File

@@ -195,18 +195,22 @@ void RendererDeferredShading::renderScene() {
piSwap<int>(wi, ri); piSwap<int>(wi, ri);
} }
fbo_out.setWriteBuffer(wi); if (view.isMotionBlurEnabled()) {
glActiveTextureChannel(1); fbo_out.setWriteBuffer(wi);
glBindTexture(GL_TEXTURE_2D, fbo_g.colorTexture(4)); glActiveTextureChannel(1);
shader_motion_blur->bind(); glBindTexture(GL_TEXTURE_2D, fbo_g.colorTexture(4));
shader_motion_blur->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4()); shader_motion_blur->bind();
shader_motion_blur->setUniformValue("dt", QVector2D(1. / fbo_out.width(), 1. / fbo_out.height())); shader_motion_blur->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
shader_motion_blur->setUniformValue("t0", 0); shader_motion_blur->setUniformValue("dt", QVector2D(1. / fbo_out.width(), 1. / fbo_out.height()));
shader_motion_blur->setUniformValue("ts", 1); shader_motion_blur->setUniformValue("t0", 0);
glDrawQuad(shader_motion_blur); shader_motion_blur->setUniformValue("ts", 1);
glActiveTextureChannel(0); shader_motion_blur->setUniformValue("factor", GLfloat(view.motionBlurFactor()));
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(wi)); shader_motion_blur->setUniformValue("steps", view.motionBlurSteps());
piSwap<int>(wi, ri); glDrawQuad(shader_motion_blur);
glActiveTextureChannel(0);
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(wi));
piSwap<int>(wi, ri);
}
glReleaseShaders(); glReleaseShaders();
fbo_out.release(); fbo_out.release();

View File

@@ -2,13 +2,13 @@
uniform sampler2D t0, ts; uniform sampler2D t0, ts;
uniform vec2 dt; uniform vec2 dt;
uniform float factor; uniform float factor = 1.;
uniform int steps = 16; uniform int steps = 8;
void main(void) { void main(void) {
vec2 cdt = dt / steps; vec2 cdt = dt / steps;
vec2 ct = qgl_FragTexture.xy; vec2 ct = qgl_FragTexture.xy;
vec3 speed = texture(ts, ct).rgb*1024; vec3 speed = texture(ts, ct).rgb * 256 * factor;
int hsteps = steps / 2; int hsteps = steps / 2;
ct -= speed.xy * cdt * hsteps; ct -= speed.xy * cdt * hsteps;
vec3 scol = vec3(0);//texture(t0, ct).rgb; vec3 scol = vec3(0);//texture(t0, ct).rgb;