source: GTP/trunk/App/Demos/Illum/Ogre/Media/PMDemo/PathMapWeightCompute.hlsl @ 2202

Revision 2202, 3.1 KB checked in by szirmay, 17 years ago (diff)
Line 
1#define SAMPLECUTDIST2 0.01
2#define WEIGHTCUTOFF 0.01
3
4uniform int nRadionColumns;
5uniform sampler2D radionSampler       : register(s0);
6uniform sampler2D entryPointCountSampler : register(s1);
7uniform sampler2D allWeightsSampler   : register(s2);
8uniform float3 lightPos;
9uniform float3 lightDir;
10uniform float clusterCount;
11
12struct vsInputComputeWeights
13{
14    float4      pos                     : POSITION;
15    float2      tex                     : TEXCOORD0;
16};
17
18struct vsOutputComputeWeights
19{
20    float4      pos                     : POSITION;
21    float2      tex                     : TEXCOORD0;
22};
23
24vsOutputComputeWeights
25        vsComputeWeights(vsInputComputeWeights input)
26{
27    vsOutputComputeWeights output = (vsOutputComputeWeights)0;
28    output.pos = input.pos;
29    output.tex = input.tex;
30    return output;
31}
32
33float4
34        psComputeWeights(vsOutputComputeWeights input) : COLOR0
35{
36        float dataColumnWidth = 1.0 / (float)nRadionColumns;
37        int bushIndex = input.tex.x * 4096 + input.tex.y * nRadionColumns * 4096;
38        int werx = bushIndex % nRadionColumns;
39        int wery = bushIndex / nRadionColumns;
40        float3 pos = tex2D(radionSampler, float2((werx + 0.25) * dataColumnWidth, (wery  + 0.5) / 4096.0) ).xyz;
41        float3 dir = tex2D(radionSampler, float2((werx + 0.75) * dataColumnWidth, (wery  + 0.5) / 4096.0) ).xyz;
42       
43        float3 diff = lightPos - pos;
44        float dist2 = dot(diff, diff);
45        if(dist2 < SAMPLECUTDIST2)
46                dist2 = SAMPLECUTDIST2;
47        diff = normalize(diff);
48        float cosa = max(dot(lightDir, -diff), 0);
49        float cosb = max(dot(dir, diff), 0);   
50       
51        /*
52        float4 occProjPos = mul(float4(pos, 1), occWorldToProjMatrix); 
53        occProjPos /= occProjPos.w;
54        float2 occTexPos = mul( occProjPos.xyw, occProjToTexMatrix);
55        float visibility = tex2Dproj(depthMapSampler, float4(occTexPos, occProjPos.z - 0.1, 1) );
56
57        float3 lightToPos = pos - lightPos;
58        float actualDepth = length(lightToPos);
59*/
60        float visibility = 1;
61       
62        float4 ret = cosa * cosb;
63
64        //return float4(lightDir + ret.x * 0.00000000001, 1);
65        return ret;
66        //return ret.x*0.0000000001 + 0.5;
67}
68
69float4 psSumWeights(vsOutputComputeWeights input) : COLOR0
70{
71        float halfPixel = 0.5 / clusterCount;
72        float iCluster = input.tex.x + halfPixel;
73        int entryPointCount = tex2D(entryPointCountSampler, float2(iCluster, 0.25));
74        int currentEntryPoint = tex2D(entryPointCountSampler, float2(iCluster, 0.75));
75        //sum entrypoint weights
76        float weight = 0;
77        float clusterRad = 0;
78        for(int i = 0; i < entryPointCount; i++)
79        {
80                float hp = float2(0.5 / (float) nRadionColumns, 0.5 / 4096.0);
81                float2 coord1 = float2((float)(currentEntryPoint % nRadionColumns)  / (float) nRadionColumns,
82                                                                currentEntryPoint / (float) nRadionColumns / 4096.0) + hp;
83                coord1.y = 1.0 - coord1.y;
84                float2 coord2 = coord1 + float2(hp.x / 2.0, 0);
85                float radrad = tex2Dlod(radionSampler, float4(coord2, 0, 0)).a;
86                //weight += tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).r * radrad;
87                weight += tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).r;
88                //clusterRad += radrad;
89                currentEntryPoint++;
90        }       
91        /*
92        if(clusterRad >= 0)
93                weight /= clusterRad;
94        else
95                weight = 0;*/
96       
97    weight /= (float) entryPointCount;
98               
99        return weight;
100}
Note: See TracBrowser for help on using the repository browser.