Merge pull request #4735 from cg110/fix_web_server_mem_leak
[vuplus_xbmc] / system / shaders / convolution-6x6_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 half3 weight(float pos)
56 {
57   half3 w;
58 #ifdef HAS_RGBA
59   w = tex1D(KernelSampler, pos).rgb;
60 #else
61   w = tex1D(KernelSampler, pos).bgr;
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, float3 xpos1, float3 xpos2, half3 linetaps1, half3 linetaps2)
77 {
78   return
79     pixel(xpos1.r, ypos) * linetaps1.r +
80     pixel(xpos1.g, ypos) * linetaps2.r +
81     pixel(xpos1.b, ypos) * linetaps1.g +
82     pixel(xpos2.r, ypos) * linetaps2.g +
83     pixel(xpos2.g, ypos) * linetaps1.b +
84     pixel(xpos2.b, ypos) * linetaps2.b;
85 }
86
87 PS_OUTPUT CONVOLUTION6x6(VS_OUTPUT In)
88 {
89   PS_OUTPUT OUT;
90
91   float2 pos = In.TextureUV + g_StepXY * 0.5;
92   float2 f = frac(pos / g_StepXY);
93
94   half3 linetaps1   = weight((1.0 - f.x) / 2.0);
95   half3 linetaps2   = weight((1.0 - f.x) / 2.0 + 0.5);
96   half3 columntaps1 = weight((1.0 - f.y) / 2.0);
97   half3 columntaps2 = weight((1.0 - f.y) / 2.0 + 0.5);
98
99   // kernel generation code made sure taps add up to 1, no need to adjust here.
100
101   float2 xystart = (-2.0 - f) * g_StepXY + In.TextureUV;
102   float3 xpos1 = float3(
103       xystart.x,
104       xystart.x + g_StepXY.x,
105       xystart.x + g_StepXY.x * 2.0);
106   float3 xpos2 = half3(
107       xystart.x + g_StepXY.x * 3.0,
108       xystart.x + g_StepXY.x * 4.0,
109       xystart.x + g_StepXY.x * 5.0);
110
111   OUT.RGBColor.rgb = getLine(xystart.y                   , xpos1, xpos2, linetaps1, linetaps2) * columntaps1.r +
112                                          getLine(xystart.y + g_StepXY.y      , xpos1, xpos2, linetaps1, linetaps2) * columntaps2.r +
113                                          getLine(xystart.y + g_StepXY.y * 2.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.g +
114                                          getLine(xystart.y + g_StepXY.y * 3.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.g +
115                                          getLine(xystart.y + g_StepXY.y * 4.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps1.b +
116                                          getLine(xystart.y + g_StepXY.y * 5.0, xpos1, xpos2, linetaps1, linetaps2) * columntaps2.b;
117
118   OUT.RGBColor.a = 1.0;
119   return OUT;
120 }
121
122 technique SCALER_T
123 {
124   pass P0
125   {
126     PixelShader  = compile ps_3_0 CONVOLUTION6x6();
127     ZEnable = False;
128     FillMode = Solid;
129     FogEnable = False;
130   }
131 };