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

Revision 1282, 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
36float4 BlackPS(VS_OUT IN):COLOR
37{
38        return float4(0,0,0,1);
39}
40
41float4 GlowCutPS(VS_OUT IN,
42                uniform float width,
43                uniform float height,
44                uniform float cutValue,
45                uniform float timeBlur,
46                uniform sampler2D Texture: register(s0)
47                ,uniform sampler2D LastTexture: register(s1)
48                 ):COLOR
49{       
50
51        IN.texCoord += float2(0.5/width, 0.5/height);
52        float4 sample = 2.0 * tex2D(Texture,IN.texCoord );
53        float luminance = dot(sample.rgb, float3(1.0, 4.5907, 0.0601));
54        if (luminance < cutValue) sample = float4(0,0,0,0);
55        float alpha = timeBlur;
56        sample = sample * alpha + tex2D(LastTexture, IN.texCoord) * (1.0 - alpha);
57       
58        return sample;
59        return sample;
60}
61
62half4 LuminancePS(VS_OUT IN,
63                uniform half width,
64                uniform half height,
65                uniform sampler2D Texture: register(s0)
66                ):COLOR
67{       
68
69        IN.texCoord += half2(0.5/width, 0.5/height);
70        half4 sample = tex2D(Texture,IN.texCoord );
71       
72        // D65 white conversion and weighting
73        half avg = sample.r * 0.21f + sample.g * 0.39f + sample.b * 0.4f;
74        return half4(avg, 0, 0, 1);
75}
76
77float4 GlowAddPS(VS_OUT IN,
78                uniform float width,
79                uniform float height,
80                uniform sampler2D Texture: register(s0),
81                uniform sampler2D GlowTexture: register(s1)
82                 ):COLOR
83{       
84        IN.texCoord += float2(0.5/width, 0.5/height);
85        /*float intens = length(tex2D(Texture,IN.texCoord ).rgb) / sqrt(3.0);
86        return float4(intens,intens,intens,1);*/
87        //return 1;
88        return tex2D(Texture,IN.texCoord ) + tex2D(GlowTexture,IN.texCoord );
89}
90
91float4 ToneMapPS(VS_OUT IN,
92                uniform half width,
93                uniform half height,
94                uniform half Gain,
95                uniform sampler2D Scene: register(s0),
96                uniform sampler2D AvrLuminanceTexture: register(s1),
97                uniform sampler2D LuminanceTexture: register(s2)
98                 ):COLOR
99{       
100        IN.texCoord += half2(0.5/width, 0.5/height);
101       
102        // Automatic key calculation
103        //half Key = 1.03f - 2.0f / (2.0f + log10(tex2D(AvrLuminanceTexture, IN.texCoord).r + 1.0f));   
104        half Key = 1 / (tex2D(AvrLuminanceTexture, IN.texCoord).r / 1 + tex2D(AvrLuminanceTexture, IN.texCoord).r);
105        //return 1 / Key;
106        // Relative luminance
107        half RelLum =  Key* tex2D(LuminanceTexture, IN.texCoord).r /
108                                                  tex2D(AvrLuminanceTexture, IN.texCoord).r;
109        half Lum = RelLum / (1 + RelLum);
110        // Color weghting
111        half4 Color = tex2D(Scene, IN.texCoord) * Lum;
112        // Gamma correction
113       
114        //Color = pow(Color * half4(1.05f, 0.97f, 1.27f, 1.0f), Gain);
115        return Color;
116
117}
118
119float4 GlowBlurHPS(VS_OUT IN,
120                uniform float Stretch,
121                uniform float width,
122                uniform float height,
123                uniform sampler2D Texture: register(s0)) : COLOR {
124        float2 tex0 = IN.texCoord + float2(0.5/width, 0.5/height);
125        float4 texLookUp_h;
126                       
127        /*texLookUp_h =  tex2D(Texture, float2(tex0.x-(3.86979f*Stretch/width), tex0.y)) +
128                                         tex2D(Texture, float2(tex0.x-(1.72291f*Stretch/width ), tex0.y)) +
129                                         tex2D(Texture, tex0) +
130                                         tex2D(Texture, float2(tex0.x+(1.72291f*Stretch/width), tex0.y)) +
131                                         tex2D(Texture, float2(tex0.x+(3.86979f*Stretch/width), tex0.y));*/
132       
133        texLookUp_h =    tex2D(Texture, float2(tex0.x-(2.0*Stretch/width), tex0.y)) +
134                                         tex2D(Texture, float2(tex0.x-(1.0*Stretch/width ), tex0.y)) +
135                                         tex2D(Texture, tex0) +
136                                         tex2D(Texture, float2(tex0.x+(1.0*Stretch/width), tex0.y)) +
137                                         tex2D(Texture, float2(tex0.x+(2.0*Stretch/width), tex0.y));
138
139        return texLookUp_h / 5.0 ;
140        //return texLookUp_h /5;
141}
142
143float4 GlowBlurVPS(VS_OUT IN,
144                uniform float Stretch,
145                uniform float width,
146                uniform float height,
147                uniform sampler2D Texture: register(s0)) : COLOR {
148        float2 tex0 = IN.texCoord + float2(0.5/width, 0.5/height);
149        float4 texLookUp_v;
150               
151        /*texLookUp_v =    tex2D(Texture, float2(tex0.x, tex0.y-(3.86979f*Stretch/height)))+
152                                         tex2D(Texture, float2(tex0.x, tex0.y-(1.72291f*Stretch/height)))+
153                                         tex2D(Texture, tex0)+
154                                         tex2D(Texture, float2(tex0.x, tex0.y+(1.72291f*Stretch/height)))+
155                                         tex2D(Texture, float2(tex0.x, tex0.y+(3.86979f*Stretch/height)));*/
156
157        texLookUp_v =    tex2D(Texture, float2(tex0.x, tex0.y-(2*Stretch/height)))+
158                                         tex2D(Texture, float2(tex0.x, tex0.y-(1*Stretch/height)))+
159                                         tex2D(Texture, tex0) +
160                                         tex2D(Texture, float2(tex0.x, tex0.y+(1*Stretch/height)))+
161                                         tex2D(Texture, float2(tex0.x, tex0.y+(2*Stretch/height)));
162       
163        return texLookUp_v / 5.0;
164}
165
166float4 CopyPS(VS_OUT IN,
167                uniform float width,
168                uniform float height,
169                uniform sampler2D Texture: register(s0)) : COLOR
170                {
171        IN.texCoord += float2(0.5/width, 0.5/height);
172        return tex2D(Texture,IN.texCoord );
173}
174
175
Note: See TracBrowser for help on using the repository browser.