diff --git a/BaseGLProject/BaseGLProject.vcxproj b/BaseGLProject/BaseGLProject.vcxproj
index 608ebc7..284df92 100644
--- a/BaseGLProject/BaseGLProject.vcxproj
+++ b/BaseGLProject/BaseGLProject.vcxproj
@@ -201,6 +201,8 @@
+
+
diff --git a/BaseGLProject/BaseGLProject.vcxproj.filters b/BaseGLProject/BaseGLProject.vcxproj.filters
index 3c1b08f..9410b9c 100644
--- a/BaseGLProject/BaseGLProject.vcxproj.filters
+++ b/BaseGLProject/BaseGLProject.vcxproj.filters
@@ -25,6 +25,9 @@
{b0c228ca-8e29-48df-a9f6-59fb58accad5}
+
+ {be4b14ab-faab-4412-8a5b-ce9c1510772f}
+
@@ -217,23 +220,33 @@
Shaders
-
- MankyuCode
-
+
+
+
+
- MankyuCode
+ Shaders\PPShaders
-
- Shaders
+
+ Shaders\PPShaders
-
- Shaders
+
+ Shaders\PPShaders
-
- Shaders
+
+ Shaders\PPShaders
- Shaders
+ Shaders\PPShaders
+
+
+ Shaders\PPShaders
+
+
+ Shaders\PPShaders
+
+
+ Shaders\PPShaders
diff --git a/BaseGLProject/DSGeometryPass.frag b/BaseGLProject/DSGeometryPass.frag
index bdd4f1a..4a5e474 100644
--- a/BaseGLProject/DSGeometryPass.frag
+++ b/BaseGLProject/DSGeometryPass.frag
@@ -1,10 +1,24 @@
#version 440
-//Copy of simple.frag
+layout (location = 0) out vec3 gPosition;
+layout (location = 1) out vec3 gNormal;
+layout (location = 2) out vec4 gAlbedoSpec;
-in vec3 f_color;
-out vec4 FragColors;
+in vec2 TexCoords;
+in vec3 FragPos;
+in vec3 Normal;
+
+//uniform sampler2D texture_diffuse1;
void main()
{
- FragColors = vec4(f_color, 1.f);
+ // store the fragment position vector in the first gbuffer texture
+ gPosition = FragPos;
+ // also store the per-fragment normals into the gbuffer
+ gNormal = normalize(Normal);
+ // and the diffuse per-fragment color
+ gAlbedoSpec.rgb = vec3(1, 1, 1);
+ //gAlbedoSpec.rgb = texture(texture_diffuse1, TexCoords).rgb;
+ // store specular intensity in gAlbedoSpec's alpha component
+ //gAlbedoSpec.a = texture(texture_specular1, TexCoords).r;
+ gAlbedoSpec.a = 1;
}
diff --git a/BaseGLProject/DSGeometryPass.vert b/BaseGLProject/DSGeometryPass.vert
index 3fc7cf5..96c3278 100644
--- a/BaseGLProject/DSGeometryPass.vert
+++ b/BaseGLProject/DSGeometryPass.vert
@@ -1,18 +1,19 @@
#version 440
-// Copy of simple.vert
layout(location=0) in vec3 coord3d;
layout(location=1) in vec3 v_normal;
-layout(location=2) in vec3 v_color;
layout(location=3) in vec2 v_texmap;
-
-out vec3 f_color;
+out vec2 TexCoords;
+out vec3 FragPos;
+out vec3 Normal;
uniform mat4 mvp;
void main(void)
-{
- f_color = v_color;
+{
+ Normal = v_normal;
+ TexCoords = v_texmap;
gl_Position = mvp * vec4(coord3d, 1.0f);
+ FragPos = gl_Position.xyz;
}
\ No newline at end of file
diff --git a/BaseGLProject/GBufferVisual.frag b/BaseGLProject/GBufferVisual.frag
new file mode 100644
index 0000000..5b70443
--- /dev/null
+++ b/BaseGLProject/GBufferVisual.frag
@@ -0,0 +1,37 @@
+#version 430
+out vec4 FragColor;
+
+in vec2 TexCoords;
+
+uniform sampler2D gPosition;
+uniform sampler2D gNormal;
+uniform sampler2D gAlbedoSpec;
+
+subroutine vec4 shading_t();
+subroutine uniform shading_t Shading;
+
+subroutine(shading_t)
+vec4 DisplayAlbedo()
+{
+ vec3 Albedo = texture(gAlbedoSpec, TexCoords).rgb;
+ return vec4(Albedo, 0);
+}
+
+subroutine(shading_t)
+vec4 DisplayPositions()
+{
+ vec3 FragPos = texture(gPosition, TexCoords).rgb;
+ return vec4(FragPos, 0);
+}
+
+subroutine(shading_t)
+vec4 DisplayNormals()
+{
+ vec3 Normal = texture(gNormal, TexCoords).rgb;
+ return vec4(Normal, 0);
+}
+
+void main(void)
+{
+ FragColor = Shading();
+}
\ No newline at end of file
diff --git a/BaseGLProject/GBufferVisual.vert b/BaseGLProject/GBufferVisual.vert
new file mode 100644
index 0000000..d033c75
--- /dev/null
+++ b/BaseGLProject/GBufferVisual.vert
@@ -0,0 +1,12 @@
+#version 430
+
+layout(location = 0) in vec2 vPosition;
+layout(location = 1) in vec2 vUV;
+
+out vec2 TexCoords;
+
+void main()
+{
+ gl_Position = vec4(vPosition,0.0,1.0);
+ TexCoords = vUV;
+}
\ No newline at end of file
diff --git a/BaseGLProject/Multipass.cpp b/BaseGLProject/Multipass.cpp
index 924fa0d..b14aba8 100644
--- a/BaseGLProject/Multipass.cpp
+++ b/BaseGLProject/Multipass.cpp
@@ -13,8 +13,9 @@ Multipass::Multipass()
void Multipass::setDrawBuffers()
{
glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
- glDrawBuffers(_draw_buffers_size, _draw_buffers);
- if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
+ glDrawBuffers(_draw_buffers_size, _draw_buffers);
+ int framebuffer_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+ if (framebuffer_status != GL_FRAMEBUFFER_COMPLETE)
throw std::runtime_error("Error during framebuffer initialisation");
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
@@ -25,8 +26,8 @@ void Multipass::bindToFrameBuffer(GLenum type, GLenum texture, std::string texNa
glFramebufferTexture2D(GL_FRAMEBUFFER, type, texture, _pass_textures[texName], 0);
if (type != GL_DEPTH_ATTACHMENT) {
_draw_buffers[_draw_buffers_size] = type;
- _draw_buffers_size++;
- }
+ _draw_buffers_size++;
+ }
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
@@ -35,7 +36,7 @@ Multipass::~Multipass()
glDeleteFramebuffers(1, &_fboId);
}
-void Multipass::addTexture(const std::string & tex_name, GLuint filter, GLuint type, GLuint type_2,
+void Multipass::addTexture(const std::string & tex_name, GLuint filter, GLuint type, GLuint type_2, GLuint type_3,
bool depth, SceneContext &scnctx, GLuint height, GLuint width)
{
height = (height == 0) ? scnctx.height : height;
@@ -44,7 +45,7 @@ void Multipass::addTexture(const std::string & tex_name, GLuint filter, GLuint t
glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
glGenTextures(1, &_pass_textures[tex_name]);;
glBindTexture(GL_TEXTURE_2D, _pass_textures[tex_name]);
- glTexImage2D(GL_TEXTURE_2D, 0, type, width, height, 0, type_2, GL_FLOAT, 0);
+ glTexImage2D(GL_TEXTURE_2D, 0, type, width, height, 0, type_2, type_3, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
@@ -66,14 +67,11 @@ void Multipass::enableFrameBufferTexture(const std::string tex_name)
void Multipass::drawResultToScreen(SceneContext & scnctx)
{
- //EXAMPLE CODE
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, scnctx.width, scnctx.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader->enable();
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, _pass_textures[_current_tex]);
- shader->addUniform("tex", 0);
+ glActiveTexture(GL_TEXTURE0);
glBindVertexArray(_quad_vao);
glBindBuffer(GL_ARRAY_BUFFER, _quad_vbo);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
diff --git a/BaseGLProject/Multipass.h b/BaseGLProject/Multipass.h
index 12b2b3f..d64b945 100644
--- a/BaseGLProject/Multipass.h
+++ b/BaseGLProject/Multipass.h
@@ -15,7 +15,7 @@ public:
void setDrawBuffers();
void bindToFrameBuffer(GLenum type, GLenum texture, std::string texName);
- void addTexture(const std::string &tex_name, GLuint filter, GLuint type, GLuint type_2,
+ void addTexture(const std::string &tex_name, GLuint filter, GLuint type, GLuint type_2, GLuint type_3,
bool depth, SceneContext &scnctx, GLuint height = 0, GLuint width = 0);
void enableFrameBufferTexture(const std::string tex_name);
diff --git a/BaseGLProject/MyGLWindow.cpp b/BaseGLProject/MyGLWindow.cpp
index 149c995..9453ace 100644
--- a/BaseGLProject/MyGLWindow.cpp
+++ b/BaseGLProject/MyGLWindow.cpp
@@ -117,10 +117,13 @@ void MyGlWindow::shaderSetup()
shaders["Skybox"]->addUniform("RefractionIndex", glm::vec3(0.65, 0.67, 0.69));
shaders["DSGeometryPass"] = new Shader("DSGeometryPass.vert", "DSGeometryPass.frag");
- shaders["DSGeometryPass"]->uniformFlags = MVP_FLAG | KA_FLAG | KD_FLAG | KS_FLAG | SHINE_FLAG;
+ shaders["DSGeometryPass"]->uniformFlags = MVP_FLAG;
shaders["DSLightPass"] = new Shader("DSLightPass.vert", "DSLightPass.frag");
shaders["DSLightPass"]->uniformFlags = LIGHTS_FLAG;
+
+ shaders["GBufferVisual"] = new Shader("GBufferVisual.vert", "GBufferVisual.frag");
+ shaders["GBufferVisual"]->uniformFlags = 0;
}
void MyGlWindow::lightSetup()
@@ -139,23 +142,29 @@ void MyGlWindow::lightSetup()
void MyGlWindow::multipassSetup()
{
- //_multipassManager.shader = shaders["ShadowLight"];
- _multipassManager.addTexture("position_buffer", GL_NEAREST, GL_RGB, GL_FLOAT, false, _scnctx);
- _multipassManager.addTexture("normal_buffer", GL_NEAREST, GL_RGB, GL_RGB, false, _scnctx);
- _multipassManager.addTexture("color_buffer", GL_NEAREST, GL_RGB, GL_RGB, false, _scnctx);
+ _multipassManager.shader = shaders["GBufferVisual"];
+ _multipassManager.addTexture("position_buffer", GL_NEAREST, GL_RGB16F, GL_RGB, GL_FLOAT, false, _scnctx);
+ _multipassManager.addTexture("normal_buffer", GL_NEAREST, GL_RGB16F, GL_RGB, GL_UNSIGNED_BYTE, false, _scnctx);
+ _multipassManager.addTexture("color_buffer", GL_NEAREST, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false, _scnctx);
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, "position_buffer");
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, "normal_buffer");
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, "color_buffer");
- //_multipassManager.setDrawBuffers();
+ _multipassManager.setDrawBuffers();
- _multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "depthing");
+ //Deferred lighting shader
+ _multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "DisplayAlbedo");
+ _multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "DisplayPositions");
+ _multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "DisplayNormals");
+
+ //Standard post-process shader
+ /*_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "depthing");
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "blurring");
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "sharpening");
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "sepia");
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "grayscale");
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "sobel_filter");
- _multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "absolutely_no_postprocess");
+ _multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "absolutely_no_postprocess");*/
}
void MyGlWindow::setup()
@@ -174,7 +183,7 @@ void MyGlWindow::setup()
Dataset moddata;
moddata.checkeredFloor(100, 100, glm::vec3(0.1, 0.1, 0.1), glm::vec3(0.7, 0.7, 0.7));
- meshes.emplace("Floor", new Mesh(moddata, shaders["BaseLight"]));
+ meshes.emplace("Floor", new Mesh(moddata, shaders["DSGeometryPass"]));
moddata.simpleCube();
@@ -185,7 +194,7 @@ void MyGlWindow::setup()
for (int i = 0; i < 30; i++)
{
std::string cube_name = "Cube" + std::to_string(i);
- meshes.emplace(cube_name, new Mesh(moddata, shaders["BaseLight"]));
+ meshes.emplace(cube_name, new Mesh(moddata, shaders["DSGeometryPass"]));
float pos_x = std::rand() % 100 - 50;
float pos_z = std::rand() % 100 - 50;
@@ -224,11 +233,12 @@ void MyGlWindow::draw()
glViewport(0, 0, _scnctx.width, _scnctx.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ _multipassManager.enableFrameBufferTexture("color_buffer");
for (auto it = meshes.begin(); it != meshes.end(); it++)
(*it).second->draw(_scnctx);
-
- //_multipassManager.drawResultToScreen(_scnctx);
+
+ _multipassManager.drawResultToScreen(_scnctx);
}
diff --git a/BaseGLProject/textureViewer.vert b/BaseGLProject/textureViewer.vert
index ae3216e..5b0c83c 100644
--- a/BaseGLProject/textureViewer.vert
+++ b/BaseGLProject/textureViewer.vert
@@ -9,4 +9,4 @@ void main()
{
gl_Position = vec4(vPosition,0.0,1.0);
uv = vUV;
-}
\ No newline at end of file
+}
\ No newline at end of file