diff --git a/BaseGLProject/Multipass.cpp b/BaseGLProject/Multipass.cpp index 9936022..c41e2ff 100644 --- a/BaseGLProject/Multipass.cpp +++ b/BaseGLProject/Multipass.cpp @@ -1,6 +1,6 @@ #include "Multipass.h" -Multipass::Multipass() : _quad_shader("textureViewer.vert", "textureViewer.frag") +Multipass::Multipass() : shader("textureViewer.vert", "textureViewer.frag") { _draw_buffers_size = 0; @@ -67,17 +67,17 @@ void Multipass::drawResultToScreen(SceneContext & scnctx) glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, scnctx.width, scnctx.height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - _quad_shader.enable(); + shader.enable(); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _pass_textures[_current_tex]); - _quad_shader.addUniform("tex", 0); + shader.addUniform("tex", 0); glBindVertexArray(_quad_vao); glBindBuffer(GL_ARRAY_BUFFER, _quad_vbo); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glBindTexture(GL_TEXTURE_2D, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); - _quad_shader.disable(); + shader.disable(); } void Multipass::_createQuad() diff --git a/BaseGLProject/Multipass.h b/BaseGLProject/Multipass.h index e94cfda..b12cf31 100644 --- a/BaseGLProject/Multipass.h +++ b/BaseGLProject/Multipass.h @@ -20,6 +20,8 @@ public: void enableFrameBufferTexture(const std::string tex_name); void drawResultToScreen(SceneContext &scnctx); + + Shader shader; private: void _createQuad(); @@ -27,8 +29,7 @@ private: GLuint _fboId; GLuint _quad_vao; - GLuint _quad_vbo; - Shader _quad_shader; + GLuint _quad_vbo; std::string _current_tex; std::map _pass_textures; diff --git a/BaseGLProject/MyGLWindow.cpp b/BaseGLProject/MyGLWindow.cpp index bc6affb..f37adc9 100644 --- a/BaseGLProject/MyGLWindow.cpp +++ b/BaseGLProject/MyGLWindow.cpp @@ -180,10 +180,10 @@ void MyGlWindow::setup() //meshes["Cube"]->assignTexture(_scnctx.textures["MossTex"]); //meshes["Cube"]->addTranslation(glm::vec4(4, 3, -4, 0)); - meshes.emplace("Mountain", new Mesh("mountain/mount.blend1.obj", shaders["TexBaseLight"])); + //meshes.emplace("Mountain", new Mesh("mountain/mount.blend1.obj", shaders["TexBaseLight"])); - //meshes.emplace("Sponza", new Mesh("sponza/sponza.obj", shaders["TexBaseLight"])); - //meshes["Sponza"]->addTranslation(glm::vec4(0, -200, 0, 1)); + meshes.emplace("Sponza", new Mesh("sponza/sponza.obj", shaders["TexBaseLight"])); + meshes["Sponza"]->addTranslation(glm::vec4(0, -200, 0, 1)); @@ -226,7 +226,7 @@ void MyGlWindow::draw() _scnctx.viewMatrix = view; _scnctx.projectionMatrix = projection; - _multipassManager.enableFrameBufferTexture("render_tex"); + _multipassManager.enableFrameBufferTexture("depth_tex"); glClearColor(_scnctx.bg.r, _scnctx.bg.g, _scnctx.bg.b, _scnctx.bg.a); glViewport(0, 0, _scnctx.width, _scnctx.height); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -235,7 +235,8 @@ void MyGlWindow::draw() for (auto it = meshes.begin(); it != meshes.end(); it++) (*it).second->draw(_scnctx); - + + _multipassManager.shader.addUniform("depth", true); _multipassManager.drawResultToScreen(_scnctx); //skybox.draw(shaders["Skybox"], _scnctx); } diff --git a/BaseGLProject/textureViewer.frag b/BaseGLProject/textureViewer.frag index edde5ac..4fc563a 100644 --- a/BaseGLProject/textureViewer.frag +++ b/BaseGLProject/textureViewer.frag @@ -10,22 +10,20 @@ uniform bool depth; float LinearizeDepth(in vec2 uv) { - float zNear = .1; // zNear of your perspective projection - float zFar = 2000.0; // zFar of your perspective projection - float depth = texture(tex, uv).x; + float zNear = 0.1f; // zNear of your perspective projection + float zFar = 2000.0f; // zFar of your perspective projection + float depth = texture(tex, uv).x; return (2.0 * zNear) / (zFar + zNear - depth * (zFar - zNear)); } - void main() { //rrra because depth textures are not usual textures, they have only one channel final_color = (depth) ? texture(tex, uv).rrra : texture(tex, uv).rgba; if (depth) { - float d; + float d; d = LinearizeDepth(uv); final_color = vec4(d,d,d,1.0); - } - //final_color = vec4(1.0,0.0,0.0,1.0); + } } \ No newline at end of file