Qaiser Butt
Qaiser Butt

Reputation: 444

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.

Upvotes: 0

Views: 1520

Answers (1)

Flex Monkey
Flex Monkey

Reputation: 3633

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

Upvotes: 2

Related Questions