git-svn-id: svn://db.shs.com.ru/libs@75 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -754,11 +754,11 @@ void KX_Pult::progress(int val, int max) {
|
||||
}
|
||||
|
||||
|
||||
void KX_Pult::renew() {
|
||||
void KX_Pult::renew(bool write) {
|
||||
addToList(trUtf8("Update settings from \"%1\"").arg(PI2QString(config_)), Qt::darkMagenta);
|
||||
dir.setPath(config.getValue("x.output_dir", "./Experiments/").stringValue());
|
||||
setWindowTitle(config.getValue("title", "Noname").stringValue() + trUtf8(" - KX Pult"));
|
||||
ui->configWidget->write();
|
||||
//if (write) ui->configWidget->write();
|
||||
if (prot_x != 0) {
|
||||
prot_x->stop();
|
||||
delete prot_x;
|
||||
|
||||
@@ -122,7 +122,7 @@ private slots:
|
||||
void updateTree(bool move = false);
|
||||
void filterTree();
|
||||
void calculate();
|
||||
void renew();
|
||||
void renew(bool write = true);
|
||||
void toggledX(int index, bool on);
|
||||
void changedX(int index, int num);
|
||||
void k_sendFailed();
|
||||
|
||||
@@ -1244,13 +1244,13 @@ void Graphic::tick(int index, bool slide, bool update_) {
|
||||
}
|
||||
}
|
||||
if (!update_) {
|
||||
findGraphicsRect();
|
||||
if (isFit) findGraphicsRect();
|
||||
mutex.unlock();
|
||||
return;
|
||||
}
|
||||
//polyline.push_back(QPointF(brick->time_, brick->output(port)));
|
||||
//cout << polyline.size() << endl;
|
||||
findGraphicsRect();
|
||||
if (isFit) findGraphicsRect();
|
||||
if (!slide) {
|
||||
if (aupdate) update();
|
||||
return;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "qpiconfig.h"
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
int QString2int(const QString & string) {
|
||||
@@ -272,8 +274,50 @@ QPIConfig::QPIConfig(QString * str, QPIConfig::FileType type_) {
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::QPIConfig(const QString & path, QStringList dirs) {
|
||||
init();
|
||||
type = Config;
|
||||
internal = true;
|
||||
dev = new QFile(path);
|
||||
dev->open(QIODevice::ReadOnly);
|
||||
incdirs = dirs;
|
||||
incdirs << QFileInfo(path).absoluteDir().path();
|
||||
QString cp = path;
|
||||
while (!dev->isOpen()) {
|
||||
if (dirs.isEmpty()) break;
|
||||
cp = dirs.back();
|
||||
if (cp.endsWith("/") || cp.endsWith("\\")) cp.chop(1);
|
||||
cp += "/" + path;
|
||||
dev->setFileName(cp);
|
||||
dev->open(QIODevice::ReadOnly);
|
||||
dirs.pop_back();
|
||||
}
|
||||
if (!dev->isOpen()) {
|
||||
delete dev;
|
||||
dev = 0;
|
||||
return;
|
||||
}
|
||||
dev->close();
|
||||
setFileName(cp);
|
||||
open(QIODevice::ReadOnly);
|
||||
parse();
|
||||
}
|
||||
|
||||
|
||||
QPIConfig::~QPIConfig() {
|
||||
stream.setDevice(0);
|
||||
root.deleteBranch();
|
||||
foreach (QPIConfig * c, inc_devs)
|
||||
delete c;
|
||||
inc_devs.clear();
|
||||
includes.clear();
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::init() {
|
||||
internal = false;
|
||||
buffer = 0;
|
||||
dev = 0;
|
||||
delim = ".";
|
||||
root._name = "root";
|
||||
root.delim = delim;
|
||||
@@ -544,6 +588,22 @@ void QPIConfig::writeAll() {
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfig::getPrefixFromLine(QString line, bool * exists) {
|
||||
line = line.trimmed();
|
||||
if (line.left(1) == "#") {if (exists) *exists = false; return QString();}
|
||||
int ci = line.indexOf("#");
|
||||
if (ci >= 0) line = line.left(ci).trimmed();
|
||||
if (line.indexOf("=") >= 0) {if (exists) *exists = false; return QString();}
|
||||
if (line.indexOf("[") >= 0 && line.indexOf("]") >= 0) {
|
||||
if (exists) *exists = true;
|
||||
line.remove(0, 1);
|
||||
return line.left(line.lastIndexOf("]")).trimmed();
|
||||
}
|
||||
if (exists) *exists = false;
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfig::writeAllToString() {
|
||||
QString str;
|
||||
QTextStream s(&str);
|
||||
@@ -606,14 +666,47 @@ bool QPIConfig::entryExists(const Entry * e, const QString & name) const {
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::updateIncludes() {
|
||||
if (internal) return;
|
||||
all_includes.clear();
|
||||
foreach (QPIConfig * c, includes)
|
||||
all_includes << c->allLeaves();
|
||||
}
|
||||
|
||||
|
||||
QString QPIConfig::entryValue(QString v) {
|
||||
int i = -1, l = 0;
|
||||
while (1) {
|
||||
i = v.indexOf("${");
|
||||
if (i < 0) break;
|
||||
l = v.indexOf("}", i + 1);
|
||||
QString w = v.mid(i + 2, l - i - 2), r;
|
||||
l = w.length() + 3;
|
||||
w = w.trimmed();
|
||||
foreach (QPIConfig::Entry * e, all_includes) {
|
||||
if (e->_full_name == w) {
|
||||
r = e->_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
v.replace(i, l, r);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
void QPIConfig::parse(QString content) {
|
||||
root.deleteBranch();
|
||||
root.clear();
|
||||
QString src, str, tab, comm, all, name, type;
|
||||
QString src, str, tab, comm, all, name, type, prefix, tprefix;
|
||||
QStringList tree;
|
||||
Entry * entry, * te, * ce;
|
||||
int ind, sind;
|
||||
bool isNew;
|
||||
bool isNew, isPrefix;
|
||||
foreach (QPIConfig * c, inc_devs)
|
||||
delete c;
|
||||
inc_devs.clear();
|
||||
includes.clear();
|
||||
if (content.isEmpty()) {
|
||||
if (buffer == 0) {
|
||||
if (!isOpen()) return;
|
||||
@@ -629,6 +722,12 @@ void QPIConfig::parse(QString content) {
|
||||
while (!stream.atEnd()) {
|
||||
other.push_back(QString());
|
||||
src = str = stream.readLine();
|
||||
tprefix = getPrefixFromLine(src, &isPrefix);
|
||||
if (isPrefix) {
|
||||
prefix = tprefix;
|
||||
if (!prefix.isEmpty())
|
||||
prefix += delim;
|
||||
}
|
||||
//cout << str << endl;
|
||||
tab = str.left(str.indexOf(str.trimmed().left(1)));
|
||||
str = str.trimmed();
|
||||
@@ -647,7 +746,20 @@ void QPIConfig::parse(QString content) {
|
||||
comm = "";
|
||||
}
|
||||
//name = str.left(ind).trimmed();
|
||||
tree = str.left(ind).trimmed().split(delim);
|
||||
tree = (prefix + str.left(ind).trimmed()).split(delim);
|
||||
if (tree.front() == "include") {
|
||||
name = str.right(str.length() - ind - 1).trimmed();
|
||||
QPIConfig * iconf = new QPIConfig(name, incdirs);
|
||||
if (!iconf->dev) {
|
||||
delete iconf;
|
||||
} else {
|
||||
inc_devs << iconf;
|
||||
includes << iconf << iconf->includes;
|
||||
updateIncludes();
|
||||
}
|
||||
//piCout << "includes" << includes;
|
||||
other.back() = src;
|
||||
} else {
|
||||
name = tree.back();
|
||||
tree.pop_back();
|
||||
entry = &root;
|
||||
@@ -673,7 +785,7 @@ void QPIConfig::parse(QString content) {
|
||||
ce->delim = delim;
|
||||
ce->_tab = tab;
|
||||
ce->_name = name;
|
||||
ce->_value = str.right(str.length() - ind - 1).trimmed();
|
||||
ce->_value = entryValue(str.right(str.length() - ind - 1).trimmed());
|
||||
ce->_type = type;
|
||||
ce->_comment = comm;
|
||||
ce->_line = lines;
|
||||
@@ -682,9 +794,11 @@ void QPIConfig::parse(QString content) {
|
||||
ce->_parent = entry;
|
||||
entry->_children << ce;
|
||||
}
|
||||
}
|
||||
} else other.back() = src;
|
||||
lines++;
|
||||
}
|
||||
setEntryDelim(&root, delim);
|
||||
buildFullNames(&root);
|
||||
//if (content.isEmpty()) stream.setDevice(this);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
QPIConfig(const QString & path, QIODevice::OpenMode mode = QIODevice::ReadWrite);
|
||||
QPIConfig(const QString & path, QPIConfig::FileType type);
|
||||
QPIConfig(QString * str, QPIConfig::FileType type = QPIConfig::Config);
|
||||
~QPIConfig() {stream.setDevice(0); root.deleteBranch();}
|
||||
~QPIConfig();
|
||||
|
||||
void setFile(const QString & path, QIODevice::OpenMode mode = QIODevice::ReadWrite);
|
||||
void setString(QString * str);
|
||||
@@ -248,6 +248,7 @@ public:
|
||||
void setDelimiter(const QString & d) {delim = d; setEntryDelim(&root, d); readAll();}
|
||||
|
||||
private:
|
||||
QPIConfig(const QString & path, QStringList dirs);
|
||||
void init();
|
||||
int childCount(const Entry * e) const {int c = 0; foreach (const Entry * i, e->_children) c += childCount(i); c += e->_children.size(); return c;}
|
||||
bool entryExists(const Entry * e, const QString & name) const;
|
||||
@@ -257,9 +258,17 @@ private:
|
||||
inline Entry & entryByIndex(const int index) {Branch b = allLeaves(); if (index < 0 || index >= b.size()) return empty; return *(b[index]);}
|
||||
void removeEntry(Branch & b, Entry * e);
|
||||
void deleteEntry(Entry * e) {foreach (Entry * i, e->_children) deleteEntry(i); delete e;}
|
||||
QString getPrefixFromLine(QString line, bool * exists);
|
||||
void updateIncludes();
|
||||
QString entryValue(QString v);
|
||||
void parse(QString content = QString());
|
||||
|
||||
int centry;
|
||||
bool internal;
|
||||
QVector<QPIConfig * > includes, inc_devs;
|
||||
Branch all_includes;
|
||||
QFile * dev;
|
||||
QStringList incdirs;
|
||||
QString delim, * buffer;
|
||||
Entry root, empty;
|
||||
uint lines;
|
||||
|
||||
Binary file not shown.
@@ -47,13 +47,13 @@ void Camera::apply(const GLdouble & aspect) {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
if (aspect <= 1.)
|
||||
glScaled(aspect, aspect, 1.);
|
||||
QMatrix4x4 pm;// = glMatrixPerspective(fov_, aspect, depth_start, depth_end);
|
||||
pm.perspective(fov_, aspect, depth_start, depth_end);
|
||||
QMatrix4x4 pm = glMatrixPerspective(fov_, aspect, depth_start, depth_end);
|
||||
//pm.perspective(fov_, aspect, depth_start, depth_end);
|
||||
//qDebug() << pm;// << glMatrixPerspective(fov_, aspect, depth_start, depth_end);
|
||||
//qDebug() << pm;
|
||||
setGLMatrix(pm);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
pm.setToIdentity();
|
||||
//qDebug() << pm;
|
||||
pm.translate(0., 0., -distance());
|
||||
pm.rotate(angles_.y(), 1., 0., 0.);
|
||||
pm.rotate(angles_.x(), 0., 1., 0.);
|
||||
|
||||
@@ -152,10 +152,13 @@ inline QDataStream & operator <<(QDataStream & s, const Material & m) {
|
||||
cs << cs.chunk(1, m.name) << cs.chunk(2, m.color_diffuse) << cs.chunk(3, m.color_specular) << cs.chunk(4, m.color_self_illumination)
|
||||
<< cs.chunk(5, m.transparency) << cs.chunk(6, m.reflectivity) << cs.chunk(7, m.glass) << cs.chunk(8, m.map_diffuse) << cs.chunk(9, m.map_normal)
|
||||
<< cs.chunk(10, m.map_relief) << cs.chunk(11, m.map_specular) << cs.chunk(12, m.map_specularity) << cs.chunk(13, m.map_self_illumination);
|
||||
s << cs.data(); return s;
|
||||
s << qCompress(cs.data()); return s;
|
||||
}
|
||||
inline QDataStream & operator >>(QDataStream & s, Material & m) {
|
||||
ChunkStream cs(s);
|
||||
QByteArray ba;
|
||||
s >> ba;
|
||||
ba = qUncompress(ba);
|
||||
ChunkStream cs(ba);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: m.name = cs.getData<QString>(); break;
|
||||
|
||||
@@ -296,30 +296,40 @@ void Light::draw(QGLShaderProgram * prog, bool simplest) {
|
||||
|
||||
QDataStream & operator <<(QDataStream & s, const GLObjectBase * p) {
|
||||
ChunkStream cs;
|
||||
//qDebug() << "place" << p->name() << "...";
|
||||
cs << cs.chunk(1, int(p->type_)) << cs.chunk(2, p->accept_light) << cs.chunk(3, p->accept_fog) << cs.chunk(4, p->visible_)
|
||||
<< cs.chunk(5, p->cast_shadow) << cs.chunk(6, p->rec_shadow) << cs.chunk(7, p->raw_matrix) << cs.chunk(8, p->line_width)
|
||||
<< cs.chunk(9, int(p->render_mode)) << cs.chunk(10, p->material_) << cs.chunk(11, p->pos_) << cs.chunk(12, p->angles_)
|
||||
<< cs.chunk(13, p->scale_) << cs.chunk(14, p->mat_) << cs.chunk(15, p->vbo) << cs.chunk(16, p->children_)
|
||||
<< cs.chunk(13, p->scale_) << cs.chunk(14, p->mat_) << cs.chunk(15, p->vbo) << cs.chunk(16, p->children_.size())
|
||||
<< cs.chunk(17, p->name_);
|
||||
//qDebug() << "place self done";
|
||||
if (p->type_ == GLObjectBase::glLight) {
|
||||
//qDebug() << "place light ...";
|
||||
Light * l = (Light*)p;
|
||||
cs << cs.chunk(100, l->direction) << cs.chunk(101, l->angle_start) << cs.chunk(102, l->angle_end) << cs.chunk(103, l->intensity)
|
||||
<< cs.chunk(104, l->decay_const) << cs.chunk(105, l->decay_linear) << cs.chunk(106, l->decay_quadratic)
|
||||
<< cs.chunk(107, l->decay_start) << cs.chunk(108, l->decay_end) << cs.chunk(109, int(l->light_type));
|
||||
}
|
||||
if (p->type_ == GLObjectBase::glCamera) {
|
||||
//qDebug() << "place camera ...";
|
||||
Camera * c = (Camera*)p;
|
||||
cs << cs.chunk(200, c->aim_) << cs.chunk(201, c->fov_) << cs.chunk(202, c->depth_start) << cs.chunk(203, c->depth_end)
|
||||
<< cs.chunk(204, c->angle_limit_lower_xy) << cs.chunk(205, c->angle_limit_upper_xy)
|
||||
<< cs.chunk(206, c->mirror_x) << cs.chunk(207, c->mirror_y);
|
||||
}
|
||||
s << cs.data(); return s;
|
||||
//qDebug() << "place" << p->name() << cs.data().size() << s.device()->size();
|
||||
s << cs.data();
|
||||
foreach (const GLObjectBase * c, p->children_)
|
||||
s << c;
|
||||
return s;
|
||||
}
|
||||
QDataStream & operator >>(QDataStream & s, GLObjectBase *& p) {
|
||||
ChunkStream cs(s);
|
||||
p = 0;
|
||||
int ccnt = 0;
|
||||
Light * l = 0;
|
||||
Camera * c = 0;
|
||||
//qDebug() << "read obj ...";
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1:
|
||||
@@ -348,12 +358,7 @@ QDataStream & operator >>(QDataStream & s, GLObjectBase *& p) {
|
||||
case 13: if (p) p->scale_ = cs.getData<QVector3D>(); break;
|
||||
case 14: if (p) p->mat_ = cs.getData<QMatrix4x4>(); break;
|
||||
case 15: if (p) p->vbo = cs.getData<GLVBO>(); break;
|
||||
case 16: if (p) {
|
||||
p->children_ = cs.getData<QList<GLObjectBase * > >();
|
||||
foreach (GLObjectBase * c_, p->children_)
|
||||
c_->parent_ = p;
|
||||
}
|
||||
break;
|
||||
case 16: if (p) ccnt = cs.getData<int>(); break;
|
||||
case 17: if (p) p->name_ = cs.getData<QString>(); break;
|
||||
case 100: if (l) l->direction = cs.getData<QVector3D>(); break;
|
||||
case 101: if (l) l->angle_start = cs.getData<GLdouble>(); break;
|
||||
@@ -375,5 +380,13 @@ QDataStream & operator >>(QDataStream & s, GLObjectBase *& p) {
|
||||
case 207: if (c) c->mirror_y = cs.getData<bool>(); break;
|
||||
}
|
||||
}
|
||||
//qDebug() << p->name() << ccnt;
|
||||
for (int i = 0; i < ccnt; ++i) {
|
||||
GLObjectBase * c = 0;
|
||||
s >> c;
|
||||
if (!c) continue;
|
||||
c->parent_ = p;
|
||||
p->children_ << c;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -45,11 +45,12 @@ GLParticlesSystem::GLParticlesSystem(const QVector3D & pos): GLObjectBase() {
|
||||
|
||||
|
||||
void GLParticlesSystem::update() {
|
||||
//qDebug() << "update" << need_birth << tick_birth;
|
||||
if (!active_) return;
|
||||
//QMutexLocker locker(&mutex);
|
||||
Particle cp(lifeDuration_);
|
||||
if (birthEnabled_) need_birth += tick_birth;
|
||||
//qDebug() << "update" << particles.size();
|
||||
qDebug() << "update" << particles.size();
|
||||
if (need_birth >= 1.f) {
|
||||
cp.pos = emitterPosition_;
|
||||
//qDebug() << "speed" << cp.speed;
|
||||
@@ -134,8 +135,10 @@ void GLParticlesSystem::draw(QGLShaderProgram * prog, bool) {
|
||||
for (int i = 0; i < particles.size(); ++i)
|
||||
//particles[i].pos_h.setZ((particles[i].pos - apos).lengthSquared());
|
||||
particles[i].pos_h.setZ(particles[i].pos.distanceToPlane(apos, dir));
|
||||
//qSort(particles.begin(), particles.end());
|
||||
qSort(particles.begin(), particles.end());
|
||||
glBegin(GL_POINTS);
|
||||
foreach (const Particle & i, particles) {
|
||||
//glVertex3f(i.pos.x(), i.pos.y(), i.pos.z());
|
||||
a = (i.lifeDuration - i.lifeCurrent) / fade_time;
|
||||
if (a > 1.f) a = 1.f;
|
||||
a *= tr_a;
|
||||
@@ -178,7 +181,11 @@ void GLParticlesSystem::draw(QGLShaderProgram * prog, bool) {
|
||||
colors << tr_r << tr_g << tr_b << a;
|
||||
}
|
||||
}
|
||||
bool cae = glIsEnabled(GL_COLOR_ARRAY), nae = glIsEnabled(GL_NORMAL_ARRAY);
|
||||
glEnd();
|
||||
//bool cae = glIsEnabled(GL_COLOR_ARRAY), nae = glIsEnabled(GL_NORMAL_ARRAY);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
//glNormal3f(vn.x(), vn.y(), vn.z());
|
||||
glNormal3f(0., 0., 1.);
|
||||
@@ -193,6 +200,16 @@ void GLParticlesSystem::draw(QGLShaderProgram * prog, bool) {
|
||||
glDrawArrays(GL_QUADS, 0, vertices.size() / 3);
|
||||
glDepthMask(true);
|
||||
//glDisable(GL_ALPHA_TEST);
|
||||
if (!cae) glDisable(GL_COLOR_ARRAY);
|
||||
if (nae) glEnable(GL_NORMAL_ARRAY);
|
||||
//if (!cae) glDisable(GL_COLOR_ARRAY);
|
||||
//if (nae) glEnable(GL_NORMAL_ARRAY);
|
||||
}
|
||||
|
||||
|
||||
|
||||
GLParticlesSystem::Particle::Particle(float life_dur) {
|
||||
size = 1.;
|
||||
angle = lifeCurrent = 0.;
|
||||
speedDecay = 0.;
|
||||
lifeDuration = life_dur;
|
||||
tex_rect = QRectF(0, 0, 1, 1);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,29 @@
|
||||
#include "globject.h"
|
||||
#include "glcamera.h"
|
||||
|
||||
class GLParticlesSystem: public GLObjectBase
|
||||
class GLParticlesSystem: public QObject, public GLObjectBase
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(float birthRate READ birthRate WRITE setBirthRate)
|
||||
Q_PROPERTY(float lifeDuration READ lifeDuration WRITE setLifeDuration)
|
||||
Q_PROPERTY(float size READ size WRITE setSize)
|
||||
Q_PROPERTY(float enlargeSpeed READ enlargeSpeed WRITE setEnlargeSpeed)
|
||||
Q_PROPERTY(float initialAngle READ initialAngle WRITE setInitialAngle)
|
||||
Q_PROPERTY(float initialSpeed READ initialSpeed WRITE setInitialSpeed)
|
||||
Q_PROPERTY(float speedDecay READ speedDecay WRITE setSpeedDecay)
|
||||
Q_PROPERTY(float baseAngle READ baseAngle WRITE setBaseAngle)
|
||||
Q_PROPERTY(QVector3D speedDirection READ speedDirection WRITE setSpeedDirection)
|
||||
Q_PROPERTY(QVector3D emitterPosition READ emitterPosition WRITE setEmitterPosition)
|
||||
Q_PROPERTY(QVector3D emitterDirection READ emitterDirection WRITE setEmitterDirection)
|
||||
Q_PROPERTY(float lifeDurationJitter READ lifeDurationJitter WRITE setLifeDurationJitter)
|
||||
Q_PROPERTY(float speedJitter READ speedJitter WRITE setSpeedJitter)
|
||||
Q_PROPERTY(float speedDirectionJitter READ speedDirectionJitter WRITE setSpeedDirectionJitter)
|
||||
Q_PROPERTY(float sizeJitter READ sizeJitter WRITE setSizeJitter)
|
||||
Q_PROPERTY(float enlargeSpeedJitter READ enlargeSpeedJitter WRITE setEnlargeSpeedJitter)
|
||||
Q_PROPERTY(float angleJitter READ angleJitter WRITE setAngleJitter)
|
||||
Q_PROPERTY(bool active READ isActive WRITE setActive)
|
||||
Q_PROPERTY(bool birthEnabled READ isBirthEnabled WRITE setBirthEnabled)
|
||||
Q_PROPERTY(float fadeTime READ fadeTime WRITE setFadeTime)
|
||||
public:
|
||||
GLParticlesSystem(const QVector3D & pos = QVector3D());
|
||||
~GLParticlesSystem() {;}
|
||||
@@ -33,7 +54,7 @@ public:
|
||||
enum Type {Cone, Omni, Box};
|
||||
|
||||
struct Particle {
|
||||
Particle(float life_dur = 40.) {size = 1.; angle = lifeCurrent = 0.; speedDecay = 0.; lifeDuration = life_dur;}
|
||||
Particle(float life_dur = 40.);
|
||||
QVector3D pos;
|
||||
QVector3D pos_h;
|
||||
QVector3D speed;
|
||||
|
||||
@@ -146,12 +146,12 @@ void createGLTexture(GLuint & tex, const QImage & image, const GLenum & format,
|
||||
|
||||
QMatrix4x4 glMatrixPerspective(double angle, double aspect, double near_, double far_) {
|
||||
QMatrix4x4 ret;
|
||||
double t = 1. / (tan(angle * deg2rad / 2.));
|
||||
double t = 1. / (tan(angle * deg2rad / 2.)), e = 2.4e-7;
|
||||
ret(0, 0) = t / aspect;
|
||||
ret(1, 1) = t;
|
||||
ret(2, 2) = far_ / (far_ - near_) - 1.;
|
||||
ret(2, 3) = 2. * far_ * near_ / (far_ - near_);
|
||||
ret(3, 2) = -1;
|
||||
ret(2, 2) = e - 1.;//far_ / (far_ - near_) - 1.;
|
||||
ret(2, 3) = (e - 2.) * near_;//2. * far_ * near_ / (far_ - near_);
|
||||
ret(3, 2) = -1.;
|
||||
ret(3, 3) = 0.;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -72,11 +72,16 @@ private:
|
||||
|
||||
inline QDataStream & operator <<(QDataStream & s, const GLVBO & m) {
|
||||
ChunkStream cs;
|
||||
//qDebug() << "place VBO" << m.vertices_.size() << m.normals_.size() << m.texcoords_.size() << m.colors_.size() << "...";
|
||||
cs << cs.chunk(1, m.vertices_) << cs.chunk(2, m.normals_) << cs.chunk(3, m.texcoords_) << cs.chunk(4, m.colors_) << cs.chunk(5, m.usage);
|
||||
s << cs.data(); return s;
|
||||
//qDebug() << "place VBO done" << cs.data().size() << "...";
|
||||
s << qCompress(cs.data()); return s;
|
||||
}
|
||||
inline QDataStream & operator >>(QDataStream & s, GLVBO & m) {
|
||||
ChunkStream cs(s);
|
||||
QByteArray ba;
|
||||
s >> ba;
|
||||
ba = qUncompress(ba);
|
||||
ChunkStream cs(ba);
|
||||
while (!cs.atEnd()) {
|
||||
switch (cs.read()) {
|
||||
case 1: m.vertices_ = cs.getData<QVector<GLfloat> >(); break;
|
||||
|
||||
@@ -28,18 +28,23 @@ GLObjectBase * loadFromQGLFile(const QString & filepath) {
|
||||
}
|
||||
f.open(QIODevice::ReadOnly);
|
||||
QDataStream s(&f);
|
||||
s.setVersion(QDataStream::Qt_4_8);
|
||||
char sign[4];
|
||||
s.readRawData(sign, 4);
|
||||
if ((sign[0] != 'Q') || (sign[1] != 'G') || (sign[2] != 'L') || (sign[3] != 'F')) {
|
||||
qDebug() << "[Loader QGL] Error: \"" + filepath + "\" is not valid QGL file!";
|
||||
return 0;
|
||||
}
|
||||
QByteArray fc_; s >> fc_;
|
||||
QByteArray fc = qUncompress(fc_);
|
||||
if (fc.isEmpty()) return 0;
|
||||
QDataStream os(fc);
|
||||
GLObjectBase * root = 0;
|
||||
os >> root;
|
||||
ushort version = 0xFFFF;
|
||||
f.peek((char*)&version, 2);
|
||||
if (version == 1) {
|
||||
s.skipRawData(2);
|
||||
s >> root;
|
||||
} else {
|
||||
qDebug() << "[Loader QGL] Error: \"" + filepath + "\" unsupported version!";
|
||||
return 0;
|
||||
}
|
||||
root->buildTransform();
|
||||
if (root->name().isEmpty())
|
||||
root->setName(QFileInfo(f).baseName());
|
||||
@@ -54,11 +59,11 @@ bool saveToQGLFile(const QString & filepath, const GLObjectBase * o) {
|
||||
return false;
|
||||
f.resize(0);
|
||||
QDataStream s(&f);
|
||||
s.setVersion(QDataStream::Qt_4_8);
|
||||
char sign[4] = {'Q', 'G', 'L', 'F'};
|
||||
ushort version = 1;
|
||||
s.writeRawData(sign, 4);
|
||||
QByteArray fc;
|
||||
QDataStream os(&fc, QIODevice::ReadWrite);
|
||||
os << o;
|
||||
s << qCompress(fc);
|
||||
s.writeRawData((char*)&version, 2);
|
||||
s << o;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
||||
view->setHoverHaloFillAlpha(0.);
|
||||
view->setSelectionHaloFillAlpha(0.);
|
||||
view->setBackColor(Qt::lightGray);
|
||||
view->setDepthStart(1.);
|
||||
view->setDepthEnd(10000.);
|
||||
view->setDepthStart(0.001);
|
||||
view->setDepthEnd(100000.);
|
||||
|
||||
spinFOV->setValue(view->FOV());
|
||||
spinDepthStart->setValue(view->depthStart());
|
||||
@@ -80,6 +80,11 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
||||
spinBloomRadius->setValue(view->feature(QGLView::qglBloomRadius).toInt());
|
||||
spinBloomThreshold->setValue(view->feature(QGLView::qglBloomThreshold).toDouble());
|
||||
spinSSAORadius->setValue(view->feature(QGLView::qglSSAORadius).toInt());
|
||||
groupDOF->setChecked(view->isFeatureEnabled(QGLView::qglDepthOfFieldEnabled));
|
||||
checkDOFAutoFocus->setChecked(view->isFeatureEnabled(QGLView::qglDepthOfFieldAutoFocusEnabled));
|
||||
spinDOFFocus->setValue(view->feature(QGLView::qglDepthOfFieldFocus).toDouble());
|
||||
spinDOFDiaphragm->setValue(view->feature(QGLView::qglDepthOfFieldDiaphragm).toDouble());
|
||||
spinDOFSpeed->setValue(view->feature(QGLView::qglDepthOfFieldAutoFocusSpeed).toDouble());
|
||||
|
||||
axis = new GLObjectBase();
|
||||
GLObjectBase * obj;
|
||||
@@ -104,6 +109,10 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
||||
|
||||
connect(view, SIGNAL(selectionChanged(GLObjectBase*,GLObjectBase*)), this, SLOT(selectionChanged(GLObjectBase*,GLObjectBase*)));
|
||||
connect(matEditor, SIGNAL(changed()), this, SLOT(materialChanged()));
|
||||
|
||||
//view->addObject(&partsys);
|
||||
partsys.material().color_diffuse = Qt::red;
|
||||
treeProps->assignObject(&partsys);
|
||||
}
|
||||
|
||||
|
||||
@@ -140,6 +149,11 @@ void MainWindow::on_view_glKeyPressEvent(QKeyEvent * e) {
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_view_glInitializeDone() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::loadFile(const QString & path) {
|
||||
prev_path = path;
|
||||
importFile(path);
|
||||
@@ -216,6 +230,7 @@ void MainWindow::on_comboRenderer_currentIndexChanged(int val) {
|
||||
switch (val) {
|
||||
case 0: view->setRenderer(new RendererSimple(view), &pr); break;
|
||||
case 1: view->setRenderer(new RendererDeferredShading(view), &pr); break;
|
||||
case 2: view->setRenderer(new RendererRT(view), &pr); break;
|
||||
}
|
||||
if (pr != 0) delete pr;
|
||||
}
|
||||
@@ -250,7 +265,9 @@ void MainWindow::on_actionSave_triggered() {
|
||||
f += ".qgl";
|
||||
prev_path = f;
|
||||
view->removeObject(axis);
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
saveToQGLFile(f, &(view->rootObject()));
|
||||
QApplication::restoreOverrideCursor();
|
||||
view->addObject(axis);
|
||||
}
|
||||
|
||||
@@ -262,7 +279,9 @@ void MainWindow::on_actionSaveSelected_triggered() {
|
||||
if (f.right(4).toLower() != ".qgl")
|
||||
f += ".qgl";
|
||||
prev_path = f;
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
saveToQGLFile(f, sel_obj);
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
#include "loader_ase.h"
|
||||
#include "renderer_simple.h"
|
||||
#include "renderer_deferred_shading.h"
|
||||
#include "renderer_rt.h"
|
||||
#include "glparticles_system.h"
|
||||
#include "water_system.h"
|
||||
#include "rope_system.h"
|
||||
|
||||
@@ -65,6 +67,8 @@ private:
|
||||
Material m;
|
||||
bool isChanged;
|
||||
|
||||
GLParticlesSystem partsys;
|
||||
|
||||
private slots:
|
||||
void on_spinFOV_valueChanged(double val) {view->setFOV(val);}
|
||||
void on_spinDepthStart_valueChanged(double val) {view->setDepthStart(val);}
|
||||
@@ -90,6 +94,11 @@ private slots:
|
||||
void on_groupReflections_clicked(bool val) {view->setFeature(QGLView::qglReflectionsEnabled, val);}
|
||||
void on_checkSoftShadows_clicked(bool val) {view->setFeature(QGLView::qglShadowsSoftEnabled, val);}
|
||||
void on_groupSSAO_clicked(bool val) {view->setFeature(QGLView::qglSSAOEnabled, val);}
|
||||
void on_groupDOF_clicked(bool val) {view->setFeature(QGLView::qglDepthOfFieldEnabled, val);}
|
||||
void on_checkDOFAutoFocus_clicked(bool val) {view->setFeature(QGLView::qglDepthOfFieldAutoFocusEnabled, val);}
|
||||
void on_spinDOFFocus_valueChanged(double val) {view->setFeature(QGLView::qglDepthOfFieldFocus, val);}
|
||||
void on_spinDOFDiaphragm_valueChanged(double val) {view->setFeature(QGLView::qglDepthOfFieldDiaphragm, val);}
|
||||
void on_spinDOFSpeed_valueChanged(double val) {view->setFeature(QGLView::qglDepthOfFieldAutoFocusSpeed, val);}
|
||||
void on_spinAccom_valueChanged(double val) {view->setFeature(QGLView::qglEyeAccomodationTime, val);}
|
||||
void on_spinAccomMS_valueChanged(double val) {view->setFeature(QGLView::qglEyeAccomodationMaxSpeed, val);}
|
||||
void on_checkReflectionsBlur_clicked(bool val) {view->setFeature(QGLView::qglReflectionsBlur, val);}
|
||||
@@ -109,6 +118,7 @@ private slots:
|
||||
void on_actionOpen_triggered();
|
||||
|
||||
void on_view_glKeyPressEvent(QKeyEvent * e);
|
||||
void on_view_glInitializeDone();
|
||||
void on_view_keyEvent(Qt::Key k, Qt::KeyboardModifiers m);
|
||||
|
||||
void on_treeObjects_itemClicked(QTreeWidgetItem * ti, int col);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1125</width>
|
||||
<height>808</height>
|
||||
<height>905</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@@ -54,7 +54,7 @@
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget_2">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_5">
|
||||
<attribute name="title">
|
||||
@@ -97,7 +97,7 @@
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="comboRenderer">
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
@@ -109,6 +109,11 @@
|
||||
<string>Deferred shading</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>RT</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
@@ -322,8 +327,11 @@
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="spinDepthStart">
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>9999999.000000000000000</double>
|
||||
<double>999999999.000000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
@@ -345,8 +353,11 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="spinDepthEnd">
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>9999999.000000000000000</double>
|
||||
<double>999999999.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -706,6 +717,112 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupDOF">
|
||||
<property name="title">
|
||||
<string>Depth of field</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_11">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<property name="labelAlignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_15">
|
||||
<property name="text">
|
||||
<string>Diaphragm</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_16">
|
||||
<property name="text">
|
||||
<string>Max speed</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="SpinSlider" name="spinDOFDiaphragm">
|
||||
<property name="minimum">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1024.000000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>8.000000000000000</double>
|
||||
</property>
|
||||
<property name="squareScale">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="SpinSlider" name="spinDOFSpeed">
|
||||
<property name="minimum">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10.000000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
<property name="squareScale">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_21">
|
||||
<property name="text">
|
||||
<string>Focus</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="SpinSlider" name="spinDOFFocus">
|
||||
<property name="minimum">
|
||||
<double>0.100000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>1000.000000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
<property name="squareScale">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="spinMaximum">
|
||||
<double>999999.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="checkDOFAutoFocus">
|
||||
<property name="text">
|
||||
<string>Auto focus</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupReflections">
|
||||
<property name="title">
|
||||
@@ -867,6 +984,22 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_4">
|
||||
<attribute name="title">
|
||||
<string>Страница</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<widget class="PropertyEditor" name="treeProps">
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -1054,6 +1187,11 @@
|
||||
<header>globject_editor.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>PropertyEditor</class>
|
||||
<extends>QTreeWidget</extends>
|
||||
<header>propertyeditor.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="qglview.qrc"/>
|
||||
|
||||
@@ -77,6 +77,11 @@ QGLView::QGLView(QWidget * parent): QGraphicsView(parent), fbo_selection(3) {
|
||||
setFeature(qglReflectionsBlur, true);
|
||||
setFeature(qglSSAOEnabled, false);
|
||||
setFeature(qglSSAORadius, 5);
|
||||
setFeature(qglDepthOfFieldEnabled, false);
|
||||
setFeature(qglDepthOfFieldAutoFocusEnabled, true);
|
||||
setFeature(qglDepthOfFieldAutoFocusSpeed, 0.1);
|
||||
setFeature(qglDepthOfFieldFocus, 1.);
|
||||
setFeature(qglDepthOfFieldDiaphragm, 8.);
|
||||
mouse_first = mouseSelect_ = hoverHalo_ = selectionHalo_ = true;
|
||||
fogEnabled_ = is_init = grabMouse_ = mouseRotate_ = mouseThis_ = shaders_bind = changed_ = false;
|
||||
rmode = GLObjectBase::Fill;
|
||||
|
||||
@@ -100,7 +100,12 @@ public:
|
||||
qglReflectionsEnabled,
|
||||
qglReflectionsBlur,
|
||||
qglSSAOEnabled,
|
||||
qglSSAORadius
|
||||
qglSSAORadius,
|
||||
qglDepthOfFieldEnabled,
|
||||
qglDepthOfFieldAutoFocusEnabled,
|
||||
qglDepthOfFieldAutoFocusSpeed,
|
||||
qglDepthOfFieldFocus,
|
||||
qglDepthOfFieldDiaphragm
|
||||
};
|
||||
|
||||
Q_ENUMS (FogMode)
|
||||
|
||||
@@ -36,7 +36,8 @@ fbo_g(5, true, GL_RGBA16F), fbo_out(3, false, GL_RGBA16F), fbo_hsmall(1, false,
|
||||
<< ShaderPair("ssr_blur", &shader_ssr_blur)
|
||||
<< ShaderPair("ssr_merge", &shader_ssr_merge)
|
||||
<< ShaderPair("ssao_blur", &shader_ssao_blur)
|
||||
<< ShaderPair("ssao_merge", &shader_ssao_merge);
|
||||
<< ShaderPair("ssao_merge", &shader_ssao_merge)
|
||||
<< ShaderPair("dof", &shader_dof);
|
||||
for (int i = 0; i < shaders.size(); ++i)
|
||||
*(shaders[i].second) = 0;
|
||||
lights_per_pass = 8;
|
||||
@@ -288,6 +289,7 @@ void RendererDeferredShading::renderScene() {
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_g.colorTexture(0));
|
||||
glActiveTextureChannel(2);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_g.colorTexture(1));
|
||||
fbo_g.bindDepthTexture(7);
|
||||
shader_ssr->bind();
|
||||
shader_ssr->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_ssr->setUniformValue("z_far", GLfloat(view.depthEnd()));
|
||||
@@ -296,6 +298,7 @@ void RendererDeferredShading::renderScene() {
|
||||
shader_ssr->setUniformValue("t0", 1);
|
||||
shader_ssr->setUniformValue("t1", 2);
|
||||
shader_ssr->setUniformValue("ts", 0);
|
||||
shader_ssr->setUniformValue("td", 7);
|
||||
glDrawQuad(shader_ssr, corner_dirs);
|
||||
|
||||
glActiveTextureChannel(0);
|
||||
@@ -309,6 +312,8 @@ void RendererDeferredShading::renderScene() {
|
||||
int crad = 1;
|
||||
for (int p = 0; p < passes; ++p) {
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(lri));
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//_MIPMAP_LINEAR);
|
||||
fbo_out.setWriteBuffer(lwi);
|
||||
shader_ssr_blur->setUniformValue("radius", GLfloat(crad));
|
||||
glDrawQuad(shader_ssr_blur);
|
||||
@@ -341,6 +346,53 @@ void RendererDeferredShading::renderScene() {
|
||||
piSwap<int>(wi, ri);
|
||||
}
|
||||
|
||||
if (view.isFeatureEnabled(QGLView::qglDepthOfFieldEnabled)) {
|
||||
if (view.isFeatureEnabled(QGLView::qglDepthOfFieldAutoFocusEnabled)) {
|
||||
GLfloat cw;
|
||||
//glReadBuffer();
|
||||
fbo_g.bind();
|
||||
glReadPixels(fbo_out.width() / 2, fbo_out.height() / 2, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &cw);
|
||||
fbo_out.bind();
|
||||
const double _pe = 2.4e-7;
|
||||
double cz = cw + cw - 1;
|
||||
cz = ((_pe - 2.) * view.depthStart()) / (cz + _pe - 1.); // infinite depth
|
||||
double z = view.feature(QGLView::qglDepthOfFieldFocus).toDouble(),
|
||||
s = view.feature(QGLView::qglDepthOfFieldAutoFocusSpeed).toDouble();
|
||||
z = z * (1. - s) + cz * s;
|
||||
view.setFeature(QGLView::qglDepthOfFieldFocus, z);
|
||||
}
|
||||
shader_dof->bind();
|
||||
shader_dof->setUniformValue("qgl_ModelViewProjectionMatrix", QMatrix4x4());
|
||||
shader_dof->setUniformValue("z_far", GLfloat(view.depthEnd()));
|
||||
shader_dof->setUniformValue("z_near", GLfloat(view.depthStart()));
|
||||
shader_dof->setUniformValue("focus", GLfloat(view.feature(QGLView::qglDepthOfFieldFocus).toDouble()));
|
||||
shader_dof->setUniformValue("diaphragm", GLfloat(view.feature(QGLView::qglDepthOfFieldDiaphragm).toDouble()));
|
||||
shader_dof->setUniformValue("t0", 0);
|
||||
shader_dof->setUniformValue("td", 7);
|
||||
fbo_g.bindDepthTexture(7);
|
||||
glActiveTextureChannel(0);
|
||||
|
||||
int passes = 3;
|
||||
float crad = 1.;
|
||||
for (int p = 0; p < passes; ++p) {
|
||||
shader_dof->setUniformValue("radius", GLfloat(crad));
|
||||
fbo_out.setWriteBuffer(wi);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||
shader_dof->setUniformValue("dt", QVector2D(1. / fbo_out.width(), 0.));
|
||||
glDrawQuad(shader_dof);
|
||||
piSwap<int>(wi, ri);
|
||||
fbo_out.setWriteBuffer(wi);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||
shader_dof->setUniformValue("dt", QVector2D(0., 1. / fbo_out.height()));
|
||||
glDrawQuad(shader_dof);
|
||||
piSwap<int>(wi, ri);
|
||||
crad *= 2.;
|
||||
}
|
||||
|
||||
glActiveTextureChannel(0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||
}
|
||||
|
||||
if (view.isFeatureEnabled(QGLView::qglEyeAccomodationEnabled)) {
|
||||
fbo_hsmall.bind();
|
||||
fbo_hsmall.setWriteBuffer(0);
|
||||
|
||||
@@ -48,7 +48,7 @@ private:
|
||||
QGLShaderProgram * shader_fxaa, * shader_ds_0, * shader_ds_1, * shader_hdr, * shader_small;
|
||||
QGLShaderProgram * shader_bloom_0, * shader_bloom_1, * shader_motion_blur, * shader_fbo_add;
|
||||
QGLShaderProgram * shader_shadow, * shader_ssr, * shader_ssr_blur, * shader_ssr_merge;
|
||||
QGLShaderProgram * shader_ssao_blur, * shader_ssao_merge;
|
||||
QGLShaderProgram * shader_ssao_blur, * shader_ssao_merge, * shader_dof;
|
||||
GLuint tnoise;
|
||||
QVector<ShaderPair> shaders;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ const vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
|
||||
void main(void) {
|
||||
//float z = pos.w;//((z_near / (z_near-z_far)) * z_far) / (pos.w - (z_far / (z_far-z_near)));
|
||||
float logz = log(pos.w * C + 1.) * FC;
|
||||
//float logz = log(pos.w * C + 1.) * FC;
|
||||
vec4 dc = qgl_FragColor;
|
||||
vec2 tc = qgl_FragTexture.xy;
|
||||
float hei = dot(texture(qgl_Material.map_relief.map, tc).rgb, luma) * qgl_Material.map_relief.amount + qgl_Material.map_relief.offset;
|
||||
@@ -44,7 +44,7 @@ void main(void) {
|
||||
//speed /= abs(pos.z);
|
||||
|
||||
//gl_FragDepth = logz;
|
||||
qgl_FragData[0] = vec4(dc.rgb, pos.w);
|
||||
qgl_FragData[0] = vec4(dc.rgb, 0.);
|
||||
qgl_FragData[1] = vec4(n.xyz, specularity + round(reflectivity * 100));
|
||||
qgl_FragData[2] = vec4(spec.rgb, hei);
|
||||
qgl_FragData[3] = vec4(self.rgb, bn.x);
|
||||
|
||||
@@ -24,7 +24,7 @@ float sh_pow, sh_mul, dist, NdotL, NdotH, spot, ldist, diff, sdist, shadow;
|
||||
|
||||
float getShadow(int light, vec3 view_pos, vec3 dpos) {
|
||||
shp = qgl_Light[light].shadowMatrix * vec4(view_pos + dpos, 1);
|
||||
shp.z -= 0.05;
|
||||
shp.z -= z_near / 20.;
|
||||
return textureProj(qgl_Light[light].shadow, shp);
|
||||
}
|
||||
|
||||
@@ -87,18 +87,26 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const float _pe = 2.4e-7;
|
||||
|
||||
void main(void) {
|
||||
//if (d == 1.) discard;
|
||||
ivec2 tc = ivec2(gl_FragCoord.xy);
|
||||
vec4 v0 = texelFetch(t0, tc, 0);
|
||||
if (v0.w == 0.) {
|
||||
float z = texelFetch(td, tc, 0).r;
|
||||
if (z == 1.) {
|
||||
qgl_FragData[0] = back_color;
|
||||
return;
|
||||
}
|
||||
vec4 v1 = texelFetch(t1, tc, 0),
|
||||
vec4 v0 = texelFetch(t0, tc, 0),
|
||||
v1 = texelFetch(t1, tc, 0),
|
||||
v2 = texelFetch(t2, tc, 0),
|
||||
v3 = texelFetch(t3, tc, 0),
|
||||
v4 = texelFetch(t4, tc, 0);
|
||||
|
||||
z = z + z - 1;
|
||||
z = ((_pe - 2.) * z_near) / (z + _pe - 1.); // infinite depth
|
||||
|
||||
vec2 sp = gl_FragCoord.xy * dt * 2 - vec2(1, 1);
|
||||
vec3 dc = v0.rgb, n = v1.xyz;
|
||||
bn = normalize(vec3(v3.w, v4.zw));
|
||||
@@ -113,7 +121,7 @@ void main(void) {
|
||||
pos.z = posz;*/
|
||||
|
||||
pos.w = 1;
|
||||
pos.xyz = view_dir * v0.w;
|
||||
pos.xyz = view_dir * z;
|
||||
pos.z = -pos.z;
|
||||
|
||||
//pos.z = posz;
|
||||
@@ -133,10 +141,10 @@ void main(void) {
|
||||
sh_mul = max(1. - specularity, 0.0001);
|
||||
for (int i = 0; i < 8; ++i)
|
||||
calcLight(i, n, v, v2);
|
||||
calcLight(0, n, v, v2);
|
||||
// calcLight(0, n, v, v2);
|
||||
|
||||
qgl_FragData[0] = vec4(max(vec3(0), li * dc + si * v2.rgb + v3.rgb + texelFetch(t_pp, tc, 0).rgb), v0.w);
|
||||
//qgl_FragData[0].rgb = vec3(abs((v0.w)/50));
|
||||
//qgl_FragData[0].rgb = vec3(-z);
|
||||
//qgl_FragData[0].rgb = li + vec3(texelFetch(t_pp, tc, 0).xyz);
|
||||
//shd = shd - shp.w;
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
#version 150
|
||||
|
||||
in float logz;
|
||||
|
||||
uniform vec4 id;
|
||||
|
||||
void main(void) {
|
||||
gl_FragDepth = logz;
|
||||
qgl_FragData[0] = id;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
#version 150
|
||||
|
||||
out float logz;
|
||||
|
||||
uniform float z_near, z_far;
|
||||
|
||||
const float C = 0.0001;
|
||||
float FC = 1. / log(z_far * C + 1.);
|
||||
|
||||
void main(void) {
|
||||
vec4 pos = qgl_ftransform();
|
||||
logz = log(pos.w * C + 1.) * FC;
|
||||
gl_Position = pos;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
#version 150
|
||||
|
||||
uniform sampler2D t0, t1, ts, tbs;
|
||||
uniform sampler2D t0, t1, ts, td, tbs;
|
||||
uniform float z_near, z_far;
|
||||
uniform mat4 mat_proj;
|
||||
uniform vec3 cam_aim, cam_pos;
|
||||
|
||||
in vec3 view_dir;
|
||||
|
||||
const float _pe = 2.4e-7;
|
||||
|
||||
void main(void) {
|
||||
ivec2 tc = ivec2(gl_FragCoord.xy);
|
||||
vec4 v0 = texelFetch(t0, tc, 0), v1 = texelFetch(t1, tc, 0), vs = texelFetch(ts, tc, 0);
|
||||
vec3 sp = vec3(qgl_FragTexture.xy, v0.w);
|
||||
vec2 tsp;
|
||||
vec4 pos;
|
||||
float z = texelFetch(td, tc, 0).r;
|
||||
z = z + z - 1;
|
||||
z = ((_pe - 2.) * z_near) / (z + _pe - 1.); // infinite depth
|
||||
pos.w = 1;
|
||||
pos.xyz = view_dir * v0.w;
|
||||
pos.xyz = view_dir * z;
|
||||
//pos.z = -pos.z;
|
||||
vec4 spos = pos;
|
||||
vec4 tpos;
|
||||
|
||||
@@ -22,9 +28,11 @@ void main(void) {
|
||||
vec3 vd = -normalize(vec3(-view_dir.xy, view_dir.z));
|
||||
vec3 rn = reflect(vd, n);
|
||||
//rn.z += 1.;
|
||||
float coeff = clamp(1. - (dot(vec3(0,0,1), n)), 0, 1), cz = v0.w;
|
||||
float coeff = clamp(1. - (dot(vec3(0,0,1), n)), 0, 1);
|
||||
coeff = coeff*coeff;
|
||||
/*coeff = coeff*coeff;
|
||||
coeff = coeff*coeff;
|
||||
coeff = coeff*coeff;*/
|
||||
float reflectivity = 0.;
|
||||
float specularity = modf(v1.w, reflectivity);
|
||||
|
||||
@@ -33,12 +41,15 @@ void main(void) {
|
||||
vec4 tv0;
|
||||
float l = z_far * 0.5;
|
||||
pos.xyz += rn * l;
|
||||
for (i = 0; i < 20; ++i) {
|
||||
float cz;
|
||||
for (i = 0; i < 24; ++i) {
|
||||
tpos = mat_proj * pos;
|
||||
tsp = -(tpos.xy / tpos.w) / 2. + 0.5;
|
||||
tv0 = texture(t0, tsp);
|
||||
cz = texture(td, tsp).r;
|
||||
cz = cz + cz - 1;
|
||||
cz = ((_pe - 2.) * z_near) / (cz + _pe - 1.); // infinite depth
|
||||
l *= 0.5;
|
||||
pos.xyz += rn * (step(pos.z, tv0.w) * 2. - 1.) * l;
|
||||
pos.xyz += rn * (step(pos.z, cz) * 2. - 1.) * l;
|
||||
}
|
||||
|
||||
vec2 ess = abs(tsp - vec2(0.5, 0.5)) - vec2(0.3, 0.3);
|
||||
@@ -52,4 +63,5 @@ void main(void) {
|
||||
vec3 rvs = texture(ts, tsp).rgb;
|
||||
|
||||
qgl_FragData[0] = vec4(rvs.rgb, coeff / 1.1 + clamp(round(blur * 10), 0, 1000));
|
||||
//qgl_FragData[0] = vec4(rvs.rgb, cz/5);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ void main(void) {
|
||||
float r = float(radius);
|
||||
vec4 v0 = texture(t0, tc);
|
||||
float rad;
|
||||
float coeff = modf(v0.a, rad) * 1.1;
|
||||
float coeff = modf(v0.w, rad) * 1.1;
|
||||
rad /= 10.;
|
||||
rad *= 2;
|
||||
float o = radius * rad, o2 = radius * rad * 2;
|
||||
|
||||
@@ -6,10 +6,10 @@ void main(void) {
|
||||
ivec2 tc = ivec2(gl_FragCoord.xy);
|
||||
vec4 v0 = texelFetch(t0, tc, 0), vg1 = texelFetch(tg1, tc, 0), vs = texelFetch(ts, tc, 0);
|
||||
float rad;
|
||||
float coeff = clamp(modf(v0.a, rad) * 1.1, 0., 1.);
|
||||
float coeff = clamp(modf(v0.w, rad) * 1.1, 0., 1.);
|
||||
float reflectivity = 0.;
|
||||
float specularity = modf(vg1.w, reflectivity);
|
||||
reflectivity = clamp(reflectivity / 100., 0., 1.);
|
||||
qgl_FragData[0].rgb = mix(vs.rgb, v0.rgb, coeff * reflectivity);
|
||||
//qgl_FragData[0].rgb = vec3(vs.rgb*coeff * reflectivity);
|
||||
//qgl_FragData[0].rgb = vec3(v0.w);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user