diff --git a/.vs/shader3/v14/.suo b/.vs/shader3/v14/.suo index eed7516..e4bb53a 100644 Binary files a/.vs/shader3/v14/.suo and b/.vs/shader3/v14/.suo differ diff --git a/FBO.cpp b/FBO.cpp index 79625f0..84df702 100644 --- a/FBO.cpp +++ b/FBO.cpp @@ -23,7 +23,7 @@ void FBO::AttachColorBuffer(const char*bufferName, GLenum attachment, GLenum dat glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, colorBuffer, 0); - mDrawBuffers.push(attachment); + mDrawBuffers.push_back(attachment); mBuffers.insert(std::pair(bufferName,colorBuffer)); glBindFramebuffer(GL_FRAMEBUFFER, 0); } @@ -52,10 +52,9 @@ void FBO::Finish() { GLenum *buffers = new GLenum[nCount]; int i = 0; - while (!mDrawBuffers.empty()) + while (i < nCount) { - buffers[i++] = mDrawBuffers.top(); - mDrawBuffers.pop(); + buffers[i++] = mDrawBuffers[i]; } glBindFramebuffer(GL_FRAMEBUFFER, mFBO); glDrawBuffers(nCount, buffers); diff --git a/FBO.h b/FBO.h index ee822ba..bbc73d8 100644 --- a/FBO.h +++ b/FBO.h @@ -1,14 +1,14 @@ #pragma once #include "glew.h" #include -#include +#include class FBO { public: GLuint mFBO; std::map mBuffers; - std::stack mDrawBuffers; + std::vector mDrawBuffers; public: FBO(); //hdr/normal color diff --git a/main.cpp b/main.cpp index 7e7abe0..eaa4a4a 100644 --- a/main.cpp +++ b/main.cpp @@ -90,14 +90,15 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ hdrProgram.DetectAttribute("texcoord"); hdrProgram.DetectUniform("U_MainTexture"); - //init dilation program - GPUProgram gaussianProgram; - gaussianProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); - gaussianProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/fullscreenquad_gaussian.fs"); - gaussianProgram.Link(); - gaussianProgram.DetectAttribute("pos"); - gaussianProgram.DetectAttribute("texcoord"); - gaussianProgram.DetectUniform("U_MainTexture"); + //combine program + GPUProgram combineProgram; + combineProgram.AttachShader(GL_VERTEX_SHADER, "res/shader/fullscreenquad.vs"); + combineProgram.AttachShader(GL_FRAGMENT_SHADER, "res/shader/combine.fs"); + combineProgram.Link(); + combineProgram.DetectAttribute("pos"); + combineProgram.DetectAttribute("texcoord"); + combineProgram.DetectUniform("U_MainTexture"); + combineProgram.DetectUniform("U_HDRTexture"); //init gpu program GPUProgram gpuProgram; @@ -167,7 +168,8 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ fbo.Finish(); FBO HDRfbo; - HDRfbo.AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA16F, viewportWidth, viewportHeight); + HDRfbo.AttachColorBuffer("color", GL_COLOR_ATTACHMENT0, GL_RGBA, viewportWidth, viewportHeight); + HDRfbo.AttachColorBuffer("hdrcolor", GL_COLOR_ATTACHMENT1, GL_RGBA16F, viewportWidth, viewportHeight); HDRfbo.AttachDepthBuffer("depth", viewportWidth, viewportHeight); HDRfbo.Finish(); @@ -225,14 +227,18 @@ INT WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _ fsq.DrawToLeftTop(originalProgram.GetLocation("pos"), originalProgram.GetLocation("texcoord")); glUseProgram(hdrProgram.mProgram); - glBindTexture(GL_TEXTURE_2D, HDRfbo.GetBuffer("color")); + glBindTexture(GL_TEXTURE_2D, HDRfbo.GetBuffer("hdrcolor")); glUniform1i(hdrProgram.GetLocation("U_MainTexture"), 0); fsq.DrawToRightTop(hdrProgram.GetLocation("pos"), hdrProgram.GetLocation("texcoord")); - glUseProgram(gaussianProgram.mProgram); + glUseProgram(combineProgram.mProgram); glBindTexture(GL_TEXTURE_2D, HDRfbo.GetBuffer("color")); - glUniform1i(gaussianProgram.GetLocation("U_MainTexture"), 0); - fsq.DrawToRightBottom(gaussianProgram.GetLocation("pos"), gaussianProgram.GetLocation("texcoord")); + glUniform1i(combineProgram.GetLocation("U_MainTexture"), 0); + + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, HDRfbo.GetBuffer("hdrcolor")); + glUniform1i(combineProgram.GetLocation("U_HDRTexture"), 1); + fsq.DrawToRightBottom(combineProgram.GetLocation("pos"), combineProgram.GetLocation("texcoord")); SwapBuffers(dc); } diff --git a/res/shader/combine.fs b/res/shader/combine.fs new file mode 100644 index 0000000..4824ae5 --- /dev/null +++ b/res/shader/combine.fs @@ -0,0 +1,9 @@ +varying vec2 V_Texcoord; + +uniform sampler2D U_MainTexture; +uniform sampler2D U_HDRTexture; + +void main() +{ + gl_FragColor = texture2D(U_MainTexture, V_Texcoord) + texture2D(U_HDRTexture, V_Texcoord); +} \ No newline at end of file diff --git a/res/shader/hdr.fs b/res/shader/hdr.fs index 4b12c09..0c26809 100644 --- a/res/shader/hdr.fs +++ b/res/shader/hdr.fs @@ -66,5 +66,14 @@ void main() vec3 VD = normalize(U_EyePos - V_WorldPos); vec4 specularColor = U_SpecularLightColor * U_SpecularMaterial * pow(max(0.0, dot(RD,VD)) ,128); - gl_FragColor = (ambientColor + diffuseColor) * 10.0; + //gl_FragColor = ambientColor + diffuseColor; + + vec4 color = ambientColor + diffuseColor; + + + if(color.r > 1.0){ + gl_FragData[1] = color; + } else { + gl_FragData[0] = color; + } } \ No newline at end of file diff --git a/shader3.vcxproj b/shader3.vcxproj index 4b9fadf..f834c86 100644 --- a/shader3.vcxproj +++ b/shader3.vcxproj @@ -82,6 +82,7 @@ + diff --git a/shader3.vcxproj.filters b/shader3.vcxproj.filters index be527bb..ce15ea6 100644 --- a/shader3.vcxproj.filters +++ b/shader3.vcxproj.filters @@ -70,5 +70,8 @@ src + + src + \ No newline at end of file