git-svn-id: svn://db.shs.com.ru/libs@54 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
726
qglview/data/shadows.dae
Normal file
726
qglview/data/shadows.dae
Normal file
File diff suppressed because one or more lines are too long
@@ -40,7 +40,8 @@ GLFramebuffer::~GLFramebuffer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GLFramebuffer::resize(int width, int height) {
|
void GLFramebuffer::resize(int width, int height, bool force) {
|
||||||
|
if ((wid == width) && (hei == height) && !force) return;
|
||||||
wid = width;
|
wid = width;
|
||||||
hei = height;
|
hei = height;
|
||||||
deleteGLFramebuffer(fbo);
|
deleteGLFramebuffer(fbo);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public:
|
|||||||
QSize size() const {return QSize(wid, hei);}
|
QSize size() const {return QSize(wid, hei);}
|
||||||
QImage grab() const;
|
QImage grab() const;
|
||||||
|
|
||||||
void resize(int width, int height);
|
void resize(int width, int height, bool force = false);
|
||||||
void bind();
|
void bind();
|
||||||
void release();
|
void release();
|
||||||
void setReadBuffer(int index) {glReadBuffer(GL_COLOR_ATTACHMENT0 + index);}
|
void setReadBuffer(int index) {glReadBuffer(GL_COLOR_ATTACHMENT0 + index);}
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ void GLObjectBase::render(int * id, QMap<int, GLObjectBase * > * ids, int sh_id_
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Light::Light(): GLObjectBase(), shadow_map(1, true, GL_R16F) {
|
Light::Light(): GLObjectBase(), shadow_map(0, true, GL_R16F) {
|
||||||
type_ = GLObjectBase::Light;
|
type_ = GLObjectBase::Light;
|
||||||
light_type = Omni;
|
light_type = Omni;
|
||||||
intensity = 1.;
|
intensity = 1.;
|
||||||
@@ -221,7 +221,7 @@ Light::Light(): GLObjectBase(), shadow_map(1, true, GL_R16F) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Light::Light(const QVector3D & p, const QColor & c, GLdouble i): GLObjectBase(), shadow_map(1, true, GL_R16F) {
|
Light::Light(const QVector3D & p, const QColor & c, GLdouble i): GLObjectBase(), shadow_map(0, true, GL_R16F) {
|
||||||
type_ = GLObjectBase::Light;
|
type_ = GLObjectBase::Light;
|
||||||
light_type = Omni;
|
light_type = Omni;
|
||||||
pos_ = p;
|
pos_ = p;
|
||||||
@@ -261,10 +261,20 @@ void Light::draw(QGLShaderProgram * prog, bool simplest) {
|
|||||||
bool l = glIsEnabled(GL_LIGHTING);
|
bool l = glIsEnabled(GL_LIGHTING);
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glPointSize(8.);
|
glPointSize(8.);
|
||||||
glBegin(GL_POINTS);
|
|
||||||
glColor3f(0., 0., 0.);
|
glColor3f(0., 0., 0.);
|
||||||
|
glBegin(GL_POINTS);
|
||||||
glVertex3f(0., 0., 0.);
|
glVertex3f(0., 0., 0.);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
double s = 10;
|
||||||
|
if (light_type != Omni) {
|
||||||
|
glBegin(GL_LINES);
|
||||||
|
QVector4D dir = QVector4D(direction);
|
||||||
|
if (raw_matrix)
|
||||||
|
dir = transform().inverted() * dir;
|
||||||
|
glVertex3f(0., 0., 0.);
|
||||||
|
glVertex3f(dir.x() * s, dir.y() * s, dir.z() * s);
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
if (l) glEnable(GL_LIGHTING);
|
if (l) glEnable(GL_LIGHTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -233,10 +233,10 @@ void GLRendererBase::renderShadow(Light * l, QGLShaderProgram * prog, QMatrix4x4
|
|||||||
Camera cam;
|
Camera cam;
|
||||||
QVector3D wp = l->worldPos();
|
QVector3D wp = l->worldPos();
|
||||||
cam.setPos(wp);
|
cam.setPos(wp);
|
||||||
cam.setAim(wp + (l->worldTransform() * QVector4D(l->direction)).toVector3D());
|
cam.setAim(wp + (/*l->worldTransform() */ QVector4D(l->direction)).toVector3D());
|
||||||
cam.setDepthStart(view.camera().depthStart());
|
cam.setDepthStart(view.camera().depthStart());
|
||||||
cam.setDepthEnd(view.camera().depthEnd());
|
cam.setDepthEnd(view.camera().depthEnd());
|
||||||
cam.setFOV(l->angle_end / 2.);
|
cam.setFOV(l->angle_end);
|
||||||
cam.apply(1.);
|
cam.apply(1.);
|
||||||
RenderingParameters rpl;
|
RenderingParameters rpl;
|
||||||
rpl.pass = GLObjectBase::Solid;
|
rpl.pass = GLObjectBase::Solid;
|
||||||
@@ -244,7 +244,11 @@ void GLRendererBase::renderShadow(Light * l, QGLShaderProgram * prog, QMatrix4x4
|
|||||||
rpl.textures = rpl.light = rpl.fog = false;
|
rpl.textures = rpl.light = rpl.fog = false;
|
||||||
rpl.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX);
|
rpl.view_matrix = getGLMatrix(GL_MODELVIEW_MATRIX);
|
||||||
rpl.proj_matrix = getGLMatrix(GL_PROJECTION_MATRIX);
|
rpl.proj_matrix = getGLMatrix(GL_PROJECTION_MATRIX);
|
||||||
l->shadow_matrix = mat * (rpl.proj_matrix * rpl.view_matrix);
|
QMatrix4x4 mbias;
|
||||||
|
mbias.scale(0.5, 0.5, 0.5);
|
||||||
|
mbias.translate(1., 1., 1.);
|
||||||
|
l->shadow_matrix = mbias*rpl.proj_matrix*rpl.view_matrix*mat;//;// * mbias;
|
||||||
|
//qDebug() << mbias;
|
||||||
//glPushMatrix();
|
//glPushMatrix();
|
||||||
renderSingleShadow(view.objects_, rpl);
|
renderSingleShadow(view.objects_, rpl);
|
||||||
//glPopMatrix();
|
//glPopMatrix();
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const char qgl_uniform[] =
|
|||||||
"uniform mat4 qgl_ModelViewProjectionMatrixInverseTranspose;\n";
|
"uniform mat4 qgl_ModelViewProjectionMatrixInverseTranspose;\n";
|
||||||
|
|
||||||
const char qgl_structs[] =
|
const char qgl_structs[] =
|
||||||
"const int qgl_MaxLights = 16;\n"
|
"const int qgl_MaxLights = 8;\n"
|
||||||
"struct QGLLight {\n"
|
"struct QGLLight {\n"
|
||||||
" vec4 color;\n"
|
" vec4 color;\n"
|
||||||
" vec4 position;\n"
|
" vec4 position;\n"
|
||||||
@@ -65,7 +65,7 @@ const char qgl_structs[] =
|
|||||||
" float constantAttenuation;\n"
|
" float constantAttenuation;\n"
|
||||||
" float linearAttenuation;\n"
|
" float linearAttenuation;\n"
|
||||||
" float quadraticAttenuation;\n"
|
" float quadraticAttenuation;\n"
|
||||||
" sampler2D shadow;\n"
|
" sampler2DShadow shadow;\n"
|
||||||
" mat4 shadowMatrix;\n"
|
" mat4 shadowMatrix;\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"struct QGLMap {\n"
|
"struct QGLMap {\n"
|
||||||
@@ -216,7 +216,7 @@ void setUniformLight(QGLShaderProgram * prog, Light * light, QString ulightn, co
|
|||||||
QMatrix4x4 m = mat * light->worldTransform();
|
QMatrix4x4 m = mat * light->worldTransform();
|
||||||
QVector4D pos(0, 0, 0, 1.), dir(light->direction);
|
QVector4D pos(0, 0, 0, 1.), dir(light->direction);
|
||||||
pos = m * pos;
|
pos = m * pos;
|
||||||
dir = (m * dir).normalized();
|
dir = (mat * dir).normalized();
|
||||||
double ang_start = light->angle_start / 2., ang_end = light->angle_end / 2.;
|
double ang_start = light->angle_start / 2., ang_end = light->angle_end / 2.;
|
||||||
if (light->light_type == Light::Omni)
|
if (light->light_type == Light::Omni)
|
||||||
ang_start = ang_end = 180.;
|
ang_start = ang_end = 180.;
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
|||||||
GLTextureManager::addSearchPath("data");
|
GLTextureManager::addSearchPath("data");
|
||||||
GLTextureManager::addSearchPath("data/images");
|
GLTextureManager::addSearchPath("data/images");
|
||||||
GLTextureManager::addSearchPath("data/SU-33_maps");
|
GLTextureManager::addSearchPath("data/SU-33_maps");
|
||||||
obj = loadFromDAEFile("data/room.dae");//new GLPrimitiveEllipsoid(EARTH_WL / 1E+6, EARTH_WL / 1E+6, EARTH_H / 1E+6, 500, 500);//GLPrimitiveCube();
|
obj = loadFromDAEFile("data/shadows.dae");//new GLPrimitiveEllipsoid(EARTH_WL / 1E+6, EARTH_WL / 1E+6, EARTH_H / 1E+6, 500, 500);//GLPrimitiveCube();
|
||||||
//obj->setScale(0.1);
|
//obj->setScale(0.1);
|
||||||
//obj->child("Plane001")->material().map_specularity.color_amount = 0.95;
|
//obj->child("Plane001")->material().map_specularity.color_amount = 0.95;
|
||||||
//obj = new GLPrimitiveEllipsoid(100, 100, 100, 100, 100);//GLPrimitiveCube();
|
//obj = new GLPrimitiveEllipsoid(100, 100, 100, 100, 100);//GLPrimitiveCube();
|
||||||
@@ -103,11 +103,11 @@ MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), Ui::MainWindow()
|
|||||||
view->camera().flyToDistance(500);
|
view->camera().flyToDistance(500);
|
||||||
//view->camera().setMode(Camera::AimMatrix);
|
//view->camera().setMode(Camera::AimMatrix);
|
||||||
Light * l = new Light(view->camera().pos());
|
Light * l = new Light(view->camera().pos());
|
||||||
l->light_type = Light::Cone;
|
/*l->light_type = Light::Cone;
|
||||||
l->direction = QVector3D(1., 0.2, -0.2);
|
l->direction = QVector3D(1., 0.2, -0.2);
|
||||||
l->angle_start = 0.;
|
l->angle_start = 0.;
|
||||||
l->angle_end = 120.;
|
l->angle_end = 120.;*/
|
||||||
l->intensity = 1.;
|
l->intensity = 0.5;
|
||||||
//l->decay_linear = 0.2;
|
//l->decay_linear = 0.2;
|
||||||
l->setName("camera");
|
l->setName("camera");
|
||||||
view->addObject(l);
|
view->addObject(l);
|
||||||
@@ -225,6 +225,15 @@ void MainWindow::glInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::on_pushButton_clicked() {
|
||||||
|
//view->removeLight(view->lightsCount() - 1);
|
||||||
|
//setWindowTitle(QString::number(view->lightsCount()));
|
||||||
|
QVector3D wp = view->light(0)->worldPos();
|
||||||
|
view->camera().setPos(wp);
|
||||||
|
view->camera().setAim(wp + (view->light(0)->worldTransform() * QVector4D(view->light(0)->direction)).toVector3D()*100);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::loadFile(const QString & path) {
|
void MainWindow::loadFile(const QString & path) {
|
||||||
prev_path = path;
|
prev_path = path;
|
||||||
QCursor pcur = cursor();
|
QCursor pcur = cursor();
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ private slots:
|
|||||||
void on_spinBloomThreshold_valueChanged(double val) {view->setFeature(QGLView::qglBloomThreshold, val);}
|
void on_spinBloomThreshold_valueChanged(double val) {view->setFeature(QGLView::qglBloomThreshold, 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();
|
||||||
void on_pushButton_2_clicked() {view->reloadShaders();}
|
void on_pushButton_2_clicked() {view->reloadShaders();}
|
||||||
void on_pushButton_3_clicked();
|
void on_pushButton_3_clicked();
|
||||||
void on_comboBox_currentIndexChanged(int val);
|
void on_comboBox_currentIndexChanged(int val);
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ void QGLView::drawBackground(QPainter * painter, const QRectF & rect) {
|
|||||||
|
|
||||||
|
|
||||||
void QGLView::initializeGL() {
|
void QGLView::initializeGL() {
|
||||||
//qDebug() << "init glview";
|
qDebug() << "init glview";
|
||||||
makeCurrent();
|
makeCurrent();
|
||||||
currentQGLView = (QGLWidget * )viewport();
|
currentQGLView = (QGLWidget * )viewport();
|
||||||
currentGLTextureManager = &textures_manager;
|
currentGLTextureManager = &textures_manager;
|
||||||
@@ -188,6 +188,7 @@ void QGLView::initializeGL() {
|
|||||||
//shader_rope = new QGLShaderProgram(context());
|
//shader_rope = new QGLShaderProgram(context());
|
||||||
reloadThisShaders();
|
reloadThisShaders();
|
||||||
is_init = true;
|
is_init = true;
|
||||||
|
resizeGL(viewport()->width(), viewport()->height());
|
||||||
|
|
||||||
//dynamic_cubemap.loadPathesFromDirectory("e");
|
//dynamic_cubemap.loadPathesFromDirectory("e");
|
||||||
//dynamic_cubemap.load();
|
//dynamic_cubemap.load();
|
||||||
@@ -470,7 +471,8 @@ void QGLView::collectObjectLights(GLObjectBase * o) {
|
|||||||
|
|
||||||
void QGLView::checkCaps() {
|
void QGLView::checkCaps() {
|
||||||
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropic);
|
glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropic);
|
||||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &max_texture_chanels);
|
//glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_texture_chanels);
|
||||||
|
//qDebug() << max_texture_chanels;
|
||||||
//qDebug() << max_texture_chanels;
|
//qDebug() << max_texture_chanels;
|
||||||
shaders_supported = QGLShaderProgram::hasOpenGLShaderPrograms();
|
shaders_supported = QGLShaderProgram::hasOpenGLShaderPrograms();
|
||||||
}
|
}
|
||||||
@@ -501,8 +503,10 @@ void QGLView::applyFog() {
|
|||||||
|
|
||||||
|
|
||||||
void QGLView::resizeGL(int width, int height) {
|
void QGLView::resizeGL(int width, int height) {
|
||||||
|
if (!is_init) return;
|
||||||
aspect = double(width) / double(height);
|
aspect = double(width) / double(height);
|
||||||
if (renderer_ != 0) renderer_->resize(width, height);
|
if (renderer_ != 0) renderer_->resize(width, height);
|
||||||
|
qDebug() << "resize" << width << height;
|
||||||
fbo_selection.resize(width, height);
|
fbo_selection.resize(width, height);
|
||||||
mouse_first = true;
|
mouse_first = true;
|
||||||
iaspect = (aspect == 0.) ? 0. : 1 / aspect;
|
iaspect = (aspect == 0.) ? 0. : 1 / aspect;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ fbo_g(5, true, GL_RGBA16F), fbo_out(3, false, GL_RGB16F), fbo_hsmall(1, false, G
|
|||||||
<< ShaderPair("shadow", &shader_shadow);
|
<< ShaderPair("shadow", &shader_shadow);
|
||||||
for (int i = 0; i < shaders.size(); ++i)
|
for (int i = 0; i < shaders.size(); ++i)
|
||||||
*(shaders[i].second) = 0;
|
*(shaders[i].second) = 0;
|
||||||
lights_per_pass = 2;
|
lights_per_pass = 8;
|
||||||
exposure_ = 1.;
|
exposure_ = 1.;
|
||||||
df = new QWidget();
|
df = new QWidget();
|
||||||
df->setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
|
df->setLayout(new QBoxLayout(QBoxLayout::TopToBottom));
|
||||||
@@ -64,7 +64,8 @@ void RendererDeferredShading::renderScene() {
|
|||||||
QMatrix4x4 mproj = rp.proj_matrix;
|
QMatrix4x4 mproj = rp.proj_matrix;
|
||||||
QMatrix4x4 mproji = rp.proj_matrix_i;
|
QMatrix4x4 mproji = rp.proj_matrix_i;
|
||||||
QMatrix4x4 mview = rp.view_matrix;
|
QMatrix4x4 mview = rp.view_matrix;
|
||||||
QMatrix4x4 mprojviewi = rp.view_matrix_i * rp.proj_matrix_i;
|
QMatrix4x4 mviewi = rp.view_matrix_i;
|
||||||
|
QMatrix4x4 mviewproji = (mview * mproj).inverted();
|
||||||
rp.prev_proj_matrix = prev_proj;
|
rp.prev_proj_matrix = prev_proj;
|
||||||
rp.prev_view_matrix = prev_view;
|
rp.prev_view_matrix = prev_view;
|
||||||
corner_dirs[0] = (QVector4D(-1, -1, 1, 1) * rp.viewproj_matrix).normalized();
|
corner_dirs[0] = (QVector4D(-1, -1, 1, 1) * rp.viewproj_matrix).normalized();
|
||||||
@@ -106,8 +107,8 @@ void RendererDeferredShading::renderScene() {
|
|||||||
//glReleaseShaders();
|
//glReleaseShaders();
|
||||||
fbo_g.release();
|
fbo_g.release();
|
||||||
|
|
||||||
shader_shadow->bind();
|
|
||||||
if (view.isFeatureEnabled(QGLView::qglShadowsEnabled)) {
|
if (view.isFeatureEnabled(QGLView::qglShadowsEnabled)) {
|
||||||
|
shader_shadow->bind();
|
||||||
int sms = view.feature(QGLView::qglShadowsMapSize).toInt();
|
int sms = view.feature(QGLView::qglShadowsMapSize).toInt();
|
||||||
glDisable(GL_TEXTURE_1D);
|
glDisable(GL_TEXTURE_1D);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
@@ -126,10 +127,10 @@ void RendererDeferredShading::renderScene() {
|
|||||||
if (l->light_type == Light::Omni) continue;
|
if (l->light_type == Light::Omni) continue;
|
||||||
l->shadow_map.resize(sms, sms);
|
l->shadow_map.resize(sms, sms);
|
||||||
l->shadow_map.bind();
|
l->shadow_map.bind();
|
||||||
l->shadow_map.setWriteBuffer(0);
|
//l->shadow_map.setWriteBuffer(0);
|
||||||
glClearFramebuffer();
|
//glClearFramebuffer();
|
||||||
//glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
renderShadow(l, shader_shadow, mprojviewi);
|
renderShadow(l, shader_shadow, mviewi);
|
||||||
l->shadow_map.release();
|
l->shadow_map.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,6 +154,8 @@ void RendererDeferredShading::renderScene() {
|
|||||||
shader_ds_1->setUniformValue("td", 5);
|
shader_ds_1->setUniformValue("td", 5);
|
||||||
shader_ds_1->setUniformValue("back_color", view.backColor());
|
shader_ds_1->setUniformValue("back_color", view.backColor());
|
||||||
shader_ds_1->setUniformValue("mat_proji", mproji);
|
shader_ds_1->setUniformValue("mat_proji", mproji);
|
||||||
|
shader_ds_1->setUniformValue("mat_viewi", mviewi);
|
||||||
|
shader_ds_1->setUniformValue("mat_viewproji", mviewproji);
|
||||||
shader_ds_1->setUniformValue("dt", QVector2D(1. / view.viewport()->width(), 1. / view.viewport()->height()));
|
shader_ds_1->setUniformValue("dt", QVector2D(1. / view.viewport()->width(), 1. / view.viewport()->height()));
|
||||||
rp.setUniform(shader_ds_1);
|
rp.setUniform(shader_ds_1);
|
||||||
fbo_g.bindColorTextures();
|
fbo_g.bindColorTextures();
|
||||||
@@ -175,11 +178,7 @@ void RendererDeferredShading::renderScene() {
|
|||||||
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
glBindTexture(GL_TEXTURE_2D, fbo_out.colorTexture(ri));
|
||||||
fbo_out.setWriteBuffer(wi);
|
fbo_out.setWriteBuffer(wi);
|
||||||
setupDSLights(l, mview);
|
setupDSLights(l, mview);
|
||||||
//shader_ds_1->setUniformValue("lightsCount", cplc);
|
|
||||||
glDrawQuad(shader_ds_1);
|
glDrawQuad(shader_ds_1);
|
||||||
//renderObjects(GLObjectBase::Solid, l, 0, true, true, view.isFogEnabled());
|
|
||||||
//renderObjects(GLObjectBase::Transparent, l, 0, true, true, view.isFogEnabled());
|
|
||||||
//glFinish();
|
|
||||||
//break;
|
//break;
|
||||||
}
|
}
|
||||||
//fbo_out.release();
|
//fbo_out.release();
|
||||||
@@ -365,7 +364,10 @@ void RendererDeferredShading::setupDSLights(int pass, const QMatrix4x4 & view_ma
|
|||||||
for (int i = light_start; i < light_end; ++i) {
|
for (int i = light_start; i < light_end; ++i) {
|
||||||
lv << view.lights()[i];
|
lv << view.lights()[i];
|
||||||
glActiveTextureChannel(shadow_start + i - light_start);
|
glActiveTextureChannel(shadow_start + i - light_start);
|
||||||
glBindTexture(GL_TEXTURE_2D, lv.back()->shadow_map.colorTexture());
|
glBindTexture(GL_TEXTURE_2D, lv.back()->shadow_map.depthTexture());
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||||
}
|
}
|
||||||
amb_light.setName("null");
|
amb_light.setName("null");
|
||||||
for (int i = light_end; i < lmax; ++i)
|
for (int i = light_end; i < lmax; ++i)
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ uniform float z_near, z_far;
|
|||||||
uniform bool firstPass;
|
uniform bool firstPass;
|
||||||
uniform vec2 dt;
|
uniform vec2 dt;
|
||||||
uniform vec4 back_color;
|
uniform vec4 back_color;
|
||||||
uniform mat4 mat_proji;
|
uniform mat4 mat_proji, mat_viewi, mat_viewproji;
|
||||||
|
|
||||||
float light_diffuse(int model, vec3 l, vec3 n) {return max(0., dot(l, n));}
|
float light_diffuse(int model, vec3 l, vec3 n) {return max(0., dot(l, n));}
|
||||||
float light_specular(int model, vec3 l, vec3 n, vec3 h, vec3 v, float shininess) {return max(0., pow(dot(n, h), shininess));}
|
float light_specular(int model, vec3 l, vec3 n, vec3 h, vec3 v, float shininess) {return max(0., pow(dot(n, h), shininess));}
|
||||||
|
|
||||||
vec4 pos, lpos;
|
vec4 pos, lpos, shp;
|
||||||
vec3 li, si, ldir, halfV;
|
vec3 li, si, ldir, halfV;
|
||||||
float sh_pow, sh_mul, dist, NdotL, NdotH, spot, ldist, diff;
|
float sh_pow, sh_mul, dist, NdotL, NdotH, spot, ldist, diff;
|
||||||
|
|
||||||
@@ -36,6 +36,25 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
|
|||||||
//spot = clamp(scos / (-qgl_Light[index].endAngleCos + qgl_Light[index].startAngleCos + 0.0001),0,1);
|
//spot = clamp(scos / (-qgl_Light[index].endAngleCos + qgl_Light[index].startAngleCos + 0.0001),0,1);
|
||||||
spot *= smoothstep(qgl_Light[index].endAngleCos, qgl_Light[index].startAngleCos, scos);
|
spot *= smoothstep(qgl_Light[index].endAngleCos, qgl_Light[index].startAngleCos, scos);
|
||||||
//spot = pow(spot, (qgl_Light[index].spotExponent + 0.001));
|
//spot = pow(spot, (qgl_Light[index].spotExponent + 0.001));
|
||||||
|
shp = qgl_Light[index].shadowMatrix*vec4(pos.xyz,1);
|
||||||
|
shp.z -= 0.1;
|
||||||
|
///spot *= textureProj(qgl_Light[index].shadow, shp);
|
||||||
|
float ds = shp.z / 100, dds = ds + ds;
|
||||||
|
float shadow = textureProj(qgl_Light[index].shadow, vec4(shp.xy, shp.zw))/* +
|
||||||
|
textureProj(qgl_Light[index].shadow, vec4(shp.xy + vec2( 0, ds), shp.zw)) +
|
||||||
|
textureProj(qgl_Light[index].shadow, vec4(shp.xy + vec2( 0, -ds), shp.zw)) +
|
||||||
|
textureProj(qgl_Light[index].shadow, vec4(shp.xy + vec2( ds, 0), shp.zw)) +
|
||||||
|
textureProj(qgl_Light[index].shadow, vec4(shp.xy + vec2( -ds, 0), shp.zw)) +
|
||||||
|
textureProj(qgl_Light[index].shadow, vec4(shp.xy + vec2( ds, ds), shp.zw)) +
|
||||||
|
textureProj(qgl_Light[index].shadow, vec4(shp.xy + vec2( ds, -ds), shp.zw)) +
|
||||||
|
textureProj(qgl_Light[index].shadow, vec4(shp.xy + vec2( -ds, -ds), shp.zw)) +
|
||||||
|
textureProj(qgl_Light[index].shadow, vec4(shp.xy + vec2( -ds, ds), shp.zw)) +
|
||||||
|
textureProj(qgl_Light[index].shadow, vec4(shp.xy + vec2( dds, 0), shp.zw)) +
|
||||||
|
textureProj(qgl_Light[index].shadow, vec4(shp.xy + vec2(-dds, 0), shp.zw)) +
|
||||||
|
textureProj(qgl_Light[index].shadow, vec4(shp.xy + vec2( 0, dds), shp.zw)) +
|
||||||
|
textureProj(qgl_Light[index].shadow, vec4(shp.xy + vec2( 0, -dds), shp.zw))*/;
|
||||||
|
spot *= shadow / 1.;
|
||||||
|
///spot *= textureProj(qgl_Light[index].shadow, shp);
|
||||||
}
|
}
|
||||||
spot /= (qgl_Light[index].constantAttenuation + ldist * (qgl_Light[index].linearAttenuation + ldist * qgl_Light[index].quadraticAttenuation));
|
spot /= (qgl_Light[index].constantAttenuation + ldist * (qgl_Light[index].linearAttenuation + ldist * qgl_Light[index].quadraticAttenuation));
|
||||||
///li += spot * gl_LightSource[index].diffuse.rgb * light_diffuse(0, ldir, n);
|
///li += spot * gl_LightSource[index].diffuse.rgb * light_diffuse(0, ldir, n);
|
||||||
@@ -86,16 +105,16 @@ void main(void) {
|
|||||||
|
|
||||||
sh_pow = 1. / max((1. - v1.w), 0.0001);
|
sh_pow = 1. / max((1. - v1.w), 0.0001);
|
||||||
sh_mul = max(1. - v1.w, 0.0001);
|
sh_mul = max(1. - v1.w, 0.0001);
|
||||||
for (int i = 0; i < 1; ++i)
|
//for (int i = 0; i < 8; ++i)
|
||||||
calcLight(i, n, v, v2);
|
// calcLight(i, n, v, v2);
|
||||||
|
calcLight(4, n, v, v2);
|
||||||
|
|
||||||
qgl_FragData[0].rgb = li * dc + si * v2.rgb + v3.rgb + texture(t_pp, tc).rgb;
|
qgl_FragData[0].rgb = li * dc + si * v2.rgb + v3.rgb + texelFetch(t_pp, tc, 0).rgb;
|
||||||
//qgl_FragData[0].rgb = vec3(abs(lpos.xyz - pos.xyz)/10);
|
//qgl_FragData[0].rgb = vec3(abs(lpos.xyz - pos.xyz)/10);
|
||||||
//qgl_FragData[0].rgb = vec3(ldist/1000);
|
//qgl_FragData[0].rgb = li + vec3(texelFetch(t_pp, tc, 0).xyz);
|
||||||
vec2 shp = (vec4(qgl_FragTexture.xy, 1, 1) *transpose(qgl_Light[0].shadowMatrix)).xy;
|
//shd = shd - shp.w;
|
||||||
float shd = 1./texture(qgl_Light[0].shadow, shp).r;
|
//qgl_FragData[0].rgb = vec3(abs(shd)/10000);
|
||||||
shd = shd*shd;// - ldist;
|
//qgl_FragData[0].rgb = vec3((shp.z)/1000);
|
||||||
qgl_FragData[0].rgb = vec3(abs(shd)/1000000);
|
//qgl_FragData[0].rgb = vec3(abs(pos.xyz)/1000);
|
||||||
//qgl_FragData[0].rgb = vec3(*1000);
|
|
||||||
//qgl_FragData[0].a = 0.;
|
//qgl_FragData[0].a = 0.;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#version 150
|
#version 150
|
||||||
|
|
||||||
in vec4 pos;
|
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
qgl_FragData[0].r = 1. / pos.w;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#version 150
|
#version 150
|
||||||
|
|
||||||
out vec4 pos;
|
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
pos = qgl_ftransform();
|
|
||||||
qgl_FragTexture = qgl_Texture;
|
qgl_FragTexture = qgl_Texture;
|
||||||
gl_Position = pos;
|
gl_Position = qgl_ftransform();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user