From dd3bc7d30464a7ae0dbe0bf06a767787ed3edd86 Mon Sep 17 00:00:00 2001 From: finscn Date: Thu, 25 Jan 2018 01:44:31 +0800 Subject: [PATCH] fix the bug about gl_FragColor on iOS --- filters/bulge-pinch/src/bulgePinch.frag | 6 ++++-- filters/godray/src/gorday.frag | 4 ++-- filters/motion-blur/src/motion-blur.frag | 7 ++++--- filters/radial-blur/src/radial-blur.frag | 9 ++++++--- filters/shockwave/src/shockwave.frag | 8 +++++--- filters/tilt-shift/src/tilt-shift.frag | 6 ++++-- filters/zoom-blur/src/zoom-blur.frag | 6 +++--- 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/filters/bulge-pinch/src/bulgePinch.frag b/filters/bulge-pinch/src/bulgePinch.frag index ec0bde774..c55463dc6 100644 --- a/filters/bulge-pinch/src/bulgePinch.frag +++ b/filters/bulge-pinch/src/bulgePinch.frag @@ -24,8 +24,10 @@ void main() coord += center * dimensions.xy; coord /= filterArea.xy; vec2 clampedCoord = clamp(coord, filterClamp.xy, filterClamp.zw); - gl_FragColor = texture2D(uSampler, clampedCoord); + vec4 color = texture2D(uSampler, clampedCoord); if (coord != clampedCoord) { - gl_FragColor *= max(0.0, 1.0 - length(coord - clampedCoord)); + color *= max(0.0, 1.0 - length(coord - clampedCoord)); } + + gl_FragColor = color; } diff --git a/filters/godray/src/gorday.frag b/filters/godray/src/gorday.frag index f24b40855..64e3ab41b 100644 --- a/filters/godray/src/gorday.frag +++ b/filters/godray/src/gorday.frag @@ -14,7 +14,6 @@ uniform float time; ${perlin} void main(void) { - gl_FragColor = texture2D(uSampler, vTextureCoord); vec2 coord = vTextureCoord * filterArea.xy / dimensions.xy; float d; @@ -37,5 +36,6 @@ void main(void) { //fade vertically. vec4 mist = vec4(noise, noise, noise, 1.0) * (1.0 - coord.y); mist.a = 1.0; - gl_FragColor += mist; + + gl_FragColor = texture2D(uSampler, vTextureCoord) + mist; } diff --git a/filters/motion-blur/src/motion-blur.frag b/filters/motion-blur/src/motion-blur.frag index 7021d91d9..c357d7c6e 100644 --- a/filters/motion-blur/src/motion-blur.frag +++ b/filters/motion-blur/src/motion-blur.frag @@ -21,10 +21,11 @@ float offset = -uOffset / length(uVelocity) - 0.5; void main(void) { - gl_FragColor = texture2D(uSampler, vTextureCoord); + vec4 color = texture2D(uSampler, vTextureCoord); if (uKernelSize == 0) { + gl_FragColor = color; return; } @@ -33,7 +34,7 @@ void main(void) break; } vec2 bias = velocity * (float(i) / k + offset); - gl_FragColor += texture2D(uSampler, vTextureCoord + bias); + color += texture2D(uSampler, vTextureCoord + bias); } - gl_FragColor /= kernelSize; + gl_FragColor = color / kernelSize; } diff --git a/filters/radial-blur/src/radial-blur.frag b/filters/radial-blur/src/radial-blur.frag index bee721b55..97eefeb88 100644 --- a/filters/radial-blur/src/radial-blur.frag +++ b/filters/radial-blur/src/radial-blur.frag @@ -26,10 +26,11 @@ float radius = uRadius / filterArea.x - gradient * 0.5; void main(void) { - gl_FragColor = texture2D(uSampler, vTextureCoord); + vec4 color = texture2D(uSampler, vTextureCoord); if (uKernelSize == 0) { + gl_FragColor = color; return; } @@ -45,6 +46,7 @@ void main(void) float gap = gradient; float scale = 1.0 - abs(delta / gap); if (scale <= 0.0) { + gl_FragColor = color; return; } radianStep = uRadian * scale / k; @@ -72,7 +74,8 @@ void main(void) // switch to pre-multiplied alpha to correctly blur transparent images // sample.rgb *= sample.a; - gl_FragColor += sample; + color += sample; } - gl_FragColor /= kernelSize; + + gl_FragColor = color / kernelSize; } diff --git a/filters/shockwave/src/shockwave.frag b/filters/shockwave/src/shockwave.frag index 572fe87f9..ec6076342 100644 --- a/filters/shockwave/src/shockwave.frag +++ b/filters/shockwave/src/shockwave.frag @@ -55,13 +55,15 @@ void main() // Do clamp : vec2 coord = vTextureCoord + offset; vec2 clampedCoord = clamp(coord, filterClamp.xy, filterClamp.zw); - gl_FragColor = texture2D(uSampler, clampedCoord); + vec4 color = texture2D(uSampler, clampedCoord); if (coord != clampedCoord) { - gl_FragColor *= max(0.0, 1.0 - length(coord - clampedCoord)); + color *= max(0.0, 1.0 - length(coord - clampedCoord)); } // No clamp : // gl_FragColor = texture2D(uSampler, vTextureCoord + offset); - gl_FragColor.rgb *= 1.0 + (brightness - 1.0) * p * fade; + color.rgb *= 1.0 + (brightness - 1.0) * p * fade; + + gl_FragColor = color; } diff --git a/filters/tilt-shift/src/tilt-shift.frag b/filters/tilt-shift/src/tilt-shift.frag index fff2be057..e8894a04f 100644 --- a/filters/tilt-shift/src/tilt-shift.frag +++ b/filters/tilt-shift/src/tilt-shift.frag @@ -32,6 +32,8 @@ void main(void) total += weight; } - gl_FragColor = color / total; - gl_FragColor.rgb /= gl_FragColor.a + 0.00001; + color /= total; + color.rgb /= color.a + 0.00001; + + gl_FragColor = color; } diff --git a/filters/zoom-blur/src/zoom-blur.frag b/filters/zoom-blur/src/zoom-blur.frag index c22fce160..3ef53998d 100644 --- a/filters/zoom-blur/src/zoom-blur.frag +++ b/filters/zoom-blur/src/zoom-blur.frag @@ -76,9 +76,9 @@ void main() { } } - gl_FragColor = color / total; - + color /= total; // switch back from pre-multiplied alpha - gl_FragColor.rgb /= gl_FragColor.a + 0.00001; + color.rgb /= color.a + 0.00001; + gl_FragColor = color; }