diff options
author | vaxerski <[email protected]> | 2023-08-03 12:59:16 +0200 |
---|---|---|
committer | vaxerski <[email protected]> | 2023-08-03 12:59:16 +0200 |
commit | 74c53d05d7f17c9d9103bab37f352d37b0a417da (patch) | |
tree | 59ac4147a9fcc14bbb9897618268a56ae0ca57f0 | |
parent | 5062b80161a91a7bc909e097a41a56bca30c73c6 (diff) | |
download | Hyprland-74c53d05d7f17c9d9103bab37f352d37b0a417da.tar.gz Hyprland-74c53d05d7f17c9d9103bab37f352d37b0a417da.zip |
blur improvements, contrast, brightness, noiseblur-improvements
-rw-r--r-- | src/config/ConfigManager.cpp | 3 | ||||
-rw-r--r-- | src/render/OpenGL.cpp | 63 | ||||
-rw-r--r-- | src/render/OpenGL.hpp | 1 | ||||
-rw-r--r-- | src/render/Shader.hpp | 4 | ||||
-rw-r--r-- | src/render/shaders/Textures.hpp | 30 |
5 files changed, 101 insertions, 0 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index c4293ffd..50132d13 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -132,6 +132,9 @@ void CConfigManager::setDefaultVars() { configValues["decoration:blur:ignore_opacity"].intValue = 0; configValues["decoration:blur:new_optimizations"].intValue = 1; configValues["decoration:blur:xray"].intValue = 0; + configValues["decoration:blur:noise"].floatValue = 0.0117; + configValues["decoration:blur:contrast"].floatValue = 0.8916; + configValues["decoration:blur:brightness"].floatValue = 0.8172; configValues["decoration:active_opacity"].floatValue = 1; configValues["decoration:inactive_opacity"].floatValue = 1; configValues["decoration:fullscreen_opacity"].floatValue = 1; diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index a36d5ce2..1040aa86 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -321,6 +321,16 @@ void CHyprOpenGLImpl::initShaders() { m_RenderData.pCurrentMonData->m_shBLUR2.radius = glGetUniformLocation(prog, "radius"); m_RenderData.pCurrentMonData->m_shBLUR2.halfpixel = glGetUniformLocation(prog, "halfpixel"); + prog = createProgram(TEXVERTSRC, FRAGBLURFINISH); + m_RenderData.pCurrentMonData->m_shBLURFINISH.program = prog; + m_RenderData.pCurrentMonData->m_shBLURFINISH.tex = glGetUniformLocation(prog, "tex"); + m_RenderData.pCurrentMonData->m_shBLURFINISH.proj = glGetUniformLocation(prog, "proj"); + m_RenderData.pCurrentMonData->m_shBLURFINISH.posAttrib = glGetAttribLocation(prog, "pos"); + m_RenderData.pCurrentMonData->m_shBLURFINISH.texAttrib = glGetAttribLocation(prog, "texcoord"); + m_RenderData.pCurrentMonData->m_shBLURFINISH.noise = glGetUniformLocation(prog, "noise"); + m_RenderData.pCurrentMonData->m_shBLURFINISH.contrast = glGetUniformLocation(prog, "contrast"); + m_RenderData.pCurrentMonData->m_shBLURFINISH.brightness = glGetUniformLocation(prog, "brightness"); + prog = createProgram(QUADVERTSRC, FRAGSHADOW); m_RenderData.pCurrentMonData->m_shSHADOW.program = prog; m_RenderData.pCurrentMonData->m_shSHADOW.proj = glGetUniformLocation(prog, "proj"); @@ -891,6 +901,59 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, wlr_box* p drawPass(&m_RenderData.pCurrentMonData->m_shBLUR2, &tempDamage); // up } + // finalize with effects + { + static auto* const PBLURCONTRAST = &g_pConfigManager->getConfigValuePtr("decoration:blur:contrast")->floatValue; + static auto* const PBLURNOISE = &g_pConfigManager->getConfigValuePtr("decoration:blur:noise")->floatValue; + static auto* const PBLURBRIGHTNESS = &g_pConfigManager->getConfigValuePtr("decoration:blur:brightness")->floatValue; + + if (currentRenderToFB == PMIRRORFB) + PMIRRORSWAPFB->bind(); + else + PMIRRORFB->bind(); + + glActiveTexture(GL_TEXTURE0); + + glBindTexture(currentRenderToFB->m_cTex.m_iTarget, currentRenderToFB->m_cTex.m_iTexID); + + glTexParameteri(currentRenderToFB->m_cTex.m_iTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glUseProgram(m_RenderData.pCurrentMonData->m_shBLURFINISH.program); + +#ifndef GLES2 + glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shBLURFINISH.proj, 1, GL_TRUE, glMatrix); +#else + wlr_matrix_transpose(glMatrix, glMatrix); + glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shBLURFINISH.proj, 1, GL_FALSE, glMatrix); +#endif + glUniform1f(m_RenderData.pCurrentMonData->m_shBLURFINISH.contrast, *PBLURCONTRAST); + glUniform1f(m_RenderData.pCurrentMonData->m_shBLURFINISH.noise, *PBLURNOISE); + glUniform1f(m_RenderData.pCurrentMonData->m_shBLURFINISH.brightness, *PBLURBRIGHTNESS); + + glUniform1i(m_RenderData.pCurrentMonData->m_shBLURFINISH.tex, 0); + + glVertexAttribPointer(m_RenderData.pCurrentMonData->m_shBLURFINISH.posAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts); + glVertexAttribPointer(m_RenderData.pCurrentMonData->m_shBLURFINISH.texAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts); + + glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBLURFINISH.posAttrib); + glEnableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBLURFINISH.texAttrib); + + if (!damage.empty()) { + for (auto& RECT : damage.getRects()) { + scissor(&RECT, false /* this region is already transformed */); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } + } + + glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBLURFINISH.posAttrib); + glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shBLURFINISH.texAttrib); + + if (currentRenderToFB != PMIRRORFB) + currentRenderToFB = PMIRRORFB; + else + currentRenderToFB = PMIRRORSWAPFB; + } + // finish glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index 9080c90b..d38f54ae 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -61,6 +61,7 @@ struct SMonitorRenderData { CShader m_shEXT; CShader m_shBLUR1; CShader m_shBLUR2; + CShader m_shBLURFINISH; CShader m_shSHADOW; CShader m_shBORDER1; CShader m_shGLITCH; diff --git a/src/render/Shader.hpp b/src/render/Shader.hpp index c43147ab..01d35209 100644 --- a/src/render/Shader.hpp +++ b/src/render/Shader.hpp @@ -43,6 +43,10 @@ class CShader { GLint distort = -1; GLint output = -1; + GLint noise = -1; + GLint contrast = -1; + GLint brightness = -1; + GLint getUniformLocation(const std::string&); void destroy(); diff --git a/src/render/shaders/Textures.hpp b/src/render/shaders/Textures.hpp index 0928487f..98cd8907 100644 --- a/src/render/shaders/Textures.hpp +++ b/src/render/shaders/Textures.hpp @@ -225,6 +225,36 @@ void main() { } )#"; +inline const std::string FRAGBLURFINISH = R"#( +precision mediump float; +varying vec2 v_texcoord; // is in 0-1 +uniform sampler2D tex; + +uniform float contrast; +uniform float noise; +uniform float brightness; + +float hash(vec2 p) { + return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453); +} + +void main() { + vec4 pixColor = texture2D(tex, v_texcoord); + + // contrast + pixColor.rgb = (pixColor.rgb - 0.5) * contrast + 0.5; + + // brightness + pixColor.rgb *= brightness; + + // noise + float noiseHash = hash(v_texcoord); + float noiseAmount = (mod(noiseHash, 1.0) - 0.5); + pixColor.rgb += noiseAmount * noise; + + gl_FragColor = pixColor; +})#"; + inline const std::string TEXFRAGSRCEXT = R"#( #extension GL_OES_EGL_image_external : require |