Blur behind buttons/sprites should now be working as intended.

This commit is contained in:
Tleety
2016-03-08 11:14:09 +01:00
parent 6b7f598c4d
commit 01f29b6d4e
13 changed files with 6053 additions and 250 deletions
+39 -15
View File
@@ -44,7 +44,8 @@ void BlurHUD::InitializeShaderPrograms()
m_CombineTexturesProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/CombineTexture.vert.glsl")));
m_CombineTexturesProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/CombineTexture.frag.glsl")));
m_CombineTexturesProgram->Compile();
m_CombineTexturesProgram->BindFragDataLocation(0, "fragmentColor");
m_CombineTexturesProgram->BindFragDataLocation(0, "sceneColor");
m_CombineTexturesProgram->BindFragDataLocation(1, "bloomColor");
m_CombineTexturesProgram->Link();
}
GLERROR("Creating DepthFill program");
@@ -53,11 +54,13 @@ void BlurHUD::InitializeShaderPrograms()
void BlurHUD::InitializeBuffers()
{
glm::vec2 res = glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
glm::vec2 res2 = glm::vec2(m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality);
CommonFunctions::GenerateTexture(&m_DepthStencil_horiz, GL_CLAMP_TO_BORDER, GL_NEAREST,
res, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR,
res, GL_RGB16F, GL_RGB, GL_FLOAT);
res2, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_NEAREST,
res2, GL_RGBA16F, GL_RGBA, GL_FLOAT);
if (m_GaussianFrameBuffer_horiz.GetHandle() == 0) {
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthStencil_horiz, GL_DEPTH_STENCIL_ATTACHMENT)));
@@ -66,9 +69,9 @@ void BlurHUD::InitializeBuffers()
m_GaussianFrameBuffer_horiz.Generate();
CommonFunctions::GenerateTexture(&m_DepthStencil_vert, GL_CLAMP_TO_BORDER, GL_NEAREST,
res, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR,
res, GL_RGB16F, GL_RGB, GL_FLOAT);
res2, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_NEAREST,
res2, GL_RGBA16F, GL_RGBA, GL_FLOAT);
if (m_GaussianFrameBuffer_vert.GetHandle() == 0) {
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthStencil_vert, GL_DEPTH_STENCIL_ATTACHMENT)));
@@ -92,11 +95,15 @@ void BlurHUD::ClearBuffer()
m_GaussianFrameBuffer_horiz.Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
glClearStencil(0x00);
glStencilMask(~0);
glDisable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_GaussianFrameBuffer_horiz.Unbind();
m_GaussianFrameBuffer_vert.Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
glClearStencil(0x00);
glStencilMask(~0);
glDisable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_GaussianFrameBuffer_vert.Unbind();
@@ -114,7 +121,10 @@ GLuint BlurHUD::Draw(GLuint texture, RenderScene& scene)
FillStencil(scene);
DrawBloomPassState state;
RenderState state;
state.Disable(GL_BLEND);
state.Disable(GL_DEPTH_TEST);
state.Disable(GL_CULL_FACE);
GLuint shaderHandle_horiz = m_GaussianProgram_horiz->GetHandle();
GLuint shaderHandle_vert = m_GaussianProgram_vert->GetHandle();
@@ -128,6 +138,10 @@ GLuint BlurHUD::Draw(GLuint texture, RenderScene& scene)
state.StencilFunc(GL_EQUAL, 1, 0xFF);
state.StencilMask(0x00);
state.DepthMask(GL_FALSE);
state.Enable(GL_SCISSOR_TEST);
glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality);
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
m_GaussianProgram_horiz->Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
@@ -144,6 +158,8 @@ GLuint BlurHUD::Draw(GLuint texture, RenderScene& scene)
state.StencilFunc(GL_EQUAL, 1, 0xFF);
state.StencilMask(0x00);
state.DepthMask(GL_FALSE);
glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality);
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
m_GaussianProgram_vert->Bind();
glActiveTexture(GL_TEXTURE0);
@@ -162,6 +178,8 @@ GLuint BlurHUD::Draw(GLuint texture, RenderScene& scene)
state.StencilFunc(GL_EQUAL, 1, 0xFF);
state.StencilMask(0x00);
state.DepthMask(GL_FALSE);
glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality);
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
m_GaussianProgram_horiz->Bind();
glActiveTexture(GL_TEXTURE0);
@@ -182,6 +200,8 @@ GLuint BlurHUD::Draw(GLuint texture, RenderScene& scene)
state.StencilFunc(GL_EQUAL, 1, 0xFF);
state.StencilMask(0x00);
state.DepthMask(GL_FALSE);
glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality);
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
m_GaussianProgram_vert->Bind();
glActiveTexture(GL_TEXTURE0);
@@ -192,6 +212,9 @@ GLuint BlurHUD::Draw(GLuint texture, RenderScene& scene)
, 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);
glScissor(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
return m_GaussianTexture_vert;
}
@@ -199,9 +222,9 @@ GLuint BlurHUD::Draw(GLuint texture, RenderScene& scene)
void BlurHUD::OnWindowResize()
{
CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
CommonFunctions::GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality), GL_RGB16F, GL_RGB, GL_FLOAT);
m_GaussianFrameBuffer_vert.Generate();
CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
CommonFunctions::GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality), GL_RGB16F, GL_RGB, GL_FLOAT);
m_GaussianFrameBuffer_horiz.Generate();
}
@@ -216,6 +239,7 @@ void BlurHUD::FillStencil(RenderScene& scene)
state.StencilFunc(GL_ALWAYS, 1, 0xFF);
state.StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
state.StencilMask(0xFF);
glViewport(0, 0, m_Renderer->GetViewportSize().Width/m_BlurQuality, m_Renderer->GetViewportSize().Height/m_BlurQuality);
m_FillDepthStencilProgram->Bind();
@@ -254,16 +278,16 @@ void BlurHUD::FillStencil(RenderScene& scene)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, spriteJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, spriteJob->EndIndex - spriteJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(spriteJob->StartIndex*sizeof(unsigned int)));
}
glViewport(0, 0, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
}
//Texture 1 will be used if texture 2 is black at that texel, else texture 2 is used.
GLuint BlurHUD::CombineTextures(GLuint texture1, GLuint texture2)
{
RenderState state;
state.BindFramebuffer(m_CombinedTextureBuffer.GetHandle());
state.Disable(GL_DEPTH_TEST);
state.Disable(GL_STENCIL_TEST);
//RenderState state;
//state.BindFramebuffer(m_CombinedTextureBuffer.GetHandle());
//state.Disable(GL_DEPTH_TEST);
//state.Disable(GL_STENCIL_TEST);
m_CombineTexturesProgram->Bind();
+15 -4
View File
@@ -281,20 +281,31 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
GLERROR("Shielded Transparent objects");
//Generate blur texture.
m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene);
//Combine nonblur and blur texture
delete state;
if (scene.ShouldBlur) {
//This needs to be drawn only when the full scene is being renderd, and then let be, otherwise sprite and other shit will show on it.
m_FullBlurredTexture = blurHUDPass->Draw(m_SceneTexture, scene);
}
DrawFinalPassState* stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
if(scene.ShouldBlur) {
//Combine nonblur and blur texture
stateSprite->Disable(GL_DEPTH_TEST);
stateSprite->Disable(GL_STENCIL_TEST);
m_CombinedTexture = blurHUDPass->CombineTextures(m_SceneTexture, m_FullBlurredTexture);
}
//Draw Transparen objects
//state->BlendFunc(GL_ONE, GL_ONE);
//state->StencilFunc(GL_EQUAL, 1, 0xFF);
//DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
GLERROR("TransparentObjects");
//state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
stateSprite->Enable(GL_DEPTH_TEST);
DrawSprites(scene.Jobs.SpriteJob, scene);
GLERROR("SpriteJobs");
delete state;
delete stateSprite;
GLERROR("END");
}
+1
View File
@@ -435,6 +435,7 @@ void RenderSystem::Update(double dt)
}
RenderScene scene;
scene.ShouldBlur = true;
scene.Camera = m_Camera;
scene.Viewport = Rectangle(1280, 720);
-1
View File
@@ -162,7 +162,6 @@ void Renderer::Draw(RenderFrame& frame)
m_DrawFinalPass->Draw(*scene, m_BlurHUDPass);
GLERROR("Draw Geometry+Light");
//m_DrawScenePass->Draw(*scene);
m_CombinedTexture = m_BlurHUDPass->CombineTextures(m_DrawFinalPass->SceneTexture(), m_DrawFinalPass->FullBlurredTexture());
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Text");
m_TextPass->Draw(*scene, *m_DrawFinalPass->FinalPassFrameBuffer());