Skip to content

Commit

Permalink
dd
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSillyDoggo committed Aug 8, 2024
1 parent 4a8c4ee commit 36ecab6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 62 deletions.
45 changes: 25 additions & 20 deletions resources/pp-frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,43 @@

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
FragColor = vec4(result, 1.0);
#else
gl_FragColor = vec4(result, 1.0);
#endif
}
}
43 changes: 2 additions & 41 deletions src/Utils/CCBlurLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -88,12 +86,6 @@ void CCBlurLayer::visit()
}

CCLayerColor::visit();

auto end = std::chrono::high_resolution_clock::now();

std::chrono::duration<double, std::milli> duration = end - start;

log::info("visit took {}ms", duration.count());
}

void CCBlurLayer::draw()
Expand All @@ -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<double, std::milli> 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();

Expand All @@ -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<double, std::milli> duration = end - start;

log::info("scene render took {}ms", duration.count());


#ifdef GEODE_IS_IOS
reinterpret_cast<void(__cdecl*)()>(geode::base::get() + 0x174250)();
#else
Expand Down Expand Up @@ -187,19 +160,7 @@ void CCBlurLayer::draw()

glBindVertexArray(0);

auto end2 = std::chrono::high_resolution_clock::now();

std::chrono::duration<double, std::milli> duration2 = end2 - start2;

log::info("scene end took {}ms", duration2.count());

#endif

auto endwhole = std::chrono::high_resolution_clock::now();

std::chrono::duration<double, std::milli> durationwhole = endwhole - startwhole;

log::info("whole render took {}ms", durationwhole.count());
}

Result<std::string> Shader::compile(const std::filesystem::path& vertexPath, const std::filesystem::path& fragmentPath) {
Expand Down
1 change: 0 additions & 1 deletion src/Utils/CCBlurLayer.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <numbers>
#include <chrono>
#include <Geode/Geode.hpp>
#include <Geode/modify/GameManager.hpp>
#include <Geode/modify/CCScheduler.hpp>
Expand Down

0 comments on commit 36ecab6

Please sign in to comment.