Merge pull request #4357 from koying/fixfilemgrdoubleclick
[vuplus_xbmc] / system / shaders / convolution-4x4_d3d.fx
1 /*
2  *      Copyright (C) 2005-2010-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 texture g_Texture;
22 texture g_KernelTexture;
23 float2  g_StepXY;
24
25 sampler RGBSampler =
26   sampler_state {
27     Texture = <g_Texture>;
28     AddressU = CLAMP;
29     AddressV = CLAMP;
30     MinFilter = POINT;
31     MagFilter = POINT;
32   };
33
34 sampler KernelSampler =
35   sampler_state
36   {
37     Texture = <g_KernelTexture>;
38     AddressU = CLAMP;
39     AddressV = CLAMP;
40     MinFilter = LINEAR;
41     MagFilter = LINEAR;
42   };
43
44 struct VS_OUTPUT
45 {
46   float4 Position   : POSITION;
47   float2 TextureUV  : TEXCOORD0;
48 };
49
50 struct PS_OUTPUT
51 {
52   float4 RGBColor : COLOR0;
53 };
54
55 half4 weight(float pos)
56 {
57   half4 w;
58 #ifdef HAS_RGBA
59   w = tex1D(KernelSampler, pos);
60 #else
61   w = tex1D(KernelSampler, pos).bgra;
62 #endif
63
64 #ifdef HAS_FLOAT_TEXTURE
65   return w;
66 #else
67   return w * 2.0 - 1.0;
68 #endif
69 }
70
71 half3 pixel(float xpos, float ypos)
72 {
73   return tex2D(RGBSampler, float2(xpos, ypos)).rgb;
74 }
75
76 half3 getLine(float ypos, float4 xpos, half4 linetaps)
77 {
78   return
79     pixel(xpos.r, ypos) * linetaps.r +
80     pixel(xpos.g, ypos) * linetaps.g +
81     pixel(xpos.b, ypos) * linetaps.b +
82     pixel(xpos.a, ypos) * linetaps.a;
83 }
84
85 PS_OUTPUT CONVOLUTION4x4(VS_OUTPUT In)
86 {
87   PS_OUTPUT OUT;
88
89   float2 pos = In.TextureUV + g_StepXY * 0.5;
90   float2 f = frac(pos / g_StepXY);
91
92   half4 linetaps   = weight(1.0 - f.x);
93   half4 columntaps = weight(1.0 - f.y);
94
95   // kernel generation code made sure taps add up to 1, no need to adjust here.
96
97   float2 xystart = (-1.0 - f) * g_StepXY + In.TextureUV;
98   float4 xpos = float4(
99       xystart.x,
100       xystart.x + g_StepXY.x,
101       xystart.x + g_StepXY.x * 2.0,
102       xystart.x + g_StepXY.x * 3.0);
103
104   OUT.RGBColor.rgb =
105     getLine(xystart.y                   , xpos, linetaps) * columntaps.r +
106     getLine(xystart.y + g_StepXY.y      , xpos, linetaps) * columntaps.g +
107     getLine(xystart.y + g_StepXY.y * 2.0, xpos, linetaps) * columntaps.b +
108     getLine(xystart.y + g_StepXY.y * 3.0, xpos, linetaps) * columntaps.a;
109
110   OUT.RGBColor.a = 1.0;
111   return OUT;
112 }
113
114 technique SCALER_T
115 {
116   pass P0
117   {
118     PixelShader  = compile ps_3_0 CONVOLUTION4x4();
119     ZEnable = False;
120     FillMode = Solid;
121     FogEnable = False;
122   }
123 };