From 0703a5851b3ff5c777e63ae5ea5c0b3a48187e88 Mon Sep 17 00:00:00 2001 From: BrimsonBhin <40442071+BrimsonBhin@users.noreply.github.com> Date: Thu, 23 Apr 2020 22:02:47 -0700 Subject: [PATCH] Gaussian Blur: Use straight multiply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Results are identical (tested with Olive 0.1.x). Using a straight multiply is faster if the compiler doesn't optimize pow(). It's also safer because with pow(), [the result is undefined if x<0 or if x=0 and y≤0](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/pow.xhtml). --- app/shaders/blur.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/shaders/blur.frag b/app/shaders/blur.frag index 1e520a996..65092c9cf 100644 --- a/app/shaders/blur.frag +++ b/app/shaders/blur.frag @@ -29,7 +29,7 @@ out vec4 fragColor; // Double gaussian formula, actually used in the code below // Should be faster than the single gaussian above since it doesn't need sqrt() float gaussian2(float x, float y, float sigma) { - return (1.0/(pow(sigma, 2.0)*2.0*M_PI))*exp(-0.5*((pow(x, 2.0) + pow(y, 2.0))/pow(sigma, 2.0))); + return (1.0/((sigma*sigma)*2.0*M_PI))*exp(-0.5*(((x*x) + (y*y))/(sigma*sigma))); } void main(void) {