1 | // This is used by 3dsmax to load the correct parser
|
---|
2 | string ParamID = "0x0";
|
---|
3 |
|
---|
4 | //DxMaterial specific
|
---|
5 |
|
---|
6 | // light direction (view space)
|
---|
7 | float3 g_LightDir : Direction <
|
---|
8 | string UIName = "Light";
|
---|
9 | string Object = "TargetLight";
|
---|
10 | int refID = 0;
|
---|
11 | > = {-0.577, -0.577, 0.577};
|
---|
12 |
|
---|
13 | float4 g_LightCol : LIGHTCOLOR
|
---|
14 | <
|
---|
15 | int LightRef = 0;
|
---|
16 | > = float4(0.0f, 0.0f, 0.0f, 0.0f);
|
---|
17 |
|
---|
18 | // material reflectivity
|
---|
19 | float4 k_a <
|
---|
20 | string UIName = "Ambient";
|
---|
21 | > = float4( 0.47f, 0.47f, 0.47f, 1.0f ); // ambient
|
---|
22 |
|
---|
23 | float4 k_d <
|
---|
24 | string UIName = "Diffuse";
|
---|
25 | > = float4( 0.47f, 0.47f, 0.47f, 1.0f ); // diffuse
|
---|
26 |
|
---|
27 | float4 k_s <
|
---|
28 | string UIName = "Specular";
|
---|
29 | > = float4( 1.0f, 1.0f, 1.0f, 1.0f ); // diffuse // specular
|
---|
30 |
|
---|
31 | int n<
|
---|
32 | string UIName = "Specular Power";
|
---|
33 | string UIType = "IntSpinner";
|
---|
34 | float UIMin = 0.0f;
|
---|
35 | float UIMax = 50.0f;
|
---|
36 | > = 15;
|
---|
37 |
|
---|
38 | bool g_AlphaVertex <
|
---|
39 | string UIName = "Vertex Alpha";
|
---|
40 | > = true;
|
---|
41 |
|
---|
42 | bool g_AddVertexColor <
|
---|
43 | string UIName = "Add Vertex Color";
|
---|
44 | > =false;
|
---|
45 |
|
---|
46 | bool g_UseParallax <
|
---|
47 | string UIName = "Normal Map Parallax";
|
---|
48 | > =false;
|
---|
49 |
|
---|
50 | float g_BumpScale <
|
---|
51 | string UIName = "Bump Amount";
|
---|
52 | float UIMin = 0.0f;
|
---|
53 | float UIMax = 5.0f;
|
---|
54 | float UIStep = 0.01f;
|
---|
55 | > = 1.0f;
|
---|
56 |
|
---|
57 |
|
---|
58 | float g_ParallaxScale <
|
---|
59 | string UIName = "Parallax Scale";
|
---|
60 | float UIMin = -0.50f;
|
---|
61 | float UIMax = 0.5f;
|
---|
62 | float UIStep = 0.01f;
|
---|
63 | > = 0.02f;
|
---|
64 |
|
---|
65 | float g_ParallaxBias <
|
---|
66 | string UIName = "Parallax Bias";
|
---|
67 | float UIMin = -0.5f;
|
---|
68 | float UIMax = 0.5f;
|
---|
69 | float UIStep = 0.01f;
|
---|
70 | > = 0.0f;
|
---|
71 |
|
---|
72 | bool g_AmbientOccEnable <
|
---|
73 | string UIName = "Ambient Occlusion Enable";
|
---|
74 | > = false;
|
---|
75 |
|
---|
76 | texture g_AmbientOccTexture <
|
---|
77 | string UIName = "Ambient Occlusion";
|
---|
78 | >;
|
---|
79 |
|
---|
80 | bool g_TopDiffuseEnable <
|
---|
81 | string UIName = "Top Diffuse Color Enable";
|
---|
82 | > = false;
|
---|
83 |
|
---|
84 | texture g_TopTexture : DiffuseMap<
|
---|
85 | string UIName = "Top Diffuse Map ";
|
---|
86 | >;
|
---|
87 |
|
---|
88 | bool g_BottomDiffuseEnable <
|
---|
89 | string UIName = "Bottom Diffuse Color Enable";
|
---|
90 | > = false;
|
---|
91 |
|
---|
92 | texture g_BottomTexture <
|
---|
93 | string UIName = "Bottom Diffuse";
|
---|
94 | >;
|
---|
95 |
|
---|
96 | bool g_SpecularEnable <
|
---|
97 | string UIName = "Specular Enable";
|
---|
98 | > = false;
|
---|
99 |
|
---|
100 | texture g_SpecularTexture <
|
---|
101 | string UIName = "Specular";
|
---|
102 | >;
|
---|
103 |
|
---|
104 | bool g_NormalEnable <
|
---|
105 | string UIName = "Normal Enable";
|
---|
106 | > = false;
|
---|
107 |
|
---|
108 | texture g_NormalTexture <
|
---|
109 | string UIName = "Normal";
|
---|
110 | >;
|
---|
111 |
|
---|
112 | bool g_ReflectionEnable <
|
---|
113 | string UIName = "Reflection Enable";
|
---|
114 | > = false;
|
---|
115 |
|
---|
116 | texture g_ReflectionTexture <
|
---|
117 | string UIName = "Reflection";
|
---|
118 | string Type = "CUBE";
|
---|
119 | >;
|
---|
120 |
|
---|
121 |
|
---|
122 | sampler2D g_AmbientOccSampler = sampler_state
|
---|
123 | {
|
---|
124 | Texture = <g_AmbientOccTexture>;
|
---|
125 | MinFilter = Linear;
|
---|
126 | MagFilter = Linear;
|
---|
127 | MipFilter = Linear;
|
---|
128 | };
|
---|
129 |
|
---|
130 |
|
---|
131 | sampler2D g_TopSampler = sampler_state
|
---|
132 | {
|
---|
133 | Texture = <g_TopTexture>;
|
---|
134 | MinFilter = Linear;
|
---|
135 | MagFilter = Linear;
|
---|
136 | MipFilter = Linear;
|
---|
137 | };
|
---|
138 |
|
---|
139 | sampler2D g_BottomSampler = sampler_state
|
---|
140 | {
|
---|
141 | Texture = <g_BottomTexture>;
|
---|
142 | MinFilter = Linear;
|
---|
143 | MagFilter = Linear;
|
---|
144 | MipFilter = Linear;
|
---|
145 | };
|
---|
146 |
|
---|
147 | sampler2D g_SpecularSampler = sampler_state
|
---|
148 | {
|
---|
149 | Texture = <g_SpecularTexture>;
|
---|
150 | MinFilter = Linear;
|
---|
151 | MagFilter = Linear;
|
---|
152 | MipFilter = Linear;
|
---|
153 | };
|
---|
154 |
|
---|
155 | sampler2D g_NormalSampler = sampler_state
|
---|
156 | {
|
---|
157 | Texture = <g_NormalTexture>;
|
---|
158 | MinFilter = Linear;
|
---|
159 | MagFilter = Linear;
|
---|
160 | MipFilter = Linear;
|
---|
161 | };
|
---|
162 |
|
---|
163 | samplerCUBE g_ReflectionSampler = sampler_state
|
---|
164 | {
|
---|
165 | Texture = <g_ReflectionTexture>;
|
---|
166 | MinFilter = Linear;
|
---|
167 | MagFilter = Linear;
|
---|
168 | MipFilter = Linear;
|
---|
169 | };
|
---|
170 |
|
---|
171 | // light direction (view space)
|
---|
172 |
|
---|
173 | // transformations
|
---|
174 | float4x4 World : WORLD;
|
---|
175 | float4x4 View : VIEW;
|
---|
176 | float4x4 Projection : PROJECTION;
|
---|
177 | float4x4 WorldViewProj : WORLDVIEWPROJ;
|
---|
178 | float4x4 WorldView : WORLDVIEW;
|
---|
179 | float3 g_CamPos : WORLDCAMERAPOSITION;
|
---|
180 |
|
---|
181 | int color0 : Color
|
---|
182 | <
|
---|
183 | int Color = 0;
|
---|
184 | int VertexColor = 0;
|
---|
185 | >;
|
---|
186 |
|
---|
187 | int texcoord0 : Texcoord
|
---|
188 | <
|
---|
189 | int Texcoord = 0;
|
---|
190 | int MapChannel = 0;
|
---|
191 | >;
|
---|
192 |
|
---|
193 | int texcoord1 :Texcoord
|
---|
194 | <
|
---|
195 | int Texcoord = 1;
|
---|
196 | int MapChannel = 1;
|
---|
197 | bool ColorChannel = true;
|
---|
198 | >;
|
---|
199 |
|
---|
200 | int texcoord2 : Texcoord
|
---|
201 | <
|
---|
202 | int Texcoord = 2;
|
---|
203 | int MapChannel = 2;
|
---|
204 | >;
|
---|
205 |
|
---|
206 | int texcoord3 : Texcoord
|
---|
207 | <
|
---|
208 | int Texcoord = 3;
|
---|
209 | int MapChannel = 3;
|
---|
210 | >;
|
---|
211 |
|
---|
212 | int texcoord4 : Texcoord
|
---|
213 | <
|
---|
214 | int Texcoord = 4;
|
---|
215 | int MapChannel = 4;
|
---|
216 | >;
|
---|
217 |
|
---|
218 | int texcoord5 : Texcoord
|
---|
219 | <
|
---|
220 | int Texcoord = 5;
|
---|
221 | int MapChannel = 5;
|
---|
222 | >;
|
---|
223 |
|
---|
224 | int texcoord6 : Texcoord
|
---|
225 | <
|
---|
226 | int Texcoord = 6;
|
---|
227 | int MapChannel = 6;
|
---|
228 | >;
|
---|
229 |
|
---|
230 | int texcoord7 : Texcoord
|
---|
231 | <
|
---|
232 | int Texcoord = 7;
|
---|
233 | int MapChannel = 7;
|
---|
234 | >;
|
---|
235 |
|
---|
236 | float3 NormalCalc(float3 mapNorm, float BumpScale)
|
---|
237 | {
|
---|
238 | float3 v = {0.5f,0.5f,1.0f};
|
---|
239 | mapNorm = lerp(v, mapNorm, BumpScale );
|
---|
240 | mapNorm = ( mapNorm * 2.0f ) - 1.0f;
|
---|
241 | return mapNorm;
|
---|
242 | }
|
---|
243 |
|
---|
244 | struct VSIn
|
---|
245 | {
|
---|
246 | float3 Position : POSITION;
|
---|
247 | float3 Normal : NORMAL;
|
---|
248 | float3 Tangent : TANGENT;
|
---|
249 | float3 BiNormal : BINORMAL;
|
---|
250 | float3 Col : COLOR0;
|
---|
251 | float2 UV0 : TEXCOORD0;
|
---|
252 | float4 Colour : TEXCOORD1;
|
---|
253 | float3 Alpha : TEXCOORD2;
|
---|
254 | float3 Illum : TEXCOORD3;
|
---|
255 | float3 UV1 : TEXCOORD4;
|
---|
256 | float3 UV2 : TEXCOORD5;
|
---|
257 | float3 UV3 : TEXCOORD6;
|
---|
258 | float3 UV4 : TEXCOORD7;
|
---|
259 |
|
---|
260 | };
|
---|
261 |
|
---|
262 | struct VSOut
|
---|
263 | {
|
---|
264 | float4 Position : POSITION;
|
---|
265 | float4 Colour : COLOR0;
|
---|
266 | float2 UV0 : TEXCOORD0;
|
---|
267 | float3 LightDir : TEXCOORD1;
|
---|
268 | float3 Normal : TEXCOORD2;
|
---|
269 | float3 ViewDir : TEXCOORD3;
|
---|
270 | float2 UV1 : TEXCOORD4;
|
---|
271 | float2 UV2 : TEXCOORD5;
|
---|
272 | float2 UV3 : TEXCOORD6;
|
---|
273 | float2 UV4 : TEXCOORD7;
|
---|
274 |
|
---|
275 | };
|
---|
276 |
|
---|
277 | struct PSIn
|
---|
278 | {
|
---|
279 | float4 Colour : COLOR0;
|
---|
280 | float2 UV0 : TEXCOORD0;
|
---|
281 | float3 LightDir : TEXCOORD1;
|
---|
282 | float3 Normal : TEXCOORD2;
|
---|
283 | float3 ViewDir : TEXCOORD3;
|
---|
284 | float2 UV1 : TEXCOORD4;
|
---|
285 | float2 UV2 : TEXCOORD5;
|
---|
286 | float2 UV3 : TEXCOORD6;
|
---|
287 | float2 UV4 : TEXCOORD7;
|
---|
288 |
|
---|
289 | };
|
---|
290 |
|
---|
291 | struct PSOut
|
---|
292 | {
|
---|
293 | float4 Colour : COLOR0;
|
---|
294 | };
|
---|
295 |
|
---|
296 | texture it
|
---|
297 | <
|
---|
298 | string UIName = "Indirect Texture";
|
---|
299 | >;
|
---|
300 |
|
---|
301 | texture st
|
---|
302 | <
|
---|
303 | string UIName = "Source Texture";
|
---|
304 | >;
|
---|
305 |
|
---|
306 | sampler2D indirectTexture = sampler_state
|
---|
307 | {
|
---|
308 | Texture = <it>;
|
---|
309 | MinFilter = POINT;
|
---|
310 | MagFilter = POINT;
|
---|
311 | MipFilter = NONE;
|
---|
312 | };
|
---|
313 |
|
---|
314 |
|
---|
315 | sampler2D sourceTexture = sampler_state
|
---|
316 | {
|
---|
317 | Texture = <st>;
|
---|
318 | MinFilter = LINEAR;
|
---|
319 | MagFilter = LINEAR;
|
---|
320 | MipFilter = NONE;
|
---|
321 | };
|
---|
322 |
|
---|
323 | VSOut VS(VSIn In)
|
---|
324 | {
|
---|
325 | VSOut Out = (VSOut)0;
|
---|
326 |
|
---|
327 | Out.Position = mul(float4(In.Position, 1.0),WorldViewProj);
|
---|
328 | Out.Colour = float4(In.UV0.xy, 0.0, 1.0);
|
---|
329 | Out.Normal = In.Normal;
|
---|
330 |
|
---|
331 | float4 WorldPos = mul(float4(In.Position, 1.0f),World);
|
---|
332 | float3 ViewDir = g_CamPos - WorldPos.xyz;
|
---|
333 |
|
---|
334 | if(g_NormalEnable)
|
---|
335 | {
|
---|
336 | float3x3 objToTangent;
|
---|
337 |
|
---|
338 | objToTangent[0] = In.BiNormal;
|
---|
339 | objToTangent[1] = In.Tangent;
|
---|
340 | objToTangent[2] = In.Normal;
|
---|
341 |
|
---|
342 | Out.LightDir = mul(objToTangent, g_LightDir);
|
---|
343 | Out.ViewDir = mul(objToTangent, ViewDir);
|
---|
344 | }
|
---|
345 | else
|
---|
346 | {
|
---|
347 | Out.LightDir = g_LightDir;
|
---|
348 | Out.ViewDir = ViewDir;
|
---|
349 | }
|
---|
350 |
|
---|
351 | Out.UV0 = In.UV0.xy;
|
---|
352 | Out.UV1 = In.Colour.xy;
|
---|
353 | Out.UV2 = In.UV2;
|
---|
354 | Out.UV3 = In.UV3;
|
---|
355 | Out.UV4 = In.UV4;
|
---|
356 |
|
---|
357 | return Out;
|
---|
358 |
|
---|
359 | }
|
---|
360 |
|
---|
361 | float epsilonX <
|
---|
362 | string UIName = "Epsilon X";
|
---|
363 | float UIMin = -0.50f;
|
---|
364 | float UIMax = 0.5f;
|
---|
365 | float UIStep = 0.001f;
|
---|
366 | > = 0.02f;
|
---|
367 |
|
---|
368 | float epsilonY <
|
---|
369 | string UIName = "Epsilon X";
|
---|
370 | float UIMin = -0.50f;
|
---|
371 | float UIMax = 0.5f;
|
---|
372 | float UIStep = 0.001f;
|
---|
373 | > = 0.02f;
|
---|
374 |
|
---|
375 | float sourceTextureSize <
|
---|
376 | string UIName = "Source Texture Size";
|
---|
377 | float UIMin = 0.0f;
|
---|
378 | float UIMax = 1024.0f;
|
---|
379 | float UIStep = 1.0f;
|
---|
380 | > = 16.0f;
|
---|
381 |
|
---|
382 | float sqrtNumSamples <
|
---|
383 | string UIName = "SQRT Num.Samples";
|
---|
384 | float UIMin = 0.0f;
|
---|
385 | float UIMax = 64.0f;
|
---|
386 | float UIStep = 1.0f;
|
---|
387 | > = 4.0f;
|
---|
388 |
|
---|
389 | PSOut PS( PSIn psIn )
|
---|
390 | {
|
---|
391 | PSOut psOut;
|
---|
392 |
|
---|
393 | psOut.Colour = float4(0.0, 0.0, 0.0, 0.0);
|
---|
394 | float2 epsilon = float2(epsilonX, epsilonY);
|
---|
395 | float4 value = tex2D(indirectTexture, psIn.UV1.xy).xyzw;
|
---|
396 | float2 coords = float2(0.0, 1.0) - abs(psIn.UV0.xy - ( value.xy - epsilon ) );
|
---|
397 |
|
---|
398 | if (value.w != 0.0)
|
---|
399 | {
|
---|
400 | float3 BottomCol = k_d.rgb;
|
---|
401 | float4 TopCol = k_d;
|
---|
402 | float3 LightCol = float3(1.0,1.0,1.0);
|
---|
403 | float3 Normal = normalize(psIn.Normal);
|
---|
404 | float3 LightDir = normalize(psIn.LightDir);
|
---|
405 | float3 ViewDir = normalize(psIn.ViewDir);
|
---|
406 | float3 Ambient = k_a.rgb;
|
---|
407 | float3 SpecLevel = float3(1.0,1.0,1.0);
|
---|
408 | float Alpha;
|
---|
409 |
|
---|
410 | float2 normalUV = psIn.UV4;
|
---|
411 |
|
---|
412 | float4 newCol;
|
---|
413 |
|
---|
414 | //if(g_AmbientOccEnable)
|
---|
415 | // Ambient *= tex2D(g_AmbientOccSampler, psIn.UV1);
|
---|
416 |
|
---|
417 |
|
---|
418 |
|
---|
419 |
|
---|
420 | //if(g_BottomDiffuseEnable)
|
---|
421 | // BottomCol = tex2D(g_BottomSampler, psIn.UV2);
|
---|
422 |
|
---|
423 |
|
---|
424 | //if(g_AlphaVertex)
|
---|
425 | // Alpha = psIn.Colour.a;
|
---|
426 | //else
|
---|
427 | // Alpha = TopCol.a;
|
---|
428 |
|
---|
429 | //if(g_UseParallax)
|
---|
430 | //{
|
---|
431 | // float height = tex2D(g_NormalSampler, psIn.UV4 ).a;
|
---|
432 | // float Altitude = height + g_ParallaxBias;
|
---|
433 | // normalUV = Altitude * g_ParallaxScale*ViewDir;
|
---|
434 | // normalUV += psIn.UV4;
|
---|
435 | //}
|
---|
436 |
|
---|
437 | //if(g_NormalEnable)
|
---|
438 | // Normal = NormalCalc(tex2D(g_NormalSampler, normalUV).xyz, g_BumpScale);
|
---|
439 |
|
---|
440 | //if(g_SpecularEnable)
|
---|
441 | // SpecLevel = tex2D(g_SpecularSampler, psIn.UV3).xyz;
|
---|
442 |
|
---|
443 |
|
---|
444 | if(g_TopDiffuseEnable)
|
---|
445 | {
|
---|
446 | float2 newcoord = (float2(1.0, 1.0) - value.zw) + ((coords * sourceTextureSize) / sqrtNumSamples);
|
---|
447 | //TopCol = float4(tex2D(sourceTexture, newcoord).xyzw);
|
---|
448 | newCol = float4(tex2D(sourceTexture, newcoord).xyzw);
|
---|
449 | psOut.Colour.a = newCol.w;
|
---|
450 | }
|
---|
451 |
|
---|
452 | //newCol.rgb = TopCol * Alpha;
|
---|
453 | //newCol.rgb += BottomCol * (1.0f - Alpha);
|
---|
454 | //if(g_AddVertexColor)
|
---|
455 | // newCol.rgb *= psIn.Colour.rgb;
|
---|
456 |
|
---|
457 | // Original version
|
---|
458 | //psOut.Colour.rgb = (Ambient + (g_LightCol * saturate(dot(Normal, LightDir)))) * newCol.rgb;
|
---|
459 | psOut.Colour.rgb = (Ambient + (g_LightCol * ( clamp(dot(Normal, LightDir), 0.0, 1.0) + clamp(-dot(Normal, LightDir), 0.0, 1.0) ) )) * newCol.rgb;
|
---|
460 |
|
---|
461 | //if(g_ReflectionEnable)
|
---|
462 | //{
|
---|
463 | // float3 CUV = normalize( reflect( ViewDir, Normal));
|
---|
464 | // float4 env = texCUBE(g_ReflectionSampler, CUV);
|
---|
465 | // psOut.Colour.rgb += env.rgb;
|
---|
466 | //}
|
---|
467 |
|
---|
468 |
|
---|
469 | //float3 H = normalize(LightDir + ViewDir);
|
---|
470 | //float Specular = pow(saturate(dot(Normal, H)), n);
|
---|
471 | //psOut.Colour.rgb += (k_s.rgb * Specular) * SpecLevel.rgb;
|
---|
472 | }
|
---|
473 |
|
---|
474 | return psOut;
|
---|
475 | }
|
---|
476 |
|
---|
477 | technique indirectTexturing
|
---|
478 | {
|
---|
479 | pass P0
|
---|
480 | {
|
---|
481 | //ZEnable = true;
|
---|
482 | //ZWriteEnable = true;
|
---|
483 | CullMode = NONE;
|
---|
484 | AlphaFunc = GREATEREQUAL;
|
---|
485 | AlphaRef = 0x110;
|
---|
486 | AlphaBlendEnable = FALSE;
|
---|
487 | AlphaTestEnable = TRUE;
|
---|
488 |
|
---|
489 | // shaders
|
---|
490 |
|
---|
491 | VertexShader = compile vs_1_1 VS();
|
---|
492 | PixelShader = compile ps_2_0 PS();
|
---|
493 | }
|
---|
494 | }
|
---|
495 |
|
---|