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

This commit is contained in:
2016-01-18 14:41:29 +00:00
parent 5b523a65ae
commit d88b341070
28 changed files with 539 additions and 112 deletions

View File

@@ -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);
@@ -350,7 +402,7 @@ void RendererDeferredShading::renderScene() {
glDrawQuad(shader_small);
hcontent.resize(fbo_hsmall.width() * fbo_hsmall.height());
glReadPixels(0, 0, fbo_hsmall.width(), fbo_hsmall.height(), GL_RGB, GL_FLOAT, hcontent.data());
GLfloat max[3] = {0.,0.,0.};//min[3] = {10000.,10000.,10000.}, ;
GLfloat max[3] = {0.,0.,0.};//min[3] = {10000.,10000.,10000.},;
for (int i = 0; i < hcontent.size(); ++i) {
//if (min[0] > hcontent[i].x) min[0] = hcontent[i].x;
if (max[0] < hcontent[i].x) max[0] = hcontent[i].x;