source: GTP/trunk/App/Demos/Illum/Ogre/Media/materials/GTPPostProc/GTPPostProc.hlsl @ 2024

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