From f4a14176a6385671f41d5d339e31df9c6f6be286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Micha=C3=ABl=20Celerier?= Date: Sat, 29 Oct 2022 23:40:07 -0400 Subject: [PATCH] [examples] Minor fixes --- examples/Gpu/Compute.hpp | 24 +++++++++++++++--------- examples/Raw/Modular.hpp | 4 ++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/examples/Gpu/Compute.hpp b/examples/Gpu/Compute.hpp index f5416b08..4409ca5c 100644 --- a/examples/Gpu/Compute.hpp +++ b/examples/Gpu/Compute.hpp @@ -100,7 +100,7 @@ void main() // about compute shaders ; fixes welcome ;p ivec2 call = ivec2(gl_GlobalInvocationID.xy); - vec4 color = vec4(0,0,0,0); + vec4 color = vec4(0.0, 0.0,0,0); for(int i = 0; i < gl_WorkGroupSize.x; i++) { @@ -171,7 +171,8 @@ void main() const int w = this->inputs.width / downscale; const int h = this->inputs.height / downscale; - const int bytes = w * h * sizeof(float) * 4; + const int downscaled_pixels_count = w * h; + const int bytes = downscaled_pixels_count * sizeof(float) * 4; // Run a pass co_yield gpp::begin_compute_pass{}; @@ -193,19 +194,24 @@ void main() // finish summing on the cpu auto& final = outputs.color_out.value; - std::fill(std::begin(final), std::end(final), 0.f); - for(int i = 0; i < w * h; i++) + final[0] = 0.f; + final[1] = 0.f; + final[2] = 0.f; + final[3] = 0.f; + + for(int i = 0; i < downscaled_pixels_count; i++) { for(int j = 0; j < 4; j++) + { final[j] += flt[i][j]; + } } - double pixels_total = this->inputs.width * this->inputs.height; - final[0] /= pixels_total; - final[1] /= pixels_total; - final[2] /= pixels_total; - final[3] /= pixels_total; + final[0] /= downscaled_pixels_count; + final[1] /= downscaled_pixels_count; + final[2] /= downscaled_pixels_count; + final[3] /= downscaled_pixels_count; } private: diff --git a/examples/Raw/Modular.hpp b/examples/Raw/Modular.hpp index 1c49c2c1..aa859d36 100644 --- a/examples/Raw/Modular.hpp +++ b/examples/Raw/Modular.hpp @@ -87,10 +87,10 @@ struct Modular { using namespace std; outputs.out_l.sample = clamp( - fmod(inputs.sidechain_l.sample * inputs.gain.value, inputs.in_l.sample), -1.f, + fmod(inputs.sidechain_l.sample * inputs.gain.value, abs(inputs.in_l.sample) + 0.01), -1.f, 1.f); outputs.out_r.sample = clamp( - fmod(inputs.sidechain_r.sample * inputs.gain.value, inputs.in_r.sample), -1.f, + fmod(inputs.sidechain_r.sample * inputs.gain.value, abs(inputs.in_r.sample) + 0.01), -1.f, 1.f); outputs.level.value