| 7 |
| 8 | uniform float[7] t; |
| 9 | uniform float[7] centerX; |
| 10 | uniform float[7] centerY; |
| 11 | uniform float[7] intensity; |
| 12 |
| 13 | float sdfRoundedBox(in float2 p, in float2 s, in float4 r) { |
| 14 | r.xy = (p.x > 0.0) ? r.xy : r.zw; |
| 15 | r.x = (p.y > 0.0) ? r.x : r.y; |
| 16 | float2 q = abs(p) - s + r.x; |
| 17 | return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r.x; |
| 18 | } |
| 19 |
| 20 | float3 rippleOffset_ios(float2 position, float2 center, float intensity, float time) { |
| 21 | float speed = (intensity > 1.0 ? 1200.0 : 1500.0) * density; |
| 22 | float frequency = (intensity > 1.0 ? 17.0 : 15.0); |
| 23 | float amplitude = (intensity > 1.0 ? 15.0 : 30.0) * density * intensity; |
| 24 | float decay = intensity > 1.0 ? 5.5 : 10.0; |
| 25 |
| 26 | float dist = length(position - center); |
| 27 | if (dist < 9.0 * density) return float3(0.0); |
| 28 |
| 29 | float delay = dist / speed; |
| 30 | time -= delay; |
| 31 | time = max(0.0, time); |
| 32 |
| 33 | float rippleAmount = amplitude * sin(frequency * time) * exp(-decay * time); |
| 34 | float absRippleAmount = abs(rippleAmount); |
| 35 | if (rippleAmount < 0.0) { |
| 36 | rippleAmount = -absRippleAmount; |
| 37 | } else { |
| 38 | rippleAmount = absRippleAmount; |
| 39 | } |
| 40 |
| 41 | if (dist <= 80.0 * density) { |
| 42 | rippleAmount *= mix(0.4, 1.0, clamp((dist - 60.0 * density) / (20.0 * density), 0.0, 1.0)); |
| 43 | } |
| 44 |
| 45 | return float3( |
| 46 | normalize(position - center) * rippleAmount, |
| 47 | (intensity > 1.0 ? 0.17 : 0.11) * (rippleAmount / amplitude) |
| 48 | ); |
| 49 | } |
| 50 |
| 51 | half4 main(in float2 fragCoord) { |
| 52 | float add = 0.0; |
| 53 | float2 offset = float2(0.0); |
| 54 | for (int i = 0; i < 7; ++i) { |
| 55 | if (i >= count) break; |
| 56 | float3 ripple = rippleOffset_ios(fragCoord, float2(centerX[i], centerY[i]), intensity[i], t[i]); |
| 57 | offset += ripple.xy; |
| 58 | add += ripple.z; |
| 59 | } |
| 60 | float2 uv = fragCoord + offset; |
| 61 | if (sdfRoundedBox(uv - size * .5, size * .5, radius) > 0.0) |
| 62 | return half4(0.0, 0.0, 0.0, 1.0); |
| 63 | return img.eval(uv) + half4(add, add, add, 1.); |
| 64 | } |