xbr-mlv4-pass4.fs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. Hyllian's xBR MultiLevel4 Shader - Pass4
  3. Ported by Aliaspider.
  4. Copyright (C) 2011/2013 Hyllian/Jararaca - sergiogdb@gmail.com
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. #version 150
  18. #define ROUND(X) floor((X)+0.5)
  19. #define ORIG_ID 3
  20. #define bin vec3( 4.0, 2.0, 1.0)
  21. uniform sampler2D source[];
  22. uniform vec4 sourceSize[];
  23. uniform vec4 targetSize;
  24. in Vertex {
  25. vec2 texCoord;
  26. };
  27. out vec4 fragColor;
  28. vec4 remapFrom01(vec4 v)
  29. {
  30. return floor((v*vec4(128.0))-vec4(63.5));
  31. }
  32. float c_df(vec3 c1, vec3 c2)
  33. {
  34. vec3 df = abs(c1 - c2);
  35. return df.r + df.g + df.b;
  36. }
  37. float df(float A, float B)
  38. {
  39. return abs(A-B);
  40. }
  41. #define GET_PIXEL(PARAM, PIXEL)\
  42. info = PARAM;\
  43. ay.z = ROUND( modf( info/2.0, info ) );\
  44. ay.y = ROUND( modf( info/2.0, info ) );\
  45. ay.x = ROUND( modf( info/2.0, info ) );\
  46. ax.z = ROUND( modf( info/2.0, info ) );\
  47. ax.y = ROUND( modf( info/2.0, info ) );\
  48. ax.x = ROUND( info );\
  49. iq.x = dot( ax, bin ) - 2.0;\
  50. iq.y = dot( ay, bin ) - 2.0;\
  51. PIXEL = texture( source[ORIG_ID], pxcoord + iq*sourceSize[ORIG_ID].zw ).xyz;\
  52. void main(void){
  53. float scale_factor = targetSize.x*sourceSize[ORIG_ID].z;
  54. vec2 fp = fract( texCoord*sourceSize[ORIG_ID].xy ) - vec2( 0.5, 0.5 );
  55. vec2 pxcoord = (floor(texCoord*sourceSize[ORIG_ID].xy)+vec2(0.5,0.5))*sourceSize[ORIG_ID].zw;
  56. vec4 UL = texture(source[0], pxcoord + vec2(-0.25,-0.25)*sourceSize[ORIG_ID].zw);
  57. vec4 UR = texture(source[0], pxcoord + vec2( 0.25,-0.25)*sourceSize[ORIG_ID].zw);
  58. vec4 DL = texture(source[0], pxcoord + vec2(-0.25, 0.25)*sourceSize[ORIG_ID].zw);
  59. vec4 DR = texture(source[0], pxcoord + vec2( 0.25, 0.25)*sourceSize[ORIG_ID].zw);
  60. vec4 ulparam = remapFrom01( UL ); // retrieve previous passes info
  61. vec4 urparam = remapFrom01( UR ); // retrieve previous passes info
  62. vec4 dlparam = remapFrom01( DL ); // retrieve previous passes info
  63. vec4 drparam = remapFrom01( DR ); // retrieve previous passes info
  64. vec3 E = texture( source[ORIG_ID], pxcoord ).xyz;
  65. vec3 ax, ay, PX, PY, PZ, PW;
  66. float info;
  67. vec2 iq;
  68. GET_PIXEL(ulparam.w, PX);
  69. GET_PIXEL(urparam.w, PY);
  70. GET_PIXEL(dlparam.w, PZ);
  71. GET_PIXEL(drparam.w, PW);
  72. vec3 fp1 = vec3( fp, -1 );
  73. vec3 color;
  74. vec4 fx;
  75. vec4 inc = vec4(abs(ulparam.x/ulparam.y), abs(urparam.x/urparam.y), abs(dlparam.x/dlparam.y), abs(drparam.x/drparam.y));
  76. vec4 level = max(inc, 1.0/inc);
  77. fx.x = clamp( dot( fp1, ulparam.xyz ) * scale_factor/( 8.0 * level.x ) + 0.5 ,0.0,1.0);
  78. fx.y = clamp( dot( fp1, urparam.xyz ) * scale_factor/( 8.0 * level.y ) + 0.5 ,0.0,1.0);
  79. fx.z = clamp( dot( fp1, dlparam.xyz ) * scale_factor/( 8.0 * level.z ) + 0.5 ,0.0,1.0);
  80. fx.w = clamp( dot( fp1, drparam.xyz ) * scale_factor/( 8.0 * level.w ) + 0.5 ,0.0,1.0);
  81. vec3 c1, c2, c3, c4;
  82. c1 = mix( E, PX, fx.x );
  83. c2 = mix( E, PY, fx.y );
  84. c3 = mix( E, PZ, fx.z );
  85. c4 = mix( E, PW, fx.w );
  86. color = c1;
  87. color = ( (c_df(c2, E) > c_df(color, E)) ) ? c2 : color;
  88. color = ( (c_df(c3, E) > c_df(color, E)) ) ? c3 : color;
  89. color = ( (c_df(c4, E) > c_df(color, E)) ) ? c4 : color;
  90. fragColor=vec4( color, 1.0 );
  91. }