PixelKit Demos

Particle Field Flow

pod 'PixelKit'
pod 'VertexKit'
import PixelKit
import VertexKit
view.backgroundColor = .black
        
PixelKit.main.bits = ._16

let res: PIX.Res = .fullscreen
let pres: PIX.Res = res / 8

let puv = MetalPIX(res: pres, uniforms: [
    MetalUniform(name: "aspct", value: pres.aspect)
    ], code:
    """
    pix = float4((u - 0.5) * in.aspct,
                 v - 0.5, 0, 0);
    """
)

let noise = NoisePIX(res: res)
noise.colored = true

let feed1 = puv._feed { feed -> (PIX & PIXOut) in
    let fx = MetalMergerEffectPIX(uniforms: [
            MetalUniform(name: "aspct",
                         value: pres.aspect),
            MetalUniform(name: "wind",
                         value: 0.001),
            MetalUniform(name: "force",
                        value: 0.01),
            MetalUniform(name: "thresh",
                         value: 0.001)
        ], code:
        """
        float x = inPixA.x;
        float y = inPixA.y;
        float xu = inPixA.z;
        float yv = inPixA.w;
        float4 b = inTexB.sample(s,
            float2(x/in.aspct+0.5,y+0.5));
        float vx = b.x * in.force;
        float vy = b.y * in.force;
        float vxy = sqrt(pow(vx, 2) + pow(vy, 2));
        if (vxy > in.thresh) {
            x += vx;
            y += vy;
        } else {
            x = xu;
            y = yv;
        }
        pix = float4(x,y,0,1);
        """
    )
    fx.inPixA = feed._RGtoBA(with: puv)
    fx.inPixB = noise - 0.5
    return fx
}

let particles = ParticlesUV3DPIX(res: res)
particles.vtxPixIn = feed1
particles.color = LiveColor(lum: 1.0, a: 0.5)

let feed2 = particles._feed { feed in
    return feed + particles
}

let finalPix = feed2
finalPix.view.frame = view.bounds
finalPix.view.checker = false
view.addSubview(finalPix.view)
Created by Hexagons