简体   繁体   中英

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

I'm looking to add an effect into my app (Live Filtering Recorder App) using core image filter. This effect needs to show distortion lines appearing just like old time recorders. I tried it by loading image frames and applying as overlay to the output of the filters image but that create a lag into the recording. So i'm not looking to generate this effect by CIFILTERS now.

Tape Recorder like Distortion Lines

Thanks.

This looks like a job for a custom kernel.

You can generate a random noise field with CIRandomGenerator and then use some custom Core Image Kernel Language to composite it over your original image in stripes using sin to control the spacing. Passing the sine of the vertical position through a smoothstep gives a nice effect.

You kernel should look something like:

    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);" +
        "}"
        )!

I've actually written a CIFilter to do this which you can find here .

Simon

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM