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