#ifdef GL_ES #extension GL_OES_texture_3D : enable precision mediump int; precision mediump float; precision mediump sampler3D; #endif #define USE_OGRE_FROM_FUTURE #include SAMPLER2D(RT, 0); SAMPLER3D(Rand, 1); SAMPLER3D(Noise, 2); SAMPLER2D(Overlay, 3); OGRE_UNIFORMS( uniform float distortionFreq; uniform float distortionScale; uniform float distortionRoll; uniform float interference; uniform float frameLimit; uniform float frameShape; uniform float frameSharpness; uniform float time_0_X; uniform float sin_time_0_X; ) MAIN_PARAMETERS IN(vec2 oUv0, TEXCOORD0) MAIN_DECLARATION { // Define a frame shape vec2 pos = abs((oUv0 - vec2_splat(0.5)) * vec2_splat(2.0)); float f = (1.0 - pos.x * pos.x) * (1.0 - pos.y * pos.y); float frame = clamp(frameSharpness * (pow(f, frameShape) - frameLimit), 0.0, 1.0); // Interference ... just a texture filled with rand() float rand = texture3D(Rand, vec3(1.5 * pos.x, 1.5 * pos.y, time_0_X)).x - 0.2; // Some signed noise for the distortion effect float noisy = texture3D(Noise, vec3(0.0, 0.5 * pos.y, 0.1 * time_0_X)).x - 0.5; // Repeat a 1 - x^2 (0 < x < 1) curve and roll it with sinus. float dst = fract(pos.y * distortionFreq + distortionRoll * sin_time_0_X); dst *= (1.0 - dst); // Make sure distortion is highest in the center of the image dst /= 1.0 + distortionScale * abs(pos.y); // ... and finally distort vec2 inUv = oUv0; inUv.x += distortionScale * noisy * dst; vec4 image = texture2D(RT, inUv); // Back frame vec4 overlay = texture2D(Overlay, inUv); // Combine frame, distorted image and interference gl_FragColor = vec4_splat(frame) * (overlay + vec4_splat(interference) * vec4_splat(rand) + image); }