1 | //------------------------------------
|
---|
2 | float alpha;
|
---|
3 | texture sceneRendering;
|
---|
4 | texture objTexture;
|
---|
5 | texture Bump; //NormalMap
|
---|
6 | float4x4 g_mWorldViewProjection; // World View Projection Matrix
|
---|
7 | float4x4 g_mWorldViewIT;
|
---|
8 | float4x4 g_mRot;
|
---|
9 | float4 lightDir; //LightDirection
|
---|
10 | //float4 eyeDir; //EyeDirection
|
---|
11 | float halfVector;
|
---|
12 | //float4 sceneAmbient;
|
---|
13 | float4 ambient;
|
---|
14 | float4 diffuse;
|
---|
15 | float4 specular;
|
---|
16 | float power;
|
---|
17 |
|
---|
18 | //------------------------------------
|
---|
19 | struct vertexInput {
|
---|
20 | float3 position : POSITION;
|
---|
21 | float4 texCoord : TEXCOORD0;
|
---|
22 | };
|
---|
23 |
|
---|
24 | struct vertexOutput {
|
---|
25 | float4 HPosition : POSITION;
|
---|
26 | float4 ColorTextureCoord : TEXCOORD0;
|
---|
27 | };
|
---|
28 |
|
---|
29 | struct vertexObjInput {
|
---|
30 | float3 position : POSITION;
|
---|
31 | float4 texCoord : TEXCOORD0;
|
---|
32 | float3 normal : NORMAL;
|
---|
33 | };
|
---|
34 |
|
---|
35 | struct vertexObjInputNM {
|
---|
36 | float3 position : POSITION;
|
---|
37 | float4 texCoord : TEXCOORD0;
|
---|
38 | };
|
---|
39 |
|
---|
40 | struct vertexObjOutput {
|
---|
41 | float4 HPosition : POSITION;
|
---|
42 | float4 ColorTextureCoord : TEXCOORD0;
|
---|
43 | float3 normal : NORMAL;
|
---|
44 | };
|
---|
45 |
|
---|
46 | struct vertexObjOutputNM {
|
---|
47 | float4 HPosition : POSITION;
|
---|
48 | float4 ColorTextureCoord : TEXCOORD0;
|
---|
49 | };
|
---|
50 |
|
---|
51 | struct pixelOutput
|
---|
52 | {
|
---|
53 | float4 color : COLOR;
|
---|
54 | };
|
---|
55 |
|
---|
56 | //------------------------------------
|
---|
57 | #define SAMPLER_LINEAR(g_samplerMap, g_txMap); \
|
---|
58 | sampler2D g_samplerMap = sampler_state { \
|
---|
59 | Texture = <g_txMap>; \
|
---|
60 | MinFilter = Linear; \
|
---|
61 | MagFilter = Linear; \
|
---|
62 | MipFilter = Linear; \
|
---|
63 | AddressU = BORDER; \
|
---|
64 | AddressV = BORDER; \
|
---|
65 | };
|
---|
66 |
|
---|
67 | #define SAMPLER_POINT(g_samplerMap, g_txMap); \
|
---|
68 | sampler2D g_samplerMap = sampler_state { \
|
---|
69 | Texture = <g_txMap>; \
|
---|
70 | MinFilter = Point; \
|
---|
71 | MagFilter = Point; \
|
---|
72 | MipFilter = Point; \
|
---|
73 | AddressU = BORDER; \
|
---|
74 | AddressV = BORDER; \
|
---|
75 | };
|
---|
76 |
|
---|
77 | SAMPLER_POINT(samplerSceneRendering, sceneRendering);
|
---|
78 | SAMPLER_LINEAR(samplerTexture, objTexture);
|
---|
79 | SAMPLER_LINEAR(samplerBump, Bump);
|
---|
80 |
|
---|
81 | //------------------------------------
|
---|
82 | vertexOutput fadeVS(vertexInput IN)
|
---|
83 | {
|
---|
84 | vertexOutput OUT;
|
---|
85 |
|
---|
86 | OUT.HPosition = float4(IN.position,1);
|
---|
87 | OUT.ColorTextureCoord = IN.texCoord;
|
---|
88 |
|
---|
89 | return OUT;
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | //------------------------------------
|
---|
94 | pixelOutput fadePS(vertexOutput IN)
|
---|
95 | {
|
---|
96 | pixelOutput OUT;
|
---|
97 | float4 retColor = tex2D(samplerSceneRendering, IN.ColorTextureCoord.xy);
|
---|
98 | retColor.a = alpha;
|
---|
99 | OUT.color = retColor;
|
---|
100 |
|
---|
101 | return OUT;
|
---|
102 | }
|
---|
103 |
|
---|
104 | //------------------------------------
|
---|
105 | vertexObjOutput fadeObjectVS(vertexObjInput IN)
|
---|
106 | {
|
---|
107 | vertexObjOutput OUT;
|
---|
108 |
|
---|
109 | OUT.HPosition = mul(float4(IN.position,1), g_mWorldViewProjection);
|
---|
110 | OUT.ColorTextureCoord = IN.texCoord;
|
---|
111 |
|
---|
112 | OUT.normal = IN.normal;//normalize
|
---|
113 | OUT.normal = mul(g_mWorldViewIT, float4(IN.normal,1)).xyz;
|
---|
114 | //OUT.LightDir.xyz = mul(g_mWorldViewIT,lightDir);
|
---|
115 | //OUT.LightDir.w = 1;
|
---|
116 |
|
---|
117 | return OUT;
|
---|
118 | }
|
---|
119 |
|
---|
120 | //------------------------------------
|
---|
121 | vertexObjOutputNM fadeObjectNMVS(vertexObjInputNM IN)
|
---|
122 | {
|
---|
123 | vertexObjOutputNM OUT;
|
---|
124 |
|
---|
125 | OUT.HPosition = mul(float4(IN.position,1), g_mWorldViewProjection);
|
---|
126 | OUT.ColorTextureCoord = IN.texCoord;
|
---|
127 |
|
---|
128 | // Transform to tangent space and output
|
---|
129 | // half vector and light direction
|
---|
130 | //float3x3 TangentSpace;
|
---|
131 | //TangentSpace[0] = IN.inTangent;
|
---|
132 | //TangentSpace[1] = IN.inBinormal;
|
---|
133 | //TangentSpace[2] = IN.normal;
|
---|
134 | //OUT.HalfVect = 0;//mul(TangentSpace,normalize(lightDir.xyz+eyeDir));
|
---|
135 | //Out.LightDir = float4(mul(TangentSpace,LightDir.xyz),LightDir.w);
|
---|
136 |
|
---|
137 | return OUT;
|
---|
138 | }
|
---|
139 |
|
---|
140 | //------------------------------------
|
---|
141 | pixelOutput fadeObjectPS(vertexObjOutput IN)
|
---|
142 | {
|
---|
143 | pixelOutput OUT;
|
---|
144 | float3 normal = normalize(IN.normal);
|
---|
145 | float4 retColor = tex2D(samplerTexture, IN.ColorTextureCoord.xy);
|
---|
146 |
|
---|
147 | //Specular
|
---|
148 | float3 specI = specular*pow( clamp(0, 1, dot(normal, halfVector)), power);
|
---|
149 |
|
---|
150 | //Diffuse
|
---|
151 | float3 diffI = diffuse*clamp(0,1,dot(normal, lightDir));
|
---|
152 |
|
---|
153 | //Ambient = ambient
|
---|
154 | retColor.rgb = retColor.rgb*(diffI + specI + ambient.xyz);
|
---|
155 | retColor.a *= alpha;
|
---|
156 |
|
---|
157 | //Do Lightning Stuff
|
---|
158 | OUT.color = retColor;
|
---|
159 |
|
---|
160 | //OUT.color = retColor;
|
---|
161 |
|
---|
162 | return OUT;
|
---|
163 | }
|
---|
164 |
|
---|
165 | pixelOutput fadeObjectNMPS(vertexObjOutputNM IN)
|
---|
166 | {
|
---|
167 | pixelOutput OUT;
|
---|
168 | float3 normal = tex2D(samplerBump,IN.ColorTextureCoord) * 2 - 1;
|
---|
169 |
|
---|
170 | float4 retColor = tex2D(samplerTexture, IN.ColorTextureCoord.xy);
|
---|
171 |
|
---|
172 | //Specular
|
---|
173 | float3 specI = specular*pow( clamp(0, 1, dot(normal, halfVector)), power);
|
---|
174 |
|
---|
175 | //Diffuse
|
---|
176 | float3 diffI = diffuse*clamp(0,1,dot(normal, lightDir));
|
---|
177 |
|
---|
178 | //Ambient = ambient
|
---|
179 | retColor.rgb = retColor.rgb*(diffI + specI + ambient.xyz);
|
---|
180 | retColor.a *= alpha;
|
---|
181 |
|
---|
182 | //Do Lightning Stuff
|
---|
183 | OUT.color = retColor;
|
---|
184 |
|
---|
185 | //OUT.color = retColor;
|
---|
186 |
|
---|
187 | return OUT;
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | //
|
---|
192 | // Effect
|
---|
193 | //
|
---|
194 |
|
---|
195 | #define Technique(name); \
|
---|
196 | technique name \
|
---|
197 | { \
|
---|
198 | pass p0 \
|
---|
199 | { \
|
---|
200 | VertexShader = compile vs_3_0 name##VS(); \
|
---|
201 | PixelShader = compile ps_3_0 name##PS(); \
|
---|
202 | } \
|
---|
203 | }
|
---|
204 |
|
---|
205 | Technique( fade );
|
---|
206 | Technique( fadeObject );
|
---|
207 | Technique( fadeObjectNM ); |
---|