1 | sampler RT : register(s0); |
---|
2 | sampler SplotchesTx : register(s1); |
---|
3 | sampler Texture2 : register(s2); |
---|
4 | sampler SepiaTx : register(s3); |
---|
5 | |
---|
6 | float2 calcSpriteAddr(float2 texCoord, float DirtFrequency, float period) |
---|
7 | { |
---|
8 | return texCoord + tex1D(Texture2, period * DirtFrequency); |
---|
9 | } |
---|
10 | |
---|
11 | float4 getSplotches(float2 spriteAddr) |
---|
12 | { |
---|
13 | // get sprite address into paged texture coords space |
---|
14 | spriteAddr = spriteAddr / 6.3f; |
---|
15 | //spriteAddr = spriteAddr - frac(spriteAddr); |
---|
16 | spriteAddr = spriteAddr - (spriteAddr /33.3f); |
---|
17 | |
---|
18 | return tex2D(SplotchesTx, spriteAddr); |
---|
19 | } |
---|
20 | |
---|
21 | float4 OldMovie_ps (float2 texCoord : TEXCOORD0, |
---|
22 | uniform float time_cycle_period, |
---|
23 | uniform float flicker, |
---|
24 | uniform float DirtFrequency, |
---|
25 | uniform float3 luminance, |
---|
26 | uniform float frameJitter, |
---|
27 | uniform float lumiShift |
---|
28 | ) : COLOR |
---|
29 | { |
---|
30 | |
---|
31 | // get sprite address |
---|
32 | float2 spriteAddr = calcSpriteAddr(texCoord, DirtFrequency, time_cycle_period); |
---|
33 | |
---|
34 | // add some dark and light splotches to the film |
---|
35 | float4 splotches = getSplotches(spriteAddr); |
---|
36 | float4 specs = 1.0f - getSplotches(spriteAddr / 3.0f); |
---|
37 | |
---|
38 | // convert color to base luminance |
---|
39 | float4 base = tex2D(RT, texCoord + float2(0, spriteAddr.y * frameJitter)); |
---|
40 | float lumi = dot(base.rgb, luminance); |
---|
41 | // randomly shift luminance |
---|
42 | lumi -= spriteAddr.x * lumiShift; |
---|
43 | // tone map luminance |
---|
44 | base.rgb = tex1D(SepiaTx, lumi ); |
---|
45 | |
---|
46 | // calc flicker speed |
---|
47 | float darken = frac(flicker * time_cycle_period); |
---|
48 | |
---|
49 | // we want darken to cycle between 0.6 and 1.0 |
---|
50 | darken = abs(darken - 0.5f) * 0.4f + 0.6f; |
---|
51 | // composite dirt onto film |
---|
52 | return base * splotches * darken + specs; |
---|
53 | } |
---|
54 | |
---|