Advertisement
Guest User

unknown filter

a guest
May 8th, 2014
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. /* COMPATIBILITY
  2. - HLSL compilers
  3. - Cg compilers
  4. */
  5.  
  6. /*
  7. Hyllian's lanczos2-sharp Shader
  8.  
  9. Copyright (C) 2011-2014 Hyllian/Jararaca - sergiogdb@gmail.com
  10.  
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24.  
  25. */
  26.  
  27. const static float floatpi = 1.5707963267948966192313216916398;
  28. const static float pi = 3.1415926535897932384626433832795;
  29.  
  30. // Calculates the distance between two points
  31. float d(float2 pt1, float2 pt2)
  32. {
  33. float2 v = pt2 - pt1;
  34. return sqrt(dot(v,v));
  35. }
  36.  
  37. struct input
  38. {
  39. float2 video_size;
  40. float2 texture_size;
  41. float2 output_size;
  42. float frame_count;
  43. float frame_direction;
  44. float frame_rotation;
  45. };
  46.  
  47.  
  48. struct out_vertex {
  49. float4 position : POSITION;
  50. float4 color : COLOR;
  51. float2 texCoord : TEXCOORD0;
  52. };
  53.  
  54. /* VERTEX_SHADER */
  55. out_vertex main_vertex
  56. (
  57. float4 position : POSITION,
  58. float4 color : COLOR,
  59. float2 texCoord1 : TEXCOORD0,
  60.  
  61. uniform float4x4 modelViewProj,
  62. uniform input IN
  63. )
  64. {
  65.  
  66. // This line fix a bug in ATI cards.
  67. float2 tex = texCoord1;
  68.  
  69. out_vertex OUT = {
  70. mul(modelViewProj, position),
  71. color,
  72. tex
  73. };
  74.  
  75. return OUT;
  76. }
  77.  
  78. float4 lanczos(float4 x)
  79. {
  80. float4 res;
  81. // res = (x==float4(0.0, 0.0, 0.0, 0.0)) ? float4(pi*floatpi) : sin(x*floatpi)*sin(x*pi)/(x*x);
  82.  
  83. // res = (x==float4(0.0, 0.0, 0.0, 0.0)) ? float4(1.0) : (2/(pi*pi))*sin(x*floatpi)*sin(x*pi)/(x*x);
  84.  
  85. // res = (x==float4(0.0, 0.0, 0.0, 0.0)) ? float4(0.5) : pi*cos(x*pi)*pi*cos(x*pi*(1.22/2.233));
  86.  
  87. // res = (x==float4(0.0, 0.0, 0.0, 0.0)) ? float4(0.5) : 2*(0.5-x*x/16.0+x*x*x*x/384.0)*sin(pi*x)/(pi*x);
  88.  
  89. //res = (x==float4(0.0, 0.0, 0.0, 0.0)) ? float4(1.0) : cos(x/2)*sin(x*pi)/(2*pi*x);
  90.  
  91. res = (x==float4(0.0, 0.0, 0.0, 0.0)) ? float4(1.0) : cos(x/floatpi)*sin(x*pi)/(pi*x);
  92.  
  93.  
  94. return res;
  95. }
  96.  
  97. float4 main_fragment(in out_vertex VAR, uniform sampler2D s_p : TEXUNIT0, uniform input IN) : COLOR
  98. {
  99. float3 color;
  100. float4x4 weights;
  101.  
  102. float2 dx = float2(1.0, 0.0);
  103. float2 dy = float2(0.0, 1.0);
  104.  
  105. float2 pc = VAR.texCoord*IN.texture_size;
  106.  
  107. float2 tc = (floor(pc-float2(0.5,0.5))+float2(0.5,0.5));
  108.  
  109. weights[0] = lanczos(float4(d(pc, tc -dx -dy), d(pc, tc -dy), d(pc, tc +dx -dy), d(pc, tc+2.0*dx -dy)));
  110. weights[1] = lanczos(float4(d(pc, tc -dx ), d(pc, tc ), d(pc, tc +dx ), d(pc, tc+2.0*dx )));
  111. weights[2] = lanczos(float4(d(pc, tc -dx +dy), d(pc, tc +dy), d(pc, tc +dx +dy), d(pc, tc+2.0*dx +dy)));
  112. weights[3] = lanczos(float4(d(pc, tc -dx+2.0*dy), d(pc, tc +2.0*dy), d(pc, tc +dx+2.0*dy), d(pc, tc+2.0*dx+2.0*dy)));
  113.  
  114. // weights[0].x = weights[0].w = weights[3].x = weights[3].w = 0.0;
  115.  
  116. dx = dx/IN.texture_size;
  117. dy = dy/IN.texture_size;
  118. tc = tc/IN.texture_size;
  119.  
  120. // reading the texels
  121.  
  122. float3 c00 = tex2D(s_p, tc -dx -dy).xyz;
  123. float3 c10 = tex2D(s_p, tc -dy).xyz;
  124. float3 c20 = tex2D(s_p, tc +dx -dy).xyz;
  125. float3 c30 = tex2D(s_p, tc+2.0*dx -dy).xyz;
  126. float3 c01 = tex2D(s_p, tc -dx ).xyz;
  127. float3 c11 = tex2D(s_p, tc ).xyz;
  128. float3 c21 = tex2D(s_p, tc +dx ).xyz;
  129. float3 c31 = tex2D(s_p, tc+2.0*dx ).xyz;
  130. float3 c02 = tex2D(s_p, tc -dx +dy).xyz;
  131. float3 c12 = tex2D(s_p, tc +dy).xyz;
  132. float3 c22 = tex2D(s_p, tc +dx +dy).xyz;
  133. float3 c32 = tex2D(s_p, tc+2.0*dx +dy).xyz;
  134. float3 c03 = tex2D(s_p, tc -dx+2.0*dy).xyz;
  135. float3 c13 = tex2D(s_p, tc +2.0*dy).xyz;
  136. float3 c23 = tex2D(s_p, tc +dx+2.0*dy).xyz;
  137. float3 c33 = tex2D(s_p, tc+2.0*dx+2.0*dy).xyz;
  138.  
  139. color = mul(weights[0], float4x3(c00, c10, c20, c30));
  140. color+= mul(weights[1], float4x3(c01, c11, c21, c31));
  141. color+= mul(weights[2], float4x3(c02, c12, c22, c32));
  142. color+= mul(weights[3], float4x3(c03, c13, c23, c33));
  143.  
  144. // final sum and weight normalization
  145. return float4(color/(dot(mul(weights, float4(1)), 1)), 1);
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement