FBO depth_texture working
This commit is contained in:
parent
640244c556
commit
f404b6ae9b
@ -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()
|
||||
|
||||
@ -20,6 +20,8 @@ public:
|
||||
|
||||
void enableFrameBufferTexture(const std::string tex_name);
|
||||
void drawResultToScreen(SceneContext &scnctx);
|
||||
|
||||
Shader shader;
|
||||
private:
|
||||
|
||||
void _createQuad();
|
||||
@ -28,7 +30,6 @@ private:
|
||||
|
||||
GLuint _quad_vao;
|
||||
GLuint _quad_vbo;
|
||||
Shader _quad_shader;
|
||||
std::string _current_tex;
|
||||
std::map<std::string, GLuint> _pass_textures;
|
||||
|
||||
|
||||
@ -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);
|
||||
@ -236,6 +236,7 @@ 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);
|
||||
}
|
||||
|
||||
@ -10,13 +10,12 @@ 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 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
|
||||
@ -27,5 +26,4 @@ void main()
|
||||
d = LinearizeDepth(uv);
|
||||
final_color = vec4(d,d,d,1.0);
|
||||
}
|
||||
//final_color = vec4(1.0,0.0,0.0,1.0);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user