Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2012
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. /*
  2. Fuzzyscreen filter by Chris Klimas <chris@twofoldsecret.com>
  3.  
  4. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
  5.  
  6. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
  7.  
  8. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  9.  
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11.  
  12. 3. This notice may not be removed or altered from any source distribution.
  13.  
  14. http://opensource.org/licenses/Zlib
  15.  
  16. */
  17.  
  18. // width of a pixel in texture units,
  19. // should be set to 1 / width, 1 / height.
  20. uniform vec2 pixelSize;
  21.  
  22. // how sharp the bilinear filter is, 0 - 1
  23. uniform float sharpness = 0.5;
  24.  
  25. // how much to boost the brightness of pixels to compensate for scanlines, 0-1
  26. // 0 = no increase, 1 = double brightness
  27. uniform float brightness = 0.25;
  28.  
  29. // how much a scanline should darken its line, 0-1
  30. uniform float scanIntensity = 0.25;
  31.  
  32. // orientation of scanlines
  33. // 1 = horizontal scanlines, 0 = vertical scanlines
  34. uniform float scanHorizontal = 1;
  35.  
  36. // amount of noise, 0-1 (a little goes a long way)
  37. uniform float noise = 0.075;
  38.  
  39. // seed used to generate noise, change this on every frame to add shimmer
  40. uniform float noiseSeed = 0.0;
  41.  
  42. vec4 effect (vec4 color, sampler2D texture, vec2 texturePos, vec2 pixelPos)
  43. {
  44.     // bilinear filter
  45.    
  46.     float xInc = pixelSize.x * (1.0 - sharpness);
  47.     float yInc = pixelSize.y * (1.0 - sharpness);
  48.  
  49.     vec4 result = texture2D(texture, texturePos + vec2(-xInc, -yInc));
  50.     result += texture2D(texture, texturePos + vec2(xInc, -yInc));
  51.     result += texture2D(texture, texturePos + vec2(-xInc, yInc));
  52.     result += texture2D(texture, texturePos + vec2(xInc, yInc));
  53.     result /= 4;
  54.  
  55.     // noise
  56.     // pseudo-random number generator via
  57.     // http://www.ozone3d.net/blogs/lab/20110427/glsl-random-generator/
  58.  
  59.     result = result + noise * fract(sin(dot(texturePos.xy + noiseSeed, vec2(12.9898, 78.233))) * 43758.5453);
  60.  
  61.     // scanlines
  62.  
  63.     int coord = int(scanHorizontal);
  64.  
  65.     if (scanIntensity > 0.0 && mod(texturePos[coord], pixelSize[coord] * 2) > pixelSize[coord])
  66.     {
  67.         result.r = max(result.r - scanIntensity, 0);
  68.         result.g = max(result.g - scanIntensity, 0);
  69.         result.b = max(result.b - scanIntensity, 0);
  70.     };
  71.  
  72.     // final brightness adjustment
  73.    
  74.     return result * (1 + brightness);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement