renderer: fix misc blur shenanigans

fixes #58
This commit is contained in:
Vaxry 2024-02-22 00:31:33 +00:00
parent 33c272be9f
commit 7ca13a801b
4 changed files with 32 additions and 32 deletions

View File

@ -36,6 +36,7 @@ bool CFramebuffer::alloc(int w, int h) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
m_cTex.m_vSize = {w, h};
} }
if (firstAlloc || m_vSize != Vector2D(w, h)) { if (firstAlloc || m_vSize != Vector2D(w, h)) {

View File

@ -163,8 +163,6 @@ CRenderer::SRenderFeedback CRenderer::renderLock(const CSessionLockSurface& surf
g_pEGL->makeCurrent(surf.eglSurface); g_pEGL->makeCurrent(surf.eglSurface);
glViewport(0, 0, surf.size.x, surf.size.y); glViewport(0, 0, surf.size.x, surf.size.y);
glScissor(frames, 0, surf.size.x, surf.size.y);
glClearColor(0.0, 0.0, 0.0, 0.0); glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -315,12 +313,12 @@ std::vector<std::unique_ptr<IWidget>>* CRenderer::getOrCreateWidgetsFor(const CS
return &widgets[surf]; return &widgets[surf];
} }
void CRenderer::blurTexture(const CFramebuffer& outfb, const CTexture& tex, SBlurParams params) { void CRenderer::blurFB(const CFramebuffer& outfb, SBlurParams params) {
glDisable(GL_BLEND); glDisable(GL_BLEND);
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
float matrix[9]; float matrix[9];
CBox box{0, 0, tex.m_vSize.x, tex.m_vSize.y}; CBox box{0, 0, outfb.m_vSize.x, outfb.m_vSize.y};
wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0, wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
projMatrix.data()); // TODO: write own, don't use WLR here projMatrix.data()); // TODO: write own, don't use WLR here
@ -328,8 +326,8 @@ void CRenderer::blurTexture(const CFramebuffer& outfb, const CTexture& tex, SBlu
wlr_matrix_multiply(glMatrix, projection.data(), matrix); wlr_matrix_multiply(glMatrix, projection.data(), matrix);
CFramebuffer mirrors[2]; CFramebuffer mirrors[2];
mirrors[0].alloc(tex.m_vSize.x, tex.m_vSize.y); mirrors[0].alloc(outfb.m_vSize.x, outfb.m_vSize.y);
mirrors[1].alloc(tex.m_vSize.x, tex.m_vSize.y); mirrors[1].alloc(outfb.m_vSize.x, outfb.m_vSize.y);
CFramebuffer* currentRenderToFB = &mirrors[0]; CFramebuffer* currentRenderToFB = &mirrors[0];
@ -340,18 +338,13 @@ void CRenderer::blurTexture(const CFramebuffer& outfb, const CTexture& tex, SBlu
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(tex.m_iTarget, tex.m_iTexID); glBindTexture(outfb.m_cTex.m_iTarget, outfb.m_cTex.m_iTexID);
glTexParameteri(tex.m_iTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(outfb.m_cTex.m_iTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glUseProgram(blurPrepareShader.program); glUseProgram(blurPrepareShader.program);
#ifndef GLES2
glUniformMatrix3fv(blurPrepareShader.proj, 1, GL_TRUE, glMatrix); glUniformMatrix3fv(blurPrepareShader.proj, 1, GL_TRUE, glMatrix);
#else
wlr_matrix_transpose(glMatrix, glMatrix);
glUniformMatrix3fv(blurPrepareShader.proj, 1, GL_FALSE, glMatrix);
#endif
glUniform1f(blurPrepareShader.contrast, params.contrast); glUniform1f(blurPrepareShader.contrast, params.contrast);
glUniform1f(blurPrepareShader.brightness, params.brightness); glUniform1f(blurPrepareShader.brightness, params.brightness);
glUniform1i(blurPrepareShader.tex, 0); glUniform1i(blurPrepareShader.tex, 0);
@ -386,20 +379,15 @@ void CRenderer::blurTexture(const CFramebuffer& outfb, const CTexture& tex, SBlu
glUseProgram(pShader->program); glUseProgram(pShader->program);
// prep two shaders // prep two shaders
#ifndef GLES2
glUniformMatrix3fv(pShader->proj, 1, GL_TRUE, glMatrix); glUniformMatrix3fv(pShader->proj, 1, GL_TRUE, glMatrix);
#else
wlr_matrix_transpose(glMatrix, glMatrix);
glUniformMatrix3fv(pShader->proj, 1, GL_FALSE, glMatrix);
#endif
glUniform1f(pShader->radius, params.size); glUniform1f(pShader->radius, params.size);
if (pShader == &blurShader1) { if (pShader == &blurShader1) {
glUniform2f(blurShader1.halfpixel, 0.5f / (tex.m_vSize.x / 2.f), 0.5f / (tex.m_vSize.y / 2.f)); glUniform2f(blurShader1.halfpixel, 0.5f / (outfb.m_vSize.x / 2.f), 0.5f / (outfb.m_vSize.y / 2.f));
glUniform1i(blurShader1.passes, params.passes); glUniform1i(blurShader1.passes, params.passes);
glUniform1f(blurShader1.vibrancy, params.vibrancy); glUniform1f(blurShader1.vibrancy, params.vibrancy);
glUniform1f(blurShader1.vibrancy_darkness, params.vibrancy_darkness); glUniform1f(blurShader1.vibrancy_darkness, params.vibrancy_darkness);
} else } else
glUniform2f(blurShader2.halfpixel, 0.5f / (tex.m_vSize.x * 2.f), 0.5f / (tex.m_vSize.y * 2.f)); glUniform2f(blurShader2.halfpixel, 0.5f / (outfb.m_vSize.x * 2.f), 0.5f / (outfb.m_vSize.y * 2.f));
glUniform1i(pShader->tex, 0); glUniform1i(pShader->tex, 0);
glVertexAttribPointer(pShader->posAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts); glVertexAttribPointer(pShader->posAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts);
@ -447,12 +435,7 @@ void CRenderer::blurTexture(const CFramebuffer& outfb, const CTexture& tex, SBlu
glUseProgram(blurFinishShader.program); glUseProgram(blurFinishShader.program);
#ifndef GLES2
glUniformMatrix3fv(blurFinishShader.proj, 1, GL_TRUE, glMatrix); glUniformMatrix3fv(blurFinishShader.proj, 1, GL_TRUE, glMatrix);
#else
wlr_matrix_transpose(glMatrix, glMatrix);
glUniformMatrix3fv(blurFinishShader.proj, 1, GL_FALSE, glMatrix);
#endif
glUniform1f(blurFinishShader.noise, params.noise); glUniform1f(blurFinishShader.noise, params.noise);
glUniform1f(blurFinishShader.brightness, params.brightness); glUniform1f(blurFinishShader.brightness, params.brightness);

View File

@ -30,7 +30,7 @@ class CRenderer {
void renderRect(const CBox& box, const CColor& col, int rounding = 0); void renderRect(const CBox& box, const CColor& col, int rounding = 0);
void renderTexture(const CBox& box, const CTexture& tex, float a = 1.0, int rounding = 0, bool noTransform = false); void renderTexture(const CBox& box, const CTexture& tex, float a = 1.0, int rounding = 0, bool noTransform = false);
void blurTexture(const CFramebuffer& outfb, const CTexture& tex, SBlurParams params); void blurFB(const CFramebuffer& outfb, SBlurParams params);
std::unique_ptr<CAsyncResourceGatherer> asyncResourceGatherer; std::unique_ptr<CAsyncResourceGatherer> asyncResourceGatherer;
std::chrono::system_clock::time_point gatheredAt; std::chrono::system_clock::time_point gatheredAt;

View File

@ -32,19 +32,35 @@ bool CBackground::draw(const SRenderData& data) {
if (blurPasses > 0 && !blurredFB.isAllocated()) { if (blurPasses > 0 && !blurredFB.isAllocated()) {
// make it brah // make it brah
CBox texbox = {{}, asset->texture.m_vSize};
Vector2D size = asset->texture.m_vSize;
float scaleX = viewport.x / asset->texture.m_vSize.x;
float scaleY = viewport.y / asset->texture.m_vSize.y;
texbox.w *= std::max(scaleX, scaleY);
texbox.h *= std::max(scaleX, scaleY);
if (scaleX > scaleY)
texbox.y = -(texbox.h - viewport.y) / 2.f;
else
texbox.x = -(texbox.w - viewport.x) / 2.f;
texbox.round();
blurredFB.alloc(viewport.x, viewport.y); // TODO 10 bit blurredFB.alloc(viewport.x, viewport.y); // TODO 10 bit
blurredFB.bind(); blurredFB.bind();
g_pRenderer->blurTexture(blurredFB, asset->texture, CRenderer::SBlurParams{blurSize, blurPasses, noise, contrast, brightness, vibrancy, vibrancy_darkness}); g_pRenderer->renderTexture(texbox, asset->texture, 1.0, 0,
true); // this could be omitted but whatever it's only once and makes code cleaner plus less blurring on large texs
g_pRenderer->blurFB(blurredFB, CRenderer::SBlurParams{blurSize, blurPasses, noise, contrast, brightness, vibrancy, vibrancy_darkness});
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
} }
CTexture* tex = blurredFB.isAllocated() ? &blurredFB.m_cTex : &asset->texture; CTexture* tex = blurredFB.isAllocated() ? &blurredFB.m_cTex : &asset->texture;
CBox texbox = {{}, asset->texture.m_vSize}; CBox texbox = {{}, tex->m_vSize};
Vector2D size = asset->texture.m_vSize; Vector2D size = tex->m_vSize;
float scaleX = viewport.x / asset->texture.m_vSize.x; float scaleX = viewport.x / tex->m_vSize.x;
float scaleY = viewport.y / asset->texture.m_vSize.y; float scaleY = viewport.y / tex->m_vSize.y;
texbox.w *= std::max(scaleX, scaleY); texbox.w *= std::max(scaleX, scaleY);
texbox.h *= std::max(scaleX, scaleY); texbox.h *= std::max(scaleX, scaleY);
@ -53,7 +69,7 @@ bool CBackground::draw(const SRenderData& data) {
texbox.y = -(texbox.h - viewport.y) / 2.f; texbox.y = -(texbox.h - viewport.y) / 2.f;
else else
texbox.x = -(texbox.w - viewport.x) / 2.f; texbox.x = -(texbox.w - viewport.x) / 2.f;
texbox.round();
g_pRenderer->renderTexture(texbox, *tex, data.opacity); g_pRenderer->renderTexture(texbox, *tex, data.opacity);
return data.opacity < 1.0; return data.opacity < 1.0;