|
|
|
@@ -12,6 +12,7 @@ DrawBloomPass::DrawBloomPass(IRenderer* renderer, ConfigFile* config)
|
|
|
|
|
DrawBloomPass::~DrawBloomPass() {
|
|
|
|
|
CommonFunctions::DeleteTexture(&m_GaussianTexture_horiz);
|
|
|
|
|
CommonFunctions::DeleteTexture(&m_GaussianTexture_vert);
|
|
|
|
|
CommonFunctions::DeleteTexture(&m_FinalGaussianTexture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DrawBloomPass::InitializeTextures()
|
|
|
|
@@ -30,9 +31,8 @@ void DrawBloomPass::ChangeQuality(int quality)
|
|
|
|
|
|
|
|
|
|
if (m_Quality == 0) {
|
|
|
|
|
CommonFunctions::DeleteTexture(&m_GaussianTexture_horiz);
|
|
|
|
|
CommonFunctions::DeleteTexture(&m_GaussianTexture_vert);
|
|
|
|
|
m_GaussianTexture_horiz = 0;
|
|
|
|
|
m_GaussianTexture_vert = 0;
|
|
|
|
|
CommonFunctions::DeleteTexture(&m_GaussianTexture_vert);
|
|
|
|
|
CommonFunctions::DeleteTexture(&m_FinalGaussianTexture);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
InitializeTextures();
|
|
|
|
@@ -62,6 +62,15 @@ void DrawBloomPass::InitializeShaderPrograms()
|
|
|
|
|
m_GaussianProgram_vert->BindFragDataLocation(0, "fragmentColor");
|
|
|
|
|
m_GaussianProgram_vert->Link();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_GaussianCombineProgram = ResourceManager::Load<ShaderProgram>("#GaussianCombineProgram");
|
|
|
|
|
if (m_GaussianCombineProgram->GetHandle() == 0) {
|
|
|
|
|
m_GaussianCombineProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/CombineGaussianTexture.vert.glsl")));
|
|
|
|
|
m_GaussianCombineProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/CombineGaussianTexture.frag.glsl")));
|
|
|
|
|
m_GaussianCombineProgram->Compile();
|
|
|
|
|
m_GaussianCombineProgram->BindFragDataLocation(0, "fragmentColor");
|
|
|
|
|
m_GaussianCombineProgram->Link();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DrawBloomPass::InitializeBuffers()
|
|
|
|
@@ -72,6 +81,12 @@ void DrawBloomPass::InitializeBuffers()
|
|
|
|
|
CommonFunctions::GenerateMipMapTexture(
|
|
|
|
|
&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height)
|
|
|
|
|
, GL_RGB, GL_FLOAT, m_BloomLod);
|
|
|
|
|
CommonFunctions::GenerateTexture(&m_FinalGaussianTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
|
|
|
|
|
|
|
|
|
if (m_GaussianCombineBuffer.GetHandle() == 0) {
|
|
|
|
|
m_GaussianCombineBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_FinalGaussianTexture, GL_COLOR_ATTACHMENT0)));
|
|
|
|
|
}
|
|
|
|
|
m_GaussianCombineBuffer.Generate();
|
|
|
|
|
|
|
|
|
|
if(m_GaussianFrameBuffer_horiz == nullptr) {
|
|
|
|
|
m_GaussianFrameBuffer_horiz = new FrameBuffer[m_BloomLod];
|
|
|
|
@@ -109,8 +124,12 @@ void DrawBloomPass::ClearBuffer()
|
|
|
|
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
m_GaussianFrameBuffer_vert[i].Unbind();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
m_GaussianCombineBuffer.Bind();
|
|
|
|
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
m_GaussianCombineBuffer.Unbind();
|
|
|
|
|
GLERROR("END");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -123,6 +142,7 @@ void DrawBloomPass::Draw(GLuint texture)
|
|
|
|
|
for (int i = 0; i < m_BloomLod; i++) {
|
|
|
|
|
GaussianLodPass(i, texture);
|
|
|
|
|
}
|
|
|
|
|
CombineGaussianBlur();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -148,7 +168,7 @@ void DrawBloomPass::OnWindowResize()
|
|
|
|
|
void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture)
|
|
|
|
|
{
|
|
|
|
|
GLERROR("DrawBloomPass::Draw: Pre");
|
|
|
|
|
|
|
|
|
|
glViewport(0, 0, m_Renderer->GetViewportSize().Width/(glm::pow(2, mipMap)), m_Renderer->GetViewportSize().Height/(glm::pow(2, mipMap)));
|
|
|
|
|
DrawBloomPassState state;
|
|
|
|
|
|
|
|
|
|
GLuint shaderHandle_horiz = m_GaussianProgram_horiz->GetHandle();
|
|
|
|
@@ -156,8 +176,6 @@ void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture)
|
|
|
|
|
|
|
|
|
|
//Horizontal pass, first use the given texture then save it to the horizontal framebuffer.
|
|
|
|
|
m_GaussianFrameBuffer_horiz[mipMap].Bind();
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, mipMap);
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipMap);
|
|
|
|
|
m_GaussianProgram_horiz->Bind();
|
|
|
|
|
glUniform1i(glGetUniformLocation(shaderHandle_horiz, "Lod"), mipMap);
|
|
|
|
|
|
|
|
|
@@ -214,6 +232,20 @@ void DrawBloomPass::GaussianLodPass(GLuint mipMap, GLuint texture)
|
|
|
|
|
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
|
|
|
|
|
|
|
|
|
GLERROR("DrawBloomPass::Draw: END");
|
|
|
|
|
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
|
|
|
|
m_GaussianFrameBuffer_vert[mipMap].Unbind();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DrawBloomPass::CombineGaussianBlur()
|
|
|
|
|
{
|
|
|
|
|
m_GaussianCombineBuffer.Bind();
|
|
|
|
|
m_GaussianCombineProgram->Bind();
|
|
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, m_GaussianTexture_vert);
|
|
|
|
|
glBindVertexArray(m_ScreenQuad->VAO);
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_ScreenQuad->ElementBuffer);
|
|
|
|
|
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
|
|
|
|
|
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
|
|
|
|
|
}
|
|
|
|
|