1 | #version 100 |
---|
2 | |
---|
3 | precision mediump int; |
---|
4 | precision mediump float; |
---|
5 | |
---|
6 | varying vec2 oUv0; |
---|
7 | //varying vec2 uv1; |
---|
8 | |
---|
9 | uniform sampler2D RT; |
---|
10 | uniform sampler2D SplotchesTx; |
---|
11 | uniform sampler2D Texture2; |
---|
12 | uniform sampler2D SepiaTx; |
---|
13 | uniform float time_cycle_period; |
---|
14 | uniform float flicker; |
---|
15 | uniform float DirtFrequency; |
---|
16 | uniform vec3 luminance; |
---|
17 | uniform float frameJitter; |
---|
18 | uniform float lumiShift; |
---|
19 | |
---|
20 | vec2 calcSpriteAddr(vec2 texCoord, float DirtFrequency1, float period) |
---|
21 | { |
---|
22 | return texCoord + texture2D(Texture2, vec2(period * DirtFrequency1, 0.0)).xy; |
---|
23 | } |
---|
24 | |
---|
25 | vec4 getSplotches(vec2 spriteAddr) |
---|
26 | { |
---|
27 | // get sprite address into paged texture coords space |
---|
28 | spriteAddr = spriteAddr / 6.3; |
---|
29 | spriteAddr = spriteAddr - (spriteAddr / 33.3); |
---|
30 | |
---|
31 | return texture2D(SplotchesTx, spriteAddr); |
---|
32 | } |
---|
33 | |
---|
34 | void main() |
---|
35 | { |
---|
36 | // get sprite address |
---|
37 | vec2 spriteAddr = calcSpriteAddr(oUv0, DirtFrequency, time_cycle_period); |
---|
38 | |
---|
39 | // add some dark and light splotches to the film |
---|
40 | vec4 splotches = getSplotches(spriteAddr); |
---|
41 | vec4 specs = 1.0 - getSplotches(spriteAddr / 3.0); |
---|
42 | |
---|
43 | // convert color to base luminance |
---|
44 | vec4 base = texture2D(RT, oUv0 + vec2(0.0, spriteAddr.y * frameJitter)); |
---|
45 | float lumi = dot(base.rgb, luminance); |
---|
46 | // randomly shift luminance |
---|
47 | lumi -= spriteAddr.x * lumiShift; |
---|
48 | // tone map luminance |
---|
49 | base.rgb = texture2D(SepiaTx, vec2(lumi, 0.0)).rgb; |
---|
50 | |
---|
51 | // calc flicker speed |
---|
52 | float darken = fract(flicker * time_cycle_period); |
---|
53 | |
---|
54 | // we want darken to cycle between 0.6 and 1.0 |
---|
55 | darken = abs(darken - 0.5) * 0.4 + 0.6; |
---|
56 | // composite dirt onto film |
---|
57 | gl_FragColor = base * splotches * darken + specs; |
---|
58 | } |
---|