source: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/programs/GameTools_PostProc.hlsl @ 777

Revision 777, 5.2 KB checked in by szirmay, 18 years ago (diff)
Line 
1struct VS_OUT
2{
3        float4 hPosition        : POSITION;
4        float2 texCoord         : TEXCOORD0;   
5};
6
7VS_OUT defaultVS(float4 position : POSITION,   
8                                float4 texCoord : TEXCOORD0)
9{
10        VS_OUT OUT;
11 
12        OUT.hPosition = float4(sign(position.xy),0,1);
13       
14        OUT.texCoord = (float2(OUT.hPosition.x,
15                                                        - OUT.hPosition.y) + 1.0) / 2.0;
16       
17   return OUT;
18}
19
20
21float4 defaultPS(VS_OUT IN,
22                uniform sampler2D Texture: register(s0)
23                 ):COLOR
24{       
25
26        /*float intens = length(tex2D(Texture,IN.texCoord ).rgb) / sqrt(3.0);
27        return float4(intens,intens,intens,1);*/
28       
29        float4 sample = tex2D(Texture,IN.texCoord );
30        if (sample.r + sample.g + sample.b < 1.7f) sample = float4(0,0,0,0);
31        return sample;
32       
33        //return tex2D(Texture,IN.texCoord ).b;
34}
35
36
37float4 GlowCutPS(VS_OUT IN,
38                uniform float width,
39                uniform float height,
40                uniform sampler2D Texture: register(s0)
41                ,uniform sampler2D LastTexture: register(s1)
42                 ):COLOR
43{       
44
45        /*float intens = length(tex2D(Texture,IN.texCoord ).rgb) / sqrt(3.0);
46        return float4(intens,intens,intens,1);*/
47        IN.texCoord += float2(0.5/width, 0.5/height);
48        float4 sample = tex2D(Texture,IN.texCoord );
49        float luminance = dot(sample.rgb, float3(1.0, 4.5907, 0.0601));
50        if (luminance < 5.0) sample = float4(0,0,0,0);
51        //if (sample.r + sample.g + sample.b < 1.7f) sample = float4(0,0,0,0);
52       
53        float alpha = 0.05;
54        sample = sample * alpha + tex2D(LastTexture, IN.texCoord) * (1.0 - alpha);
55       
56        return sample;
57}
58
59half4 LuminancePS(VS_OUT IN,
60                uniform half width,
61                uniform half height,
62                uniform sampler2D Texture: register(s0)
63                ):COLOR
64{       
65
66        IN.texCoord += half2(0.5/width, 0.5/height);
67        half4 sample = tex2D(Texture,IN.texCoord );
68       
69        // D65 white conversion and weighting
70        half avg = sample.r * 0.21f + sample.g * 0.39f + sample.b * 0.4f;
71        return half4(avg, 0, 0, 1);
72}
73
74float4 GlowAddPS(VS_OUT IN,
75                uniform float width,
76                uniform float height,
77                uniform sampler2D Texture: register(s0),
78                uniform sampler2D GlowTexture: register(s1)
79                 ):COLOR
80{       
81        IN.texCoord += float2(0.5/width, 0.5/height);
82        /*float intens = length(tex2D(Texture,IN.texCoord ).rgb) / sqrt(3.0);
83        return float4(intens,intens,intens,1);*/
84        //return 1;
85        return tex2D(Texture,IN.texCoord ) + tex2D(GlowTexture,IN.texCoord );
86}
87
88float4 ToneMapPS(VS_OUT IN,
89                uniform half width,
90                uniform half height,
91                uniform half Gain,
92                uniform sampler2D Scene: register(s0),
93                uniform sampler2D AvrLuminanceTexture: register(s1),
94                uniform sampler2D LuminanceTexture: register(s2)
95                 ):COLOR
96{       
97        IN.texCoord += half2(0.5/width, 0.5/height);
98       
99        // Automatic key calculation
100        //half Key = 1.03f - 2.0f / (2.0f + log10(tex2D(AvrLuminanceTexture, IN.texCoord).r + 1.0f));   
101        half Key = 1 / (tex2D(AvrLuminanceTexture, IN.texCoord).r / 1 + tex2D(AvrLuminanceTexture, IN.texCoord).r);
102        //return 1 / Key;
103        // Relative luminance
104        half RelLum =  Key* tex2D(LuminanceTexture, IN.texCoord).r /
105                                                  tex2D(AvrLuminanceTexture, IN.texCoord).r;
106        half Lum = RelLum / (1 + RelLum);
107        // Color weghting
108        half4 Color = tex2D(Scene, IN.texCoord) * Lum;
109        // Gamma correction
110       
111        //Color = pow(Color * half4(1.05f, 0.97f, 1.27f, 1.0f), Gain);
112        return Color;
113
114}
115
116float4 GlowBlurHPS(VS_OUT IN,
117                uniform float Stretch,
118                uniform float width,
119                uniform float height,
120                uniform sampler2D Texture: register(s0)) : COLOR {
121        float2 tex0 = IN.texCoord + float2(0.5/width, 0.5/height);
122        float4 texLookUp_h;
123                       
124        /*texLookUp_h =  tex2D(Texture, float2(tex0.x-(3.86979f*Stretch/width), tex0.y)) +
125                                         tex2D(Texture, float2(tex0.x-(1.72291f*Stretch/width ), tex0.y)) +
126                                         tex2D(Texture, tex0) +
127                                         tex2D(Texture, float2(tex0.x+(1.72291f*Stretch/width), tex0.y)) +
128                                         tex2D(Texture, float2(tex0.x+(3.86979f*Stretch/width), tex0.y));*/
129       
130        texLookUp_h =    tex2D(Texture, float2(tex0.x-(2.0*Stretch/width), tex0.y)) +
131                                         tex2D(Texture, float2(tex0.x-(1.0*Stretch/width ), tex0.y)) +
132                                         tex2D(Texture, tex0) +
133                                         tex2D(Texture, float2(tex0.x+(1.0*Stretch/width), tex0.y)) +
134                                         tex2D(Texture, float2(tex0.x+(2.0*Stretch/width), tex0.y));
135
136        return texLookUp_h / 5.0 ;
137        //return texLookUp_h /5;
138}
139
140float4 GlowBlurVPS(VS_OUT IN,
141                uniform float Stretch,
142                uniform float width,
143                uniform float height,
144                uniform sampler2D Texture: register(s0)) : COLOR {
145        float2 tex0 = IN.texCoord + float2(0.5/width, 0.5/height);
146        float4 texLookUp_v;
147               
148        /*texLookUp_v =    tex2D(Texture, float2(tex0.x, tex0.y-(3.86979f*Stretch/height)))+
149                                         tex2D(Texture, float2(tex0.x, tex0.y-(1.72291f*Stretch/height)))+
150                                         tex2D(Texture, tex0)+
151                                         tex2D(Texture, float2(tex0.x, tex0.y+(1.72291f*Stretch/height)))+
152                                         tex2D(Texture, float2(tex0.x, tex0.y+(3.86979f*Stretch/height)));*/
153
154        texLookUp_v =    tex2D(Texture, float2(tex0.x, tex0.y-(2*Stretch/height)))+
155                                         tex2D(Texture, float2(tex0.x, tex0.y-(1*Stretch/height)))+
156                                         tex2D(Texture, tex0) +
157                                         tex2D(Texture, float2(tex0.x, tex0.y+(1*Stretch/height)))+
158                                         tex2D(Texture, float2(tex0.x, tex0.y+(2*Stretch/height)));
159       
160        return texLookUp_v / 5.0;
161}
162
163float4 CopyPS(VS_OUT IN,
164                uniform float width,
165                uniform float height,
166                uniform sampler2D Texture: register(s0)) : COLOR
167                {
168        IN.texCoord += float2(0.5/width, 0.5/height);
169        return tex2D(Texture,IN.texCoord );
170}
171
172
Note: See TracBrowser for help on using the repository browser.