source: GTP/trunk/App/Demos/Illum/PathMap/pathMap.fx @ 1480

Revision 1480, 3.5 KB checked in by szirmay, 18 years ago (diff)
Line 
1float4x4 modelToWorldMatrix;
2float4x4 inverseTransposedModelToWorldMatrix;
3float4x4 modelToProjMatrix;
4
5float4x4 occWorldToProjMatrix;
6float3x3 occProjToTexMatrix;
7
8texture brdfMap;                                                                //material texture sampler
9sampler2D brdfMapSampler =      sampler_state{ 
10                texture = < brdfMap >;
11                MinFilter = LINEAR;
12                MagFilter = LINEAR;
13                MipFilter = None;
14                AddressU  = Border;
15                AddressV  = Wrap;
16                };
17
18texture filteredAtlas;
19sampler filteredAtlasSampler = sampler_state
20{
21   Texture = <filteredAtlas>;
22   MinFilter = LINEAR;
23   MagFilter = LINEAR;
24   MipFilter = None;
25   AddressU = Wrap;
26   AddressV = Wrap;
27};
28
29texture depthMap;
30sampler2D depthMapSampler =     sampler_state{ 
31                texture = < depthMap >;
32                MinFilter = Linear;
33                MagFilter = Linear;
34                MipFilter = None;
35                AddressU  = Border;
36                AddressV  = Border;
37                BorderColor = float4(1, 1, 1, 1);
38                };
39               
40float3          lightPos;
41float3          lightDir;
42float3          lightPower;
43
44float4          weightsa[8];
45
46struct vsInputWalk
47{
48    float4 pos                  : POSITION;
49    float3 normal               : NORMAL;
50    float2 tex                  : TEXCOORD0;
51};
52
53struct vsOutputWalk
54{
55    float4 pos                  : POSITION;
56    float3 normal               : NORMAL;
57    float2 tex                  : TEXCOORD0;
58    float4 worldPos             : TEXCOORD1;
59    float4 occProjPos   : TEXCOORD2;   
60};
61
62
63vsOutputWalk
64        vsWalk(vsInputWalk input)
65{
66        vsOutputWalk output = (vsOutputWalk)0;
67        output.pos = mul(input.pos, modelToProjMatrix);
68
69        output.worldPos = mul(input.pos, modelToWorldMatrix);
70        output.occProjPos = mul(output.worldPos, occWorldToProjMatrix);
71       
72        output.normal = mul(inverseTransposedModelToWorldMatrix, float4(input.normal.xyz, 0.0));
73        output.tex = input.tex;
74       
75        return output;
76}
77
78
79float4
80        psWalk(vsOutputWalk input) : COLOR
81{
82//      return 1;
83       
84        float3 col = 0;
85        for(int iCluster=0; iCluster<32; iCluster++)
86        {
87                float4 weight = weightsa[iCluster/4];
88                float3 val = tex2D(filteredAtlasSampler, float2(
89                        input.tex.x / 32.0 + 1.0 / 32.0 * (iCluster % 32) + 0.0 / 4096.0, 1.0 - input.tex.y + 0.0 / 128.0));
90                col += val.xyz * weight.x;
91                iCluster++;
92               
93                val = tex2D(filteredAtlasSampler, float2(
94                        input.tex.x / 32.0 + 1.0 / 32.0 * (iCluster % 32) + 0.0 / 4096.0, 1.0 - input.tex.y  + 0.0 / 128.0));
95                col += val.xyz * weight.y;
96                iCluster++;
97               
98                val = tex2D(filteredAtlasSampler, float2(
99                        input.tex.x / 32.0 + 1.0 / 32.0 * (iCluster % 32) + 0.0 / 4096.0, 1.0 - input.tex.y  + 0.0 / 128.0));
100                col += val.xyz * weight.z;
101                iCluster++;
102               
103                val = tex2D(filteredAtlasSampler, float2(
104                        input.tex.x / 32.0 + 1.0 / 32.0 * (iCluster % 32) + 0.0 / 4096.0, 1.0 - input.tex.y  + 0.0 / 128.0));
105                col += val.xyz * weight.w;
106        }
107//      col *= 1000.01;
108//      col *= 0.8;
109//      col = 0;
110
111        input.normal = normalize(input.normal);
112
113        input.occProjPos /= input.occProjPos.w;
114        float2 occTexPos = mul(input.occProjPos.xyw, occProjToTexMatrix);
115        float3 toLight = lightPos - input.worldPos;
116        float3 toLightDir = normalize(lightPos - input.worldPos);
117        float cosa = dot(input.normal, toLightDir);
118        float cosb = dot(lightDir, -toLightDir);
119       
120        float visibility = tex2Dlod(depthMapSampler, float4(occTexPos, input.occProjPos.z, 0));
121        if(cosa > 0 && cosb > 0.0)
122                col += cosa.xxx * pow(cosb, 9) * visibility / dot(toLight, toLight);
123        return float4(lightPower * col * tex2D(brdfMapSampler, input.tex), 1);
124}
125
126technique walk{
127        pass P0
128    {
129        VertexShader = compile vs_3_0 vsWalk();
130        PixelShader  = compile ps_3_0 psWalk();
131    }
132}
133
134#include "bushToAtlas.fx"
135#include "showTex.fx"
136#include "computeWeights.fx"
137#include "depthMap.fx"
138#include "dots.fx"
139#include "torch.tx"
Note: See TracBrowser for help on using the repository browser.