summaryrefslogtreecommitdiff
path: root/shaders/vcr_lite.kage
blob: 405195c3e0207bfe27657521bb68b962795247b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//go:build ignore

//kage:unit pixels

package main

var Time float
var NoiseOffset float

const noiseX = 840.0
const noiseY = 840.0
const speed = 0.01

const colorOffsetIntensity = 0.1

func rand(co vec2) float {
    return fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453)
}


func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
    time := Time * speed
    uv := srcPos / imageSrc0Size()

    uv.x = uv.x + (rand(vec2(time,srcPos.y)) - 0.5) / (noiseX); 
    uv.y = uv.y + (rand(vec2(time))-0.5) / (noiseY)
    offsetR := vec2(0.006 * sin(time), 0.0) * colorOffsetIntensity
    offsetG := vec2(0.0073 * (cos(time * 0.97)), 0.0) * colorOffsetIntensity
    r := imageSrc0UnsafeAt((uv+offsetR) * imageSrc0Size()).r
    g := imageSrc0UnsafeAt((uv+offsetG) * imageSrc0Size()).g
    b := imageSrc0UnsafeAt(uv * imageSrc0Size()).b
    return vec4(r, g, b, 1.0)
}