Advertisement
Guest User

Lanczos (4tap).OpenGL.shader

a guest
May 3rd, 2011
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.82 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.     Copyright (C) 2010 Team XBMC
  4.     http://www.xbmc.org
  5.     Copyright (C) 2011 Stefanos A.
  6.     http://www.opentk.com
  7.  
  8. This Program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2, or (at your option)
  11. any later version.
  12.  
  13. This Program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with XBMC; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21. http://www.gnu.org/copyleft/gpl.html
  22. -->
  23. <!--
  24.     From this forum post:
  25.  
  26.    http://board.byuu.org/viewtopic.php?p=33597
  27. -->
  28. <shader language="GLSL">
  29.     <vertex><![CDATA[
  30.     void main()
  31.     {
  32.         gl_TexCoord[0] = gl_MultiTexCoord0;         //center
  33.         gl_Position = ftransform();
  34.     }
  35.     ]]></vertex>
  36.  
  37.     <fragment><![CDATA[
  38.     #define FIX(c) max(abs(c), 1e-5);
  39.  
  40.     uniform sampler2D rubyTexture;
  41.     uniform vec2 rubyTextureSize;
  42.  
  43.     const float PI = 3.1415926535897932384626433832795;
  44.  
  45.     vec4 weight4(float x)
  46.     {        
  47.         vec4 sample = FIX(PI * vec4(1.0 + x, x, 1.0 - x, 2.0 - x));
  48.  
  49.         // Lanczos2
  50.         vec4 ret = 2.0 * sin(sample) * sin(sample / 2.0) / pow(sample, 2.0);
  51.  
  52.         // Normalize
  53.         return ret / dot(ret, vec4(1.0));
  54.     }        
  55.  
  56.     vec3 pixel(float xpos, float ypos)
  57.     {
  58.         return texture2D(rubyTexture, vec2(xpos, ypos)).rgb;
  59.     }
  60.  
  61.     vec3 line(float ypos, vec4 xpos, vec4 linetaps)
  62.     {        
  63.         return mat4x3(
  64.             pixel(xpos.x, ypos),
  65.             pixel(xpos.y, ypos),
  66.             pixel(xpos.z, ypos),
  67.             pixel(xpos.w, ypos)) * linetaps;          
  68.     }
  69.  
  70.     void main()
  71.     {
  72.         vec2 stepxy = 1.0 / rubyTextureSize.xy;
  73.         vec2 pos = gl_TexCoord[0].xy + stepxy * 0.5;
  74.         vec2 f = fract(pos / stepxy);
  75.  
  76.         vec2 xystart = (-1.5 - f) * stepxy + pos;
  77.         vec4 xpos = vec4(
  78.             xystart.x,
  79.             xystart.x + stepxy.x,
  80.             xystart.x + stepxy.x * 2.0,
  81.             xystart.x + stepxy.x * 3.0);
  82.  
  83.         vec4 linetaps   = weight4(f.x);
  84.         vec4 columntaps = weight4(f.y);  
  85.  
  86.         gl_FragColor.rgb = mat4x3(
  87.             line(xystart.y                 , xpos, linetaps),
  88.             line(xystart.y + stepxy.y      , xpos, linetaps),
  89.             line(xystart.y + stepxy.y * 2.0, xpos, linetaps),
  90.             line(xystart.y + stepxy.y * 3.0, xpos, linetaps)) * columntaps;
  91.  
  92.         gl_FragColor.a = 1.0;
  93.     }
  94.     ]]></fragment>
  95. </shader>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement