diff --git a/resources/pp-frag.glsl b/resources/pp-frag.glsl index 09c4b51..ddcc14b 100644 --- a/resources/pp-frag.glsl +++ b/resources/pp-frag.glsl @@ -16,33 +16,38 @@ uniform sampler2D screen; uniform vec2 screenSize; -uniform bool fast; -uniform bool first; uniform float radius; +uniform bool first; void main() { - float scaledRadius = radius * screenSize.y * 0.5; - vec2 texOffset = 1.0 / screenSize; // gets size of single texel + // Compute scaled radius + float scaledRadius = clamp(radius * screenSize.y * 0.5, 1.0, 25.0); + vec2 texOffset = 1.0 / screenSize; + // Initialize result with the center pixel vec3 result = texture2D(screen, TexCoords).rgb; - scaledRadius *= radius * 10.0 / ((radius * 10.0 + 1.0) * (radius * 10.0 + 1.0) - 1.0); + float weightSum = 1.0; float weight = 1.0; - float weightSum = weight; - if (first) { - for (int i = 1; float(i) < scaledRadius; i++) { - weight -= 1.0 / scaledRadius; - weightSum += weight * 2.0; - result += texture2D(screen, TexCoords + vec2(texOffset.x * float(i), 0.0)).rgb * weight; - result += texture2D(screen, TexCoords - vec2(texOffset.x * float(i), 0.0)).rgb * weight; - } - } else { - for (int i = 1; float(i) < scaledRadius; i++) { - weight -= 1.0 / scaledRadius; - weightSum += weight * 2.0; - result += texture2D(screen, TexCoords + vec2(0.0, texOffset.y * float(i))).rgb * weight; - result += texture2D(screen, TexCoords - vec2(0.0, texOffset.y * float(i))).rgb * weight; + + // Precompute inverse radius for weight reduction + float inverseRadius = 1.0 / scaledRadius; + + for (float i = 1.0; i < scaledRadius; i++) { + weight -= inverseRadius; + weightSum += weight * 2.0; + + if (first) { + vec2 offset = vec2(texOffset.x * i, 0.0); + result += texture2D(screen, TexCoords + offset).rgb * weight; + result += texture2D(screen, TexCoords - offset).rgb * weight; + } else { + vec2 offset = vec2(0.0, texOffset.y * i); + result += texture2D(screen, TexCoords + offset).rgb * weight; + result += texture2D(screen, TexCoords - offset).rgb * weight; } } + + // Normalize the result by the total weight result /= weightSum; #if __VERSION__ == 300 @@ -50,4 +55,4 @@ void main() { #else gl_FragColor = vec4(result, 1.0); #endif -} +} \ No newline at end of file diff --git a/src/Utils/CCBlurLayer.cpp b/src/Utils/CCBlurLayer.cpp index 7dfa18d..66cc2e1 100644 --- a/src/Utils/CCBlurLayer.cpp +++ b/src/Utils/CCBlurLayer.cpp @@ -74,8 +74,6 @@ CCBlurLayer* CCBlurLayer::create() void CCBlurLayer::visit() { - auto start = std::chrono::high_resolution_clock::now(); - if (this->getOpacity()) { float v = this->getOpacity() / 255.0f; @@ -88,12 +86,6 @@ void CCBlurLayer::visit() } CCLayerColor::visit(); - - auto end = std::chrono::high_resolution_clock::now(); - - std::chrono::duration duration = end - start; - - log::info("visit took {}ms", duration.count()); } void CCBlurLayer::draw() @@ -103,23 +95,13 @@ void CCBlurLayer::draw() if (blurStrength == 0) return CCLayerColor::draw(); - auto startwhole = std::chrono::high_resolution_clock::now(); - - auto start1 = std::chrono::high_resolution_clock::now(); - GLint drawFbo = 0; GLint readFbo = 0; glGetIntegerv(0x8CA6, &drawFbo); - //glGetIntegerv(0x8CAA, &readFbo); + glGetIntegerv(0x8CAA, &readFbo); glBindFramebuffer(0x8D40, ppRt0.fbo); - //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - - auto end1 = std::chrono::high_resolution_clock::now(); - - std::chrono::duration duration1 = end1 - start1; - - log::info("link 1 took {}ms", duration1.count()); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); CCLayerColor::draw(); @@ -136,18 +118,9 @@ void CCBlurLayer::draw() kmGLPushMatrix(); #endif - auto start = std::chrono::high_resolution_clock::now(); - parent->transform(); parent->visit(); - auto end = std::chrono::high_resolution_clock::now(); - - std::chrono::duration duration = end - start; - - log::info("scene render took {}ms", duration.count()); - - #ifdef GEODE_IS_IOS reinterpret_cast(geode::base::get() + 0x174250)(); #else @@ -187,19 +160,7 @@ void CCBlurLayer::draw() glBindVertexArray(0); - auto end2 = std::chrono::high_resolution_clock::now(); - - std::chrono::duration duration2 = end2 - start2; - - log::info("scene end took {}ms", duration2.count()); - #endif - - auto endwhole = std::chrono::high_resolution_clock::now(); - - std::chrono::duration durationwhole = endwhole - startwhole; - - log::info("whole render took {}ms", durationwhole.count()); } Result Shader::compile(const std::filesystem::path& vertexPath, const std::filesystem::path& fragmentPath) { diff --git a/src/Utils/CCBlurLayer.hpp b/src/Utils/CCBlurLayer.hpp index 06bc106..c71ea90 100644 --- a/src/Utils/CCBlurLayer.hpp +++ b/src/Utils/CCBlurLayer.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include