source: GTP/trunk/App/Demos/Illum/pathmap/pathMap.fx @ 2197

Revision 2197, 7.7 KB checked in by szirmay, 17 years ago (diff)
Line 
1float4x4 modelToWorldMatrix;
2float4x4 inverseTransposedModelToWorldMatrix;
3float4x4 modelToProjMatrix;
4
5float4x4 occWorldToProjMatrix;
6float3x3 occProjToTexMatrix;
7
8int2 prmAtlasTiles;
9float2 atlasHalfPixel;
10
11texture brdfMap;                                                                //material texture sampler
12sampler2D brdfMapSampler =      sampler_state{ 
13                texture = < brdfMap >;
14                MinFilter = LINEAR;
15                MagFilter = LINEAR;
16                MipFilter = None;
17                AddressU  = Wrap;
18                AddressV  = Wrap;
19                };
20               
21texture bumpMap;                                                                //material texture sampler
22sampler2D bumpMapSampler =      sampler_state{ 
23                texture = < bumpMap >;
24                MinFilter = LINEAR;
25                MagFilter = LINEAR;
26                MipFilter = None;
27                AddressU  = Wrap;
28                AddressV  = Wrap;
29                };
30               
31texture normalMap;                                                              //material texture sampler
32sampler2D normalMapSampler =    sampler_state{ 
33                texture = < normalMap >;
34                MinFilter = LINEAR;
35                MagFilter = LINEAR;
36                MipFilter = None;
37                AddressU  = Wrap;
38                AddressV  = Wrap;
39                };
40
41texture filteredAtlas;
42sampler filteredAtlasSampler = sampler_state
43{
44   Texture = <filteredAtlas>;
45   MinFilter = LINEAR;
46   MagFilter = LINEAR;
47   MipFilter = None;
48   AddressU = Wrap;
49   AddressV = Wrap;
50};
51
52texture depthMap;
53sampler2D depthMapSampler =     sampler_state{ 
54                texture = < depthMap >;
55                MinFilter = Linear;
56                MagFilter = Linear;
57                MipFilter = None;
58                AddressU  = Clamp;
59                AddressV  = Clamp;
60//              AddressU  = Border;
61//              AddressV  = Border;
62//              BorderColor = float4(65535, 65535, 65535, 65535);
63                };
64               
65float3          lightPos;
66float3          lightDir;
67float3          lightPower;
68
69float4          weightsa[8];
70
71struct vsInputWalk
72{
73    float4 pos                  : POSITION;
74    float3 normal               : NORMAL;
75    float2 tex                  : TEXCOORD0;
76    float2 texAtlas             : TEXCOORD1;
77    float3 tangent              : TEXCOORD2;
78    float3 binormal             : TEXCOORD3;
79};
80
81struct vsOutputWalk
82{
83    float4 pos                  : POSITION;
84    float3 normal               : NORMAL;
85    float3 tangent              : TEXCOORD4;
86    float3 binormal             : TEXCOORD5;
87   
88    float2 tex                  : TEXCOORD0;
89    float2 texAtlas             : TEXCOORD1;
90    float4 worldPos             : TEXCOORD2;
91    float4 occProjPos   : TEXCOORD3;   
92};
93
94
95vsOutputWalk
96        vsWalk(vsInputWalk input)
97{
98        vsOutputWalk output = (vsOutputWalk)0;
99        output.pos = mul(input.pos, modelToProjMatrix);
100
101        output.worldPos = mul(input.pos, modelToWorldMatrix);
102        output.occProjPos = mul(output.worldPos, occWorldToProjMatrix);
103       
104        output.normal = mul(inverseTransposedModelToWorldMatrix, float4(input.normal.xyz, 0.0));
105        output.tangent = mul(inverseTransposedModelToWorldMatrix, float4(input.tangent.xyz, 0.0));
106        output.binormal = mul(inverseTransposedModelToWorldMatrix, float4(input.binormal.xyz, 0.0));
107        output.tex = input.tex;
108        output.texAtlas = input.texAtlas;
109       
110        return output;
111}
112
113
114float4
115        psWalk(vsOutputWalk input) : COLOR
116{
117        float3 col = 0;
118        for(int iCluster=0; iCluster<32; iCluster++)
119        {
120                float2 prmTexPos = float2(
121                        (input.texAtlas.x + (iCluster % prmAtlasTiles.x)) / prmAtlasTiles.x,
122                        1.0 - (input.texAtlas.y + (iCluster / prmAtlasTiles.x)) / prmAtlasTiles.y) + atlasHalfPixel;
123                float4 weight = weightsa[iCluster/4];
124//              weight = 0.001;
125                float3 val = tex2D(filteredAtlasSampler, prmTexPos);
126                col += val.xyz * weight.x;
127                iCluster++;
128               
129                prmTexPos.x += 1.0 / prmAtlasTiles.x;
130                val = tex2D(filteredAtlasSampler, prmTexPos);
131                col += val.xyz * weight.y;
132                iCluster++;
133               
134                prmTexPos.x += 1.0 / prmAtlasTiles.x;
135                val = tex2D(filteredAtlasSampler, prmTexPos);
136                col += val.xyz * weight.z;
137                iCluster++;
138               
139                prmTexPos.x += 1.0 / prmAtlasTiles.x;
140                val = tex2D(filteredAtlasSampler, prmTexPos);
141                col += val.xyz * weight.w;
142        }
143//      col *= 1000.01;
144//      col *= 0.8;
145//      col = 0;
146
147    // get tangent space normal vector
148/*    float3 tNormal = tex2D(normalMapSampler, input.tex).rgb;
149        // which is the transpose of ModelToTangent
150    float3 mNormal = normalize( input.tangent * tNormal.x + input.binormal * tNormal.y + input.normal * tNormal.z );
151
152        input.normal = mNormal;
153*/     
154//      return float4(input.normal, 1);
155
156        input.occProjPos /= input.occProjPos.w;
157        float2 occTexPos = mul(input.occProjPos.xyw, occProjToTexMatrix);
158        float3 toLight = lightPos - input.worldPos;
159        float3 toLightDir = normalize(lightPos - input.worldPos);
160        float cosa = dot(input.normal, toLightDir);
161        float cosb = dot(lightDir, -toLightDir);
162       
163        float visibility = tex2Dproj(depthMapSampler, float4(occTexPos, input.occProjPos.z, 1));
164        if(cosa > 0 && cosb > 0.0)
165                col += cosa.xxx * pow(cosb, 9) * visibility / dot(toLight, toLight);
166               
167//      return float4(input.tangent,1);
168//      return tex2D(filteredAtlasSampler, float2(input.texAtlas.x / 32.0, 1.0 - input.texAtlas.y));
169        return float4( lightPower * col  * tex2D(brdfMapSampler, input.tex) , 1);
170//      return float4(lightPower * col * tex2D(bumpMapSampler, input.tex), 1);
171}
172
173float4
174        psWalkIndirect(vsOutputWalk input) : COLOR
175{
176        float3 col = 0;
177        for(int iCluster=0; iCluster<32; iCluster++)
178        {
179                float2 prmTexPos = float2(
180                        (input.texAtlas.x + (iCluster % prmAtlasTiles.x)) / prmAtlasTiles.x,
181                        1.0 - (input.texAtlas.y + (iCluster / prmAtlasTiles.x)) / prmAtlasTiles.y) + atlasHalfPixel;
182                float4 weight = weightsa[iCluster/4];
183                float3 val = tex2D(filteredAtlasSampler, prmTexPos);
184                col += val.xyz * weight.x;
185                iCluster++;
186               
187                prmTexPos.x += 1.0 / prmAtlasTiles.x;
188                val = tex2D(filteredAtlasSampler, prmTexPos);
189                col += val.xyz * weight.y;
190                iCluster++;
191               
192                prmTexPos.x += 1.0 / prmAtlasTiles.x;
193                val = tex2D(filteredAtlasSampler, prmTexPos);
194                col += val.xyz * weight.z;
195                iCluster++;
196               
197                prmTexPos.x += 1.0 / prmAtlasTiles.x;
198                val = tex2D(filteredAtlasSampler, prmTexPos);
199                col += val.xyz * weight.w;
200        }
201
202        return float4( lightPower * col  * tex2D(brdfMapSampler, input.tex) , 1);
203}
204
205float4
206        psWalkDirect(vsOutputWalk input) : COLOR
207{
208        float3 col = 0;
209
210        input.occProjPos /= input.occProjPos.w;
211        float2 occTexPos = mul(input.occProjPos.xyw, occProjToTexMatrix);
212        float3 toLight = lightPos - input.worldPos;
213        float3 toLightDir = normalize(lightPos - input.worldPos);
214        float cosa = dot(input.normal, toLightDir);
215        float cosb = dot(lightDir, -toLightDir);
216       
217        float visibility = tex2Dproj(depthMapSampler, float4(occTexPos, input.occProjPos.z, 1));
218        if(cosa > 0 && cosb > 0.0)
219                col += cosa.xxx * pow(cosb, 9) * visibility / dot(toLight, toLight);
220
221        return float4( lightPower * col  * tex2D(brdfMapSampler, input.tex) , 1);
222}
223
224float4
225        psWalkAmbient(vsOutputWalk input) : COLOR
226{
227        float3 col = 0.0012;
228
229        input.occProjPos /= input.occProjPos.w;
230        float2 occTexPos = mul(input.occProjPos.xyw, occProjToTexMatrix);
231        float3 toLight = lightPos - input.worldPos;
232        float3 toLightDir = normalize(lightPos - input.worldPos);
233        float cosa = dot(input.normal, toLightDir);
234        float cosb = dot(lightDir, -toLightDir);
235       
236        float visibility = tex2Dproj(depthMapSampler, float4(occTexPos, input.occProjPos.z, 1));
237        if(cosa > 0 && cosb > 0.0)
238                col += cosa.xxx * pow(cosb, 9) * visibility / dot(toLight, toLight);
239
240        return float4( lightPower * col  * tex2D(brdfMapSampler, input.tex) , 1);
241}
242
243technique walk{
244        pass P0
245    {
246        VertexShader = compile vs_3_0 vsWalk();
247        PixelShader  = compile ps_3_0 psWalk();
248    }
249}
250
251technique walkIndirect{
252        pass P0
253    {
254        VertexShader = compile vs_3_0 vsWalk();
255        PixelShader  = compile ps_3_0 psWalkIndirect();
256    }
257}
258
259technique walkAmbient{
260        pass P0
261    {
262        VertexShader = compile vs_3_0 vsWalk();
263        PixelShader  = compile ps_3_0 psWalkAmbient();
264    }
265}
266
267technique walkDirect{
268        pass P0
269    {
270        VertexShader = compile vs_3_0 vsWalk();
271        PixelShader  = compile ps_3_0 psWalkDirect();
272    }
273}
274
275#include "bushToAtlas.fx"
276#include "normalize.fx"
277#include "showTex.fx"
278#include "computeWeights.fx"
279#include "depthMap.fx"
280#include "dots.fx"
281#include "torch.tx"
Note: See TracBrowser for help on using the repository browser.