1. /*
  2.    bicubic-fast Shader
  3.  
  4.    Programmed by Hyllian - 2012
  5.  
  6. */
  7.  
  8.  
  9. const static float4x4 invX = float4x4(-1.0/6.0,  0.5, -1.0/3.0, 0.0,
  10.                                            0.5, -1.0,     -0.5, 1.0,
  11.                                           -0.5,  0.5,      1.0, 0.0,
  12.                                        1.0/6.0,  0.0, -1.0/6.0, 0.0);
  13.  
  14.  
  15. const static float4x4 invY = float4x4(-1.0/6.0,  0.5, -0.5,  1.0/6.0,
  16.                                            0.5, -1.0,  0.5,      0.0,
  17.                                       -1.0/3.0, -0.5,  1.0, -1.0/6.0,
  18.                                            0.0,  1.0,  0.0,      0.0);
  19.  
  20. struct input
  21. {
  22.     float2 video_size;
  23.     float2 texture_size;
  24.     float2 output_size;
  25. };
  26.  
  27.  
  28. struct out_vertex {
  29.     float4 position : POSITION;
  30.     float4 color    : COLOR;
  31.     float2 texCoord : TEXCOORD0;
  32.     float4 t1;
  33.     float4 t2;
  34.     float4 t3;
  35.     float4 t4;
  36.     float4 t5;
  37.     float4 t6;
  38.     float4 t7;
  39.     float2 t8;
  40. };
  41.  
  42. /*    VERTEX_SHADER    */
  43. out_vertex main_vertex
  44. (
  45.     float4 position : POSITION,
  46.     float4 color    : COLOR,
  47.     float2 tex      : TEXCOORD0,
  48.  
  49.     uniform float4x4 modelViewProj,
  50.     uniform input IN
  51. )
  52. {
  53.     float2 ps = float2(1.0/IN.texture_size.x, 1.0/IN.texture_size.y);
  54.     float dx = ps.x;
  55.     float dy = ps.y;
  56.  
  57.  
  58.     out_vertex OUT = {
  59.         mul(modelViewProj, position),
  60.         color,
  61.         tex,
  62.         float4(tex,tex) + float4(   -dx,    -dy,    0.0,    -dy),
  63.         float4(tex,tex) + float4(    dx,    -dy, 2.0*dx,    -dy),
  64.         float4(tex,tex) + float4(   -dx,    0.0,     dx,    0.0),
  65.         float4(tex,tex) + float4(2.0*dx,    0.0,    -dx,     dy),
  66.         float4(tex,tex) + float4(   0.0,     dy,     dx,     dy),
  67.         float4(tex,tex) + float4(2.0*dx,     dy,    -dx, 2.0*dy),
  68.         float4(tex,tex) + float4(   0.0, 2.0*dy,     dx, 2.0*dy),
  69.         tex             + float2(2.0*dx, 2.0*dy)
  70.     };
  71.  
  72.  
  73.     return OUT;
  74. }
  75.  
  76.  
  77. float4 main_fragment(in out_vertex VAR, uniform sampler2D s_p : TEXUNIT0, uniform input IN) : COLOR
  78. {
  79.  
  80.   float2 fp = frac(VAR.texCoord*IN.texture_size);
  81.  
  82.   float3 c00 = tex2D(s_p, VAR.t1.xy).xyz;
  83.   float3 c01 = tex2D(s_p, VAR.t1.zw).xyz;
  84.   float3 c02 = tex2D(s_p, VAR.t2.xy).xyz;
  85.   float3 c03 = tex2D(s_p, VAR.t2.zw).xyz;
  86.   float3 c10 = tex2D(s_p, VAR.t3.xy).xyz;
  87.   float3 c11 = tex2D(s_p, VAR.texCoord).xyz;
  88.   float3 c12 = tex2D(s_p, VAR.t3.zw).xyz;
  89.   float3 c13 = tex2D(s_p, VAR.t4.xy).xyz;
  90.   float3 c20 = tex2D(s_p, VAR.t4.zw).xyz;
  91.   float3 c21 = tex2D(s_p, VAR.t5.xy).xyz;
  92.   float3 c22 = tex2D(s_p, VAR.t5.zw).xyz;
  93.   float3 c23 = tex2D(s_p, VAR.t6.xy).xyz;
  94.   float3 c30 = tex2D(s_p, VAR.t6.zw).xyz;
  95.   float3 c31 = tex2D(s_p, VAR.t7.xy).xyz;
  96.   float3 c32 = tex2D(s_p, VAR.t7.zw).xyz;
  97.   float3 c33 = tex2D(s_p, VAR.t8.xy).xyz;
  98.  
  99.  
  100.   float4x4   red_matrix = float4x4(c00.x, c01.x, c02.x, c03.x,
  101.                                    c10.x, c11.x, c12.x, c13.x,
  102.                                    c20.x, c21.x, c22.x, c23.x,
  103.                                    c30.x, c31.x, c32.x, c33.x);
  104.  
  105.   float4x4 green_matrix = float4x4(c00.y, c01.y, c02.y, c03.y,
  106.                                    c10.y, c11.y, c12.y, c13.y,
  107.                                    c20.y, c21.y, c22.y, c23.y,
  108.                                    c30.y, c31.y, c32.y, c33.y);
  109.  
  110.   float4x4  blue_matrix = float4x4(c00.z, c01.z, c02.z, c03.z,
  111.                                    c10.z, c11.z, c12.z, c13.z,
  112.                                    c20.z, c21.z, c22.z, c23.z,
  113.                                    c30.z, c31.z, c32.z, c33.z);
  114.  
  115.  
  116.   float4x1 invX_Px = mul(invX, float4x1(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0));
  117.   float1x4 Py_invY = mul(float1x4(fp.y*fp.y*fp.y, fp.y*fp.y, fp.y, 1.0), invY);
  118.  
  119.  
  120.   float red   = mul(Py_invY, mul(  red_matrix, invX_Px));
  121.   float green = mul(Py_invY, mul(green_matrix, invX_Px));
  122.   float blue  = mul(Py_invY, mul( blue_matrix, invX_Px));
  123.  
  124.   return float4(red, green, blue, 1.0);
  125. }