source: GTP/trunk/App/Demos/Illum/Standalone/Glow [DirectX]/Cube.fx @ 846

Revision 846, 4.7 KB checked in by szirmay, 18 years ago (diff)
Line 
1//Vertex Shader input
2struct VS_INPUT
3{
4        float4 pos : POSITION;
5        float2 tex0 : TEXCOORD0;
6};
7
8//Vertex Shader output
9struct VS_OUTPUT
10{
11        float4 pos : POSITION;
12        float2 tex0 : TEXCOORD0;
13};
14
15// Texture samplers
16texture Original;
17sampler2D OriginalSampler = sampler_state
18{
19        texture = <Original>;
20        mipfilter = LINEAR;
21        minfilter = LINEAR;
22        magfilter = LINEAR;
23        AddressU = Wrap;
24        AddressV = Wrap;
25};
26
27texture Glow;
28sampler2D GlowSampler = sampler_state
29{
30        texture = <Glow>;
31        mipfilter = LINEAR;
32        minfilter = LINEAR;
33        magfilter = LINEAR;
34        AddressU = Wrap;
35        AddressV = Wrap;
36};
37
38texture OldGlow;
39sampler2D OldGlowSampler = sampler_state
40{
41        texture = <OldGlow>;
42        mipfilter = LINEAR;
43        minfilter = LINEAR;
44        magfilter = LINEAR;
45        AddressU = Wrap;
46        AddressV = Wrap;
47};
48
49texture SourceTexture;
50sampler2D SourceTextureSampler = sampler_state
51{
52        texture = <SourceTexture>;
53        mipfilter = LINEAR;
54        AddressU = Clamp;
55        AddressV = Clamp;
56};
57
58//Uniform parameters.
59uniform float4x4 modelViewProjection;
60
61// Width and height of the viewport
62uniform float dsWidth, dsHeight;
63// Number of glow passes and the gain
64uniform float GlowPasses, GlowGain;
65// Blur sample strecth
66uniform float Stretch;
67
68// Simple vertex shader with MVP
69VS_OUTPUT VS_myVertexShader(in VS_INPUT input){
70        VS_OUTPUT output0;
71        output0.pos = mul(input.pos,modelViewProjection);
72        output0.tex0 = input.tex0;
73        return output0;
74}
75
76// Vertex shader for the full screen triangle rendering
77VS_OUTPUT VS_myVertexBlurShader(in VS_INPUT input){
78        VS_OUTPUT output0;
79        output0.pos = mul(input.pos,modelViewProjection);
80        output0.tex0 = input.tex0 + 0.5*float2(1.0f/dsWidth, 1.0f/dsHeight);
81        return output0;
82}
83
84// Simple texturing shader
85half4 PS_Cube(in float2 tex0:TEXCOORD0) : COLOR {
86        half4 texLookUp;
87        texLookUp.rgba = tex2D(SourceTextureSampler,tex0).rgba;
88        return texLookUp;
89}
90
91// Glow cutting shader
92// Based on the alpha value of the texture
93half4 PS_CubeGlow(in float2 tex0:TEXCOORD0) : COLOR {
94        half4 texLookUp;
95        texLookUp.rgba = tex2D(SourceTextureSampler,tex0).rgba;
96        if (texLookUp.a > 0.6f) texLookUp = half4(0,0,0,0);
97        return texLookUp;
98}
99
100// Final compositing shader
101// Original + Glow -> Final image
102half4 PS_Final(in float2 tex0:TEXCOORD0) : COLOR {
103        half4 Orig;
104        Orig.rgba = tex2D(OriginalSampler,tex0).rgba;
105
106        half4 Glow;
107        Glow.rgba = tex2D(GlowSampler,tex0).rgba;
108       
109        return Orig + Glow;
110}
111
112// Horizontal blur with addition from the blur history
113// Separated Gaussian blur
114half4 PS_Blur_h(in float2 tex0:TEXCOORD0) : COLOR {
115        half4 texLookUp_h;
116                       
117        texLookUp_h =    tex2D(GlowSampler, float2(tex0.x-(3.86979f*Stretch/dsWidth / 2), tex0.y)) +
118                                         tex2D(GlowSampler, float2(tex0.x-(1.72291f*Stretch/dsWidth / 2), tex0.y)) +
119                                         tex2D(GlowSampler, tex0) +
120                                         tex2D(GlowSampler, float2(tex0.x+(1.72291f*Stretch/dsWidth / 2), tex0.y)) +
121                                         tex2D(GlowSampler, float2(tex0.x+(3.86979f*Stretch/dsWidth / 2), tex0.y));
122
123        half4 oldGlow = tex2D(OldGlowSampler, tex0);
124        return texLookUp_h / 5 + oldGlow * GlowGain;
125}
126
127// Vertical blur with addition from the blur history
128// Separated Gaussian blur
129half4 PS_Blur_v(in float2 tex0:TEXCOORD0) : COLOR {
130        half4 texLookUp_v;
131               
132        texLookUp_v =    tex2D(GlowSampler, float2(tex0.x, tex0.y-(3.86979f*Stretch/dsHeight / 2)))+
133                                         tex2D(GlowSampler, float2(tex0.x, tex0.y-(1.72291f*Stretch/dsHeight / 2)))+
134                                         tex2D(GlowSampler, tex0)+
135                                         tex2D(GlowSampler, float2(tex0.x, tex0.y+(1.72291f*Stretch/dsHeight / 2)))+
136                                         tex2D(GlowSampler, float2(tex0.x, tex0.y+(3.86979f*Stretch/dsHeight / 2)));
137
138        half4 oldGlow = tex2D(OldGlowSampler, tex0);
139        return texLookUp_v / 5 + oldGlow * GlowGain;
140}
141
142// Original dice
143technique Cube
144{
145    pass P0{
146        // compiler directives
147        VertexShader = compile vs_2_0 VS_myVertexShader();
148        PixelShader  = compile ps_2_0 PS_Cube();
149    }
150}
151
152// Glow cut
153technique CubeGlow
154{
155    pass P0{
156        // compiler directives
157        VertexShader = compile vs_2_0 VS_myVertexShader();
158        PixelShader  = compile ps_2_0 PS_CubeGlow();
159    }
160}
161
162// Horizontal blur
163technique Blur_h
164{
165    pass P0{
166        // compiler directives
167        VertexShader = compile vs_2_0 VS_myVertexBlurShader();
168        PixelShader  = compile ps_2_0 PS_Blur_h();
169    }
170}
171
172// Vertical blur
173technique Blur_v
174{
175    pass P0{
176        // compiler directives
177        VertexShader = compile vs_2_0 VS_myVertexBlurShader();
178        PixelShader  = compile ps_2_0 PS_Blur_v();
179    }
180}
181
182// Final compositing
183technique Final
184{
185    pass P0{
186        // compiler directives
187        VertexShader = compile vs_2_0 VS_myVertexShader();
188        PixelShader  = compile ps_2_0 PS_Final();
189    }
190}
Note: See TracBrowser for help on using the repository browser.