source: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_Blur.hlsl @ 2138

Revision 2138, 2.3 KB checked in by szirmay, 17 years ago (diff)
Line 
1#define samplesU 7
2#define samplesV 7
3
4struct VS_INPUT {           
5    float4 Position : POSITION;
6};
7
8struct VS_OUTPUT {         
9    float4 hPosition : POSITION;
10    float2 Position  : TEXCOORD0;
11};
12
13VS_OUTPUT BlurVS(VS_INPUT IN) {
14        VS_OUTPUT OUT;
15    OUT.hPosition = IN.Position;
16    OUT.Position =(IN.Position.xy + 1.0) / 2.0;
17    OUT.Position.y = 1.0 - OUT.Position.y;
18    return OUT;
19}
20
21float4 BlurPS(VS_OUTPUT IN,
22                        uniform sampler2D Texture : register(s0),
23                        uniform float width,
24                        uniform float height ) : COLOR
25
26
27  float2 pixel = float2(1.0 / width, 1.0 / height);
28  float2 uv = IN.Position + pixel * 0.5;
29
30  float4 sum = float4(0,0,0,0);
31
32        for(int i = 0; i < samplesU; i++)
33         for(int j = 0; j < samplesU; j++)
34                sum += tex2D(Texture, uv + float2(i - samplesU * 0.5,j - samplesV * 0.5) * pixel);
35
36  sum /= samplesU * samplesV;
37
38  return sum;
39  return tex2D(Texture, uv);
40}
41
42float4 CopyPS(VS_OUTPUT IN,
43                        uniform sampler2D Texture : register(s0),
44                        uniform float alpha,
45                        uniform float width,
46                        uniform float height ) : COLOR
47
48  float2 pixel = float2(1.0 / width, 1.0 / height);
49  float2 uv = IN.Position + pixel * 0.5;
50
51  float4 Color = tex2D(Texture, uv);
52  Color.a = alpha; 
53 // Color = float4(0,0,0,1);
54  return Color;
55}
56
57VS_OUTPUT BlurCubeFaceVS(VS_INPUT IN) {
58        VS_OUTPUT OUT;
59    OUT.hPosition = IN.Position;   
60    OUT.Position = OUT.hPosition;
61    return OUT;
62}
63
64float4 BlurCubeFacePS(VS_OUTPUT IN,
65                        uniform samplerCUBE Texture : register(s0),
66                        uniform float width,
67                        uniform float height,
68                        uniform float face ) : COLOR
69
70
71  float2 pixel = float2(2.0 / width, 2.0 / height);
72  float2 uv = IN.Position + pixel * 0.5;
73
74  float4 sum = float4(0,0,0,0);
75
76        for(int i = 0; i < samplesU; i++)
77         for(int j = 0; j < samplesV; j++)
78         {
79                float3 dir;
80                float2 pos = uv + float2(i - samplesU * 0.5,j - samplesV * 0.5) * pixel;
81                if (face == 0) dir = float3(1, pos.y, -pos.x);
82                if (face == 1) dir = float3(-1, pos.y, pos.x);
83                if (face == 2) dir = float3(pos.x, 1, -pos.y);
84                if (face == 3) dir = float3(pos.x, -1, pos.y);
85                if (face == 4) dir = float3(pos.x, pos.y, 1);
86                if (face == 5) dir = float3(-pos.x, pos.y,-1);
87               
88                sum += texCUBE(Texture, dir);
89         }
90               
91
92  sum /= samplesU * samplesV;
93
94  return sum;
95  //return texCUBE(Texture, float3(uv, 1)) + face * 0.0000001;
96}
Note: See TracBrowser for help on using the repository browser.