Merge pull request #4735 from cg110/fix_web_server_mem_leak
[vuplus_xbmc] / system / shaders / convolutionsep-4x4_d3d.fx
1 /*
2  *      Copyright (C) 2005-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 texture g_IntermediateTexture;
24 float2  g_StepXY_P0;
25 float2  g_StepXY_P1;
26
27 sampler RGBSampler =
28   sampler_state {
29     Texture = <g_Texture>;
30     AddressU = CLAMP;
31     AddressV = CLAMP;
32     MipFilter = LINEAR;
33     MinFilter = POINT;
34     MagFilter = POINT;
35   };
36
37 sampler KernelSampler =
38   sampler_state
39   {
40     Texture = <g_KernelTexture>;
41     AddressU = CLAMP;
42     AddressV = CLAMP;
43     MipFilter = LINEAR;
44     MinFilter = LINEAR;
45     MagFilter = LINEAR;
46   };
47
48 sampler IntermediateSampler =
49   sampler_state {
50     Texture = <g_IntermediateTexture>;
51     AddressU = CLAMP;
52     AddressV = CLAMP;
53     MipFilter = LINEAR;
54     MinFilter = POINT;
55     MagFilter = POINT;
56   };
57
58 struct VS_OUTPUT
59 {
60   float4 Position   : POSITION;
61   float2 TextureUV  : TEXCOORD0;
62 };
63
64 struct PS_OUTPUT
65 {
66   float4 RGBColor : COLOR0;
67 };
68
69 half4 weight(float pos)
70 {
71   half4 w;
72 #ifdef HAS_RGBA
73   w = tex1D(KernelSampler, pos);
74 #else
75   w = tex1D(KernelSampler, pos).bgra;
76 #endif
77
78 #ifdef HAS_FLOAT_TEXTURE
79   return w;
80 #else
81   return w * 2.0 - 1.0;
82 #endif
83 }
84
85 half3 pixel(sampler samp, float xpos, float ypos)
86 {
87   return tex2D(samp, float2(xpos, ypos)).rgb;
88 }
89
90 // Code for first pass - horizontal
91
92 half3 getLine(float ypos, float4 xpos, half4 linetaps)
93 {
94   return
95     pixel(RGBSampler, xpos.r, ypos) * linetaps.r +
96     pixel(RGBSampler, xpos.g, ypos) * linetaps.g +
97     pixel(RGBSampler, xpos.b, ypos) * linetaps.b +
98     pixel(RGBSampler, xpos.a, ypos) * linetaps.a;
99 }
100
101 PS_OUTPUT CONVOLUTION4x4Horiz(VS_OUTPUT In)
102 {
103   PS_OUTPUT OUT;
104
105   float2 pos = In.TextureUV + g_StepXY_P0 * 0.5;
106   float2 f = frac(pos / g_StepXY_P0);
107
108   half4 linetaps = weight(1.0 - f.x);
109
110   // kernel generation code made sure taps add up to 1, no need to adjust here.
111
112   float2 xystart;
113   xystart.x = (-1.0 - f.x) * g_StepXY_P0.x + In.TextureUV.x;
114   xystart.y = In.TextureUV.y;
115
116   float4 xpos = float4(
117       xystart.x,
118       xystart.x + g_StepXY_P0.x,
119       xystart.x + g_StepXY_P0.x * 2.0,
120       xystart.x + g_StepXY_P0.x * 3.0);
121
122   OUT.RGBColor.rgb = getLine(xystart.y, xpos, linetaps);
123   OUT.RGBColor.a = 1.0;
124
125   return OUT;
126 }
127
128 // Code for second pass - vertical
129
130 half3 getRow(float xpos, float4 ypos, half4 columntaps)
131 {
132   return
133     pixel(IntermediateSampler, xpos, ypos.r) * columntaps.r +
134     pixel(IntermediateSampler, xpos, ypos.g) * columntaps.g +
135     pixel(IntermediateSampler, xpos, ypos.b) * columntaps.b +
136     pixel(IntermediateSampler, xpos, ypos.a) * columntaps.a;
137 }
138
139 PS_OUTPUT CONVOLUTION4x4Vert(VS_OUTPUT In)
140 {
141   PS_OUTPUT OUT;
142
143   float2 pos = In.TextureUV + g_StepXY_P1 * 0.5;
144   float2 f = frac(pos / g_StepXY_P1);
145
146   half4 columntaps = weight(1.0 - f.y);
147
148   // kernel generation code made sure taps add up to 1, no need to adjust here.
149
150   float2 xystart;
151   xystart.x = In.TextureUV.x;
152   xystart.y = (-1.0 - f.y) * g_StepXY_P1.y + In.TextureUV.y;
153
154   float4 ypos = float4(
155       xystart.y,
156       xystart.y + g_StepXY_P1.y,
157       xystart.y + g_StepXY_P1.y * 2.0,
158       xystart.y + g_StepXY_P1.y * 3.0);
159
160   OUT.RGBColor.rgb = getRow(xystart.x, ypos, columntaps);
161   OUT.RGBColor.a = 1.0;
162
163   return OUT;
164 }
165
166 technique SCALER_T
167 {
168   pass P0
169   {
170     PixelShader  = compile ps_3_0 CONVOLUTION4x4Horiz();
171     ZEnable = False;
172     FillMode = Solid;
173     FogEnable = False;
174   }
175   pass P1
176   {
177     PixelShader  = compile ps_3_0 CONVOLUTION4x4Vert();
178     ZEnable = False;
179     FillMode = Solid;
180     FogEnable = False;
181   }
182
183 };