SHARE
TWEET

xbr-lvl2.glsl for Dolphin 4.0-6068

a guest Apr 24th, 2015 276 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.    Hyllian's xBR-lv2 Shader
  3.    
  4.    Copyright (C) 2011/2014 Hyllian/Jararaca - sergiogdb@gmail.com
  5.  
  6.    This program is free software; you can redistribute it and/or
  7.    modify it under the terms of the GNU General Public License
  8.    as published by the Free Software Foundation; either version 2
  9.    of the License, or (at your option) any later version.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21.    Incorporates some of the ideas from SABR shader. Thanks to Joshua Street.
  22. */
  23.  
  24. /*
  25. [configuration]
  26.  
  27. [OptionBool]
  28. GUIName = xbr-lvl2
  29. OptionName = BR
  30. DefaultValue = true
  31.  
  32. [/configuration]
  33. */
  34.  
  35. const float coef = 2.0;
  36. const float3 rgbw = float3(16.163, 23.351, 8.4772);
  37. const float4 xbr_eq_threshold = float4(15.0, 15.0, 15.0, 15.0);
  38. const float xbr_scale = 3.0;
  39.  
  40. const float4 Ao = float4( 1.0, -1.0, -1.0, 1.0 );
  41. const float4 Bo = float4( 1.0,  1.0, -1.0,-1.0 );
  42. const float4 Co = float4( 1.5,  0.5, -0.5, 0.5 );
  43. const float4 Ax = float4( 1.0, -1.0, -1.0, 1.0 );
  44. const float4 Bx = float4( 0.5,  2.0, -0.5,-2.0 );
  45. const float4 Cx = float4( 1.0,  1.0, -0.5, 0.0 );
  46. const float4 Ay = float4( 1.0, -1.0, -1.0, 1.0 );
  47. const float4 By = float4( 2.0,  0.5, -2.0,-0.5 );
  48. const float4 Cy = float4( 2.0,  0.0, -1.0, 0.5 );
  49.  
  50.  
  51. float4 df(float4 A, float4 B)
  52. {
  53.     return abs(A-B);
  54. }
  55.  
  56. float4 weighted_distance(float4 a, float4 b, float4 c, float4 d, float4 e, float4 f, float4 g, float4 h)
  57. {
  58.     return (df(a,b) + df(a,c) + df(d,e) + df(d,f) + 4.0*df(g,h));
  59. }
  60.  
  61.  
  62. bvec4 eq(float4 A, float4 B)
  63. {
  64.     return (greaterThan(xbr_eq_threshold, df(A, B)));
  65. }
  66.  
  67.  
  68. void main() {
  69.     float4 color = Sample();
  70.     if OptionEnabled(BR) {
  71.         bvec4 edr, edr_left, edr_up, px; // px = pixel, edr = edge detection rule
  72.         bvec4 interp_restriction_lv1, interp_restriction_lv2_left, interp_restriction_lv2_up;
  73.         float4 fx, fx_left, fx_up, final_fx; // inequations of straight lines.
  74.         float3 res1, res2, pix1, pix2, pix[4];
  75.         float4 pixel;
  76.         float4 delta         = float4(1.0/xbr_scale, 1.0/xbr_scale, 1.0/xbr_scale, 1.0/xbr_scale);
  77.         float4 deltaL        = float4(0.5/xbr_scale, 1.0/xbr_scale, 0.5/xbr_scale, 1.0/xbr_scale);
  78.         float4 deltaU        = deltaL.yxwz;
  79.  
  80.    
  81.     float2 fp  = fract(GetCoordinates()*GetResolution());
  82.     float2 TexCoord_0 = GetCoordinates()-fp*GetInvResolution();
  83.     float2 dx = float2(GetInvResolution().x, 0.0);
  84.     float2 dy = float2(0.0, GetInvResolution().y);
  85.     float2 y2 = dy+dy; float2 x2 = dx+dx;
  86.  
  87.     float3 A  = SampleLocation(TexCoord_0 - dx - dy).xyz;
  88.     float3 B  = SampleLocation(TexCoord_0 - dy).xyz;
  89.     float3 C  = SampleLocation(TexCoord_0 + dx - dy).xyz;
  90.     float3 D  = SampleLocation(TexCoord_0 - dx).xyz;
  91.     float3 E  = SampleLocation(TexCoord_0).xyz;
  92.     float3 F  = SampleLocation(TexCoord_0 + dx).xyz;
  93.     float3 G  = SampleLocation(TexCoord_0  - dx + dy).xyz;
  94.     float3 H  = SampleLocation(TexCoord_0 + dy).xyz;
  95.     float3 I  = SampleLocation(TexCoord_0 + dx + dy).xyz;
  96.     float3 A1 = SampleLocation(TexCoord_0  - dx - y2).xyz;
  97.     float3 C1 = SampleLocation(TexCoord_0  + dx - y2).xyz;
  98.     float3 A0 = SampleLocation(TexCoord_0 - x2 - dy).xyz;
  99.     float3 G0 = SampleLocation(TexCoord_0 - x2 + dy).xyz;
  100.     float3 C4 = SampleLocation(TexCoord_0 + x2 - dy).xyz;
  101.     float3 I4 = SampleLocation(TexCoord_0 + x2 + dy).xyz;
  102.     float3 G5 = SampleLocation(TexCoord_0 - dx + y2).xyz;
  103.     float3 I5 = SampleLocation(TexCoord_0 + dx + y2).xyz;
  104.     float3 B1 = SampleLocation(TexCoord_0 - y2).xyz;
  105.     float3 D0 = SampleLocation(TexCoord_0 - x2).xyz;
  106.     float3 H5 = SampleLocation(TexCoord_0 + y2).xyz;
  107.     float3 F4 = SampleLocation(TexCoord_0 + x2).xyz;
  108.  
  109.     float4 b  = float4(dot(B ,rgbw), dot(D ,rgbw), dot(H ,rgbw), dot(F ,rgbw));
  110.     float4 c  = float4(dot(C ,rgbw), dot(A ,rgbw), dot(G ,rgbw), dot(I ,rgbw));
  111.     float4 d  = float4(b.y, b.z, b.w, b.x);
  112.     float4 e  = float4(dot(E,rgbw));
  113.     float4 f  = float4(b.w, b.x, b.y, b.z);
  114.     float4 g  = float4(c.z, c.w, c.x, c.y);
  115.     float4 h  = float4(b.z, b.w, b.x, b.y);
  116.     float4 i  = float4(c.w, c.x, c.y, c.z);
  117.     float4 i4 = float4(dot(I4,rgbw), dot(C1,rgbw), dot(A0,rgbw), dot(G5,rgbw));
  118.     float4 i5 = float4(dot(I5,rgbw), dot(C4,rgbw), dot(A1,rgbw), dot(G0,rgbw));
  119.     float4 h5 = float4(dot(H5,rgbw), dot(F4,rgbw), dot(B1,rgbw), dot(D0,rgbw));
  120.     float4 f4 = float4(h5.y, h5.z, h5.w, h5.x);
  121.  
  122.  
  123.  
  124.         // These inequations define the line below which interpolation occurs.
  125.         fx      = (Ao*fp.y+Bo*fp.x);
  126.         fx_left = (Ax*fp.y+Bx*fp.x);
  127.         fx_up   = (Ay*fp.y+By*fp.x);
  128.  
  129.  
  130.     interp_restriction_lv1 = bvec4(float4(notEqual(e,f))*float4(notEqual(e,h)));
  131.     interp_restriction_lv2_left = bvec4(float4(notEqual(e,g))*float4(notEqual(d,g)));
  132.     interp_restriction_lv2_up   = bvec4(float4(notEqual(e,c))*float4(notEqual(b,c)));
  133.  
  134.  
  135.         float4 fx45 = clamp((fx      + delta  -Co)/(2*delta ), 0.0, 1.0);
  136.         float4 fx30 = clamp((fx_left + deltaL -Cx)/(2*deltaL), 0.0, 1.0);
  137.         float4 fx60 = clamp((fx_up   + deltaU -Cy)/(2*deltaU), 0.0, 1.0);
  138.  
  139.     edr      = bvec4(float4(lessThan(weighted_distance( e, c, g, i, h5, f4, h, f), weighted_distance( h, d, i5, f, i4, b, e, i)))*float4(interp_restriction_lv1));
  140.     edr_left = bvec4(float4(lessThanEqual(coef*df(f,g),df(h,c)))*float4(interp_restriction_lv2_left)*float4(edr));
  141.     edr_up   = bvec4(float4(greaterThanEqual(df(f,g),coef*df(h,c)))*float4(interp_restriction_lv2_up)*float4(edr));
  142.  
  143.  
  144.         fx45 = float4(edr)*fx45;
  145.         fx30 = float4(edr_left)*fx30;
  146.         fx60 = float4(edr_up)*fx60;
  147.  
  148.         px = lessThanEqual(df(e,f),df(e,h));
  149.  
  150.         float4 maximo = max(max(fx30, fx60), fx45);
  151.  
  152.         pix[0] = mix(E, mix(H, F, float(px.x)), maximo.x);
  153.         pix[1] = mix(E, mix(F, B, float(px.y)), maximo.y);
  154.         pix[2] = mix(E, mix(B, D, float(px.z)), maximo.z);
  155.         pix[3] = mix(E, mix(D, H, float(px.w)), maximo.w);
  156.         pixel = float4(dot( pix[0], rgbw ), dot( pix[1], rgbw ), dot( pix[2], rgbw ), dot( pix[3], rgbw ));
  157.        
  158.  
  159.         float4 diff = df(pixel,e);
  160.  
  161.         float3 res = pix[0];
  162.         float mx = diff.x;
  163.  
  164.         if (diff.y > mx) {res = pix[1]; mx = diff.y;}
  165.         if (diff.z > mx) {res = pix[2]; mx = diff.z;}
  166.         if (diff.w > mx) {res = pix[3];}
  167.         color.xyz = res;
  168.         }
  169.     SetOutput(color);
  170. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top