Advertisement
Guest User

smart-blur v2

a guest
May 3rd, 2014
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. /* COMPATIBILITY
  2. - HLSL compilers
  3. - Cg compilers
  4. */
  5.  
  6. /*
  7. Hyllian Smart-Blur 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. // Control the blur changing this param (RGB values). Below the threshold, blur is applied for each color channel.
  28. // Threshold is the max color differency among the eight pixel neighbors from central pixel.
  29. const static float3 threshold = float3(0.2, 0.2, 0.2);
  30.  
  31.  
  32. bool eq(float3 c1, float3 c2) {
  33. return all(abs(c1 - c2) < threshold);
  34. }
  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. A1 B1
  49. A B C C4
  50. D0 D E F F4
  51. G0 G H I
  52. H5 I5
  53.  
  54. f = (C + C4 + F + F4)/4; // and so on... to get four texture colors in only one fetch using linear filtering.
  55.  
  56. */
  57.  
  58.  
  59. struct out_vertex {
  60. float2 texCoord;
  61. };
  62.  
  63. /* VERTEX_SHADER */
  64. out_vertex main_vertex
  65. (
  66. float4 position : POSITION,
  67. out float4 oPosition : POSITION,
  68. float2 tex : TEXCOORD0,
  69.  
  70. uniform float4x4 modelViewProj,
  71. uniform input IN
  72. )
  73. {
  74.  
  75. oPosition = mul(modelViewProj, position);
  76.  
  77. out_vertex OUT = {
  78. tex
  79. };
  80.  
  81.  
  82. return OUT;
  83. }
  84.  
  85.  
  86. float4 main_fragment(in out_vertex VAR, uniform sampler2D s_p : TEXUNIT0, uniform input IN) : COLOR
  87. {
  88. float2 dx = float2(1.0/IN.texture_size.x, 0.0);
  89. float2 dy = float2(0.0, 1.0/IN.texture_size.y);
  90. float2 pix_upper_left = floor(VAR.texCoord*IN.texture_size);
  91.  
  92. float2 tc = (pix_upper_left+float2(0.5,0.5))/IN.texture_size;
  93.  
  94. pix_upper_left /= IN.texture_size;
  95.  
  96. float3 E = tex2D(s_p, tc).xyz;
  97.  
  98. float3 f = tex2D(s_p, pix_upper_left+2.0*dx ).xyz;
  99. float3 b = tex2D(s_p, pix_upper_left -dy).xyz;
  100. float3 d = tex2D(s_p, pix_upper_left -dx +dy).xyz;
  101. float3 h = tex2D(s_p, pix_upper_left +dx+2.0*dy).xyz;
  102.  
  103. if (eq(E,f) && eq(E,h) && eq(E,b) && eq(E,d)) {
  104. E = (E+f+b+d+h)/5.0;
  105. }
  106.  
  107. return float4(E, 1.0);
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement