From 783a9619a7247872d7645ea32242305038b21cc4 Mon Sep 17 00:00:00 2001 From: "J.C" Date: Fri, 4 Jan 2019 16:03:03 +0800 Subject: [PATCH] 1, use new way to generate hash, old one does not work on iOS devices (refer to: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/) 2, remove the division for pre-multiplied alpha, it's even not enabled before? --- filters/zoom-blur/src/zoom-blur.frag | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/filters/zoom-blur/src/zoom-blur.frag b/filters/zoom-blur/src/zoom-blur.frag index 3ef53998d..1fa9db2d9 100644 --- a/filters/zoom-blur/src/zoom-blur.frag +++ b/filters/zoom-blur/src/zoom-blur.frag @@ -9,9 +9,11 @@ uniform float uRadius; const float MAX_KERNEL_SIZE = 32.0; -float random(vec3 scale, float seed) { - // use the fragment position for a different seed per-pixel - return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed); +// author: http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/ +highp float rand(vec2 co, float seed) { + const highp float a = 12.9898, b = 78.233, c = 43758.5453; + highp float dt = dot(co + seed, vec2(a, b)), sn = mod(dt, 3.14159); + return fract(sin(sn) * c + seed); } void main() { @@ -52,7 +54,7 @@ void main() { } // randomize the lookup values to hide the fixed number of samples - float offset = random(vec3(12.9898, 78.233, 151.7182), 0.0); + float offset = rand(vTextureCoord, 0.0); float total = 0.0; vec4 color = vec4(0.0); @@ -78,7 +80,7 @@ void main() { color /= total; // switch back from pre-multiplied alpha - color.rgb /= color.a + 0.00001; + // color.rgb /= color.a + 0.00001; gl_FragColor = color; }