#ifdef GL_ES precision mediump int; precision mediump float; #endif #define USE_OGRE_FROM_FUTURE #include SAMPLER2D(RT, 0); SAMPLER2D(SplotchesTx, 1); SAMPLER2D(Texture2, 2); SAMPLER2D(SepiaTx, 3); OGRE_UNIFORMS( uniform float time_cycle_period; uniform float flicker; uniform float DirtFrequency; uniform vec3 luminance; uniform float frameJitter; uniform float lumiShift; ) vec2 calcSpriteAddr(vec2 texCoord, float DirtFrequency1, float period) { return texCoord + texture2D(Texture2, vec2(period * DirtFrequency1, 0.0)).xy; } vec4 getSplotches(vec2 spriteAddr) { // get sprite address into paged texture coords space spriteAddr = spriteAddr / vec2_splat(6.3); spriteAddr = spriteAddr - (spriteAddr / vec2_splat(33.3)); return texture2D(SplotchesTx, spriteAddr); } MAIN_PARAMETERS IN(vec2 oUv0, TEXCOORD0) MAIN_DECLARATION { // get sprite address vec2 spriteAddr = calcSpriteAddr(oUv0, DirtFrequency, time_cycle_period); // add some dark and light splotches to the film vec4 splotches = getSplotches(spriteAddr); vec4 specs = vec4_splat(1.0) - getSplotches(spriteAddr / vec2_splat(3.0)); // convert color to base luminance vec4 base = texture2D(RT, oUv0 + vec2(0.0, spriteAddr.y * frameJitter)); float lumi = dot(base.rgb, luminance); // randomly shift luminance lumi -= spriteAddr.x * lumiShift; // tone map luminance base.rgb = texture2D(SepiaTx, vec2(lumi, 0.0)).rgb; // calc flicker speed float darken = fract(flicker * time_cycle_period); // we want darken to cycle between 0.6 and 1.0 darken = abs(darken - 0.5) * 0.4 + 0.6; // composite dirt onto film gl_FragColor = base * splotches * vec4_splat(darken) + specs; }