link下的图片如何使用CIFilter制作失真效果

How to create distortion effect using CIFilter as the images under link

我希望使用核心图像过滤器将效果添加到我的应用程序(实时过滤记录器应用程序)中。此效果需要显示像旧时录音机一样出现的失真线。我通过加载图像帧并将其作为叠加层应用到滤镜图像的输出来进行尝试,但这会在录制中造成滞后。所以我现在不打算通过 CIFILTERS 产生这种效果。

Tape Recorder like Distortion Lines

谢谢。

这看起来像是自定义内核的工作。

您可以使用 CIRandomGenerator 生成随机噪声场,然后使用一些自定义的 Core Image Kernel Language 将其合成到原始图像上,使用 sin 控制间距。通过 smoothstep 传递垂直位置的正弦会产生很好的效果。

您的内核应该类似于:

    let kernel = CIColorKernel(string:
        "kernel vec4 vhsNoise(__sample image, __sample noise, float time, float spacing, float stripeHeight, float backgroundNoise)" +
            "{" +
            "   vec2 uv = destCoord();" +

            "   float stripe = smoothstep(1.0 - stripeHeight, 1.0, sin((time + uv.y) / spacing)); " +

            "   return image + (noise * noise * stripe) + (noise * backgroundNoise);" +
        "}"
        )!

我实际上写了一个 CIFilter 来做到这一点,你可以 find here

西蒙