source: GTP/trunk/App/Demos/Illum/pathmap/computeWeights.fx @ 2498

Revision 2498, 3.2 KB checked in by szirmay, 17 years ago (diff)
Line 
1#define SAMPLECUTDIST2 0.01
2#define WEIGHTCUTOFF 0.01
3
4int nRadionColumns;
5
6texture radions;
7sampler radionSampler = sampler_state
8{
9   Texture = <radions>;
10   MinFilter = Point;
11   MagFilter = Point;
12   MipFilter = None;
13};
14
15
16struct vsInputComputeWeights
17{
18    float4      pos                     : POSITION;
19    float2      tex                     : TEXCOORD0;
20};
21
22struct vsOutputComputeWeights
23{
24    float4      pos                     : POSITION;
25    float2      tex                     : TEXCOORD0;
26};
27
28vsOutputComputeWeights
29        vsComputeWeights(vsInputComputeWeights input)
30{
31    vsOutputComputeWeights output = (vsOutputComputeWeights)0;
32    output.pos = input.pos;
33   
34    output.tex = (input.pos + 1.0) / 2.0;
35    output.tex.y = 1.0 - output.tex.y;
36   
37    //output.tex = input.tex;
38    return output;
39}
40
41float4
42        psComputeWeights(vsOutputComputeWeights input) : COLOR0
43{
44        float dataColumnWidth = 1.0 / (float)nRadionColumns;
45        int bushIndex = input.tex.x * 4096 + input.tex.y * nRadionColumns * 4096;
46        int werx = bushIndex % nRadionColumns;
47        int wery = bushIndex / nRadionColumns;
48        float3 pos = tex2D(radionSampler, float2((werx + 0.25) * dataColumnWidth, (wery  + 0.5) / 4096.0) ).xyz;
49        float3 dir = tex2D(radionSampler, float2((werx + 0.75) * dataColumnWidth, (wery  + 0.5) / 4096.0) ).xyz;
50        /*
51        float3 diff = lightPos - pos;
52        float dist2 = dot(diff, diff);
53        if(dist2 < SAMPLECUTDIST2)
54                dist2 = SAMPLECUTDIST2;
55        diff = normalize(diff);
56        float cosa = - dot(lightDir, diff);
57        float cosb = dot(dir, diff);   
58       
59        float4 occProjPos = mul(float4(pos, 1), occWorldToProjMatrix); 
60        occProjPos /= occProjPos.w;
61        float2 occTexPos = mul( occProjPos.xyw, occProjToTexMatrix);
62        float visibility = tex2Dproj(depthMapSampler, float4(occTexPos, occProjPos.z - 0.1, 1) );
63
64        float3 lightToPos = pos - lightPos;
65        float actualDepth = length(lightToPos);
66
67        float ret;
68        if(  visibility < 0.5 || cosa < 0 || cosb < 0)
69                ret = 0.0;
70        else
71                ret = pow(cosa, 9) * cosb / dist2;
72
73        if(ret < 0.000001)
74                ret = 0.0;
75//      if(ret > WEIGHTCUTOFF)
76//              ret = WEIGHTCUTOFF;
77        */
78       
79       
80        float3 diff = lightPos - pos;
81        float dist2 = dot(diff, diff);
82        if(dist2 < SAMPLECUTDIST2)
83                dist2 = SAMPLECUTDIST2;
84        diff = normalize(diff);
85        float cosa = max(dot(lightDir, -diff), 0);
86        float cosb = max(dot(dir, diff), 0);
87        float ret = pow(cosa, 9) * cosb / dist2;
88        return ret;
89       
90        return float4(ret, ret, ret, ret);
91//      return float4((wery  + 0.5) / 4096.0, werx, werx, 1);
92//      return float4(actualDepth, 1, 1, 1);
93}
94
95technique ComputeWeights{
96        pass P0
97    {
98        VertexShader = compile vs_3_0 vsComputeWeights();
99        PixelShader  = compile ps_3_0 psComputeWeights();
100    }
101}
102/*
103float4
104        psAggregateWeights(vsOutputComputeWeights input, in int rid : VPOS) : COLOR0
105{
106        float sumWeight = 0.0;
107        float sumProb = 0.0000001;
108       
109        int iRadion = clusterStarts[rid];
110        float2 wTex = float2((iRadion / 4096 + 0.5) * dataColumnWidth,
111                                                 (iRadion % 4096  + 0.5) / 4096.0) );
112        while(iRadion < clusterStarts[rid+1])
113        {
114                sumWeight += tex2Dlod(weightSampler, float4(wTex, 0, 1));
115                float sumProb += 1.0;
116                wTex.y += 1.0 / 4096.0;
117        }
118        return (sumWeight / sumProb).xxxx;
119}
120
121technique AggregateWeights{
122        pass P0
123    {
124        VertexShader = compile vs_3_0 vsComputeWeights();
125        PixelShader  = compile ps_3_0 psAggregateWeights();
126    }
127}
128*/
Note: See TracBrowser for help on using the repository browser.