1 | #define SAMPLECUTDIST2 0.01
|
---|
2 | #define WEIGHTCUTOFF 0.01
|
---|
3 |
|
---|
4 | uniform int nRadionColumns;
|
---|
5 | uniform sampler2D radionSampler : register(s0);
|
---|
6 | uniform sampler2D entryPointCountSampler : register(s1);
|
---|
7 | uniform sampler2D allWeightsSampler : register(s2);
|
---|
8 | uniform float3 lightPos;
|
---|
9 | uniform float3 lightDir;
|
---|
10 | uniform float clusterCount;
|
---|
11 |
|
---|
12 | struct vsInputComputeWeights
|
---|
13 | {
|
---|
14 | float4 pos : POSITION;
|
---|
15 | float2 tex : TEXCOORD0;
|
---|
16 | };
|
---|
17 |
|
---|
18 | struct vsOutputComputeWeights
|
---|
19 | {
|
---|
20 | float4 pos : POSITION;
|
---|
21 | float2 tex : TEXCOORD0;
|
---|
22 | };
|
---|
23 |
|
---|
24 | vsOutputComputeWeights
|
---|
25 | vsComputeWeights(vsInputComputeWeights input)
|
---|
26 | {
|
---|
27 | vsOutputComputeWeights output = (vsOutputComputeWeights)0;
|
---|
28 | output.pos = input.pos;
|
---|
29 | output.tex = input.tex;
|
---|
30 | output.tex.y = 1.0 - output.tex.y;
|
---|
31 | return output;
|
---|
32 | }
|
---|
33 |
|
---|
34 | float4
|
---|
35 | psComputeWeights(vsOutputComputeWeights input) : COLOR0
|
---|
36 | {
|
---|
37 | float dataColumnWidth = 1.0 / (float)nRadionColumns;
|
---|
38 | int bushIndex = input.tex.x * 4096 + input.tex.y * nRadionColumns * 4096;
|
---|
39 | int werx = bushIndex % nRadionColumns;
|
---|
40 | int wery = bushIndex / nRadionColumns;
|
---|
41 | float3 pos = tex2D(radionSampler, float2((werx + 0.25) * dataColumnWidth, (wery + 0.5) / 4096.0) ).xyz;
|
---|
42 | float3 dir = tex2D(radionSampler, float2((werx + 0.75) * dataColumnWidth, (wery + 0.5) / 4096.0) ).xyz;
|
---|
43 |
|
---|
44 | float3 diff = lightPos - pos;
|
---|
45 | float dist2 = dot(diff, diff);
|
---|
46 | if(dist2 < SAMPLECUTDIST2)
|
---|
47 | dist2 = SAMPLECUTDIST2;
|
---|
48 | diff = normalize(diff);
|
---|
49 | float cosa = max(dot(lightDir, -diff), 0);
|
---|
50 | float cosb = max(dot(dir, diff), 0);
|
---|
51 |
|
---|
52 | /*
|
---|
53 | float4 occProjPos = mul(float4(pos, 1), occWorldToProjMatrix);
|
---|
54 | occProjPos /= occProjPos.w;
|
---|
55 | float2 occTexPos = mul( occProjPos.xyw, occProjToTexMatrix);
|
---|
56 | float visibility = tex2Dproj(depthMapSampler, float4(occTexPos, occProjPos.z - 0.1, 1) );
|
---|
57 |
|
---|
58 | float3 lightToPos = pos - lightPos;
|
---|
59 | float actualDepth = length(lightToPos);
|
---|
60 | */
|
---|
61 | float visibility = 1;
|
---|
62 |
|
---|
63 | float4 ret = cosa * cosb;
|
---|
64 |
|
---|
65 | float ize = 0;
|
---|
66 | if(pos.z > 0) ize = 1;
|
---|
67 | //return float4(lightDir + ret.x * 0.00000000001, 1);
|
---|
68 | //return ret;
|
---|
69 | return ret.x*0.0000000001 + ize;
|
---|
70 | }
|
---|
71 |
|
---|
72 | float4 psSumWeights(vsOutputComputeWeights input) : COLOR0
|
---|
73 | {
|
---|
74 | float halfPixel = 0.5 / clusterCount;
|
---|
75 | float iCluster = input.tex.x + halfPixel;
|
---|
76 | int entryPointCount = tex2D(entryPointCountSampler, float2(iCluster, 0.25));
|
---|
77 | int currentEntryPoint = tex2D(entryPointCountSampler, float2(iCluster, 0.75));
|
---|
78 | //sum entrypoint weights
|
---|
79 | float weight = 0;
|
---|
80 | float clusterRad = 0;
|
---|
81 | for(int i = 0; i < entryPointCount; i++)
|
---|
82 | {
|
---|
83 | float hp = float2(0.5 / (float) nRadionColumns, 0.5 / 4096.0);
|
---|
84 | float2 coord1 = float2((float)(currentEntryPoint % nRadionColumns) / (float) nRadionColumns,
|
---|
85 | currentEntryPoint / (float) nRadionColumns / 4096.0) + hp;
|
---|
86 | float2 coord2 = coord1 + float2(hp.x / 2.0, 0);
|
---|
87 | float radrad = tex2Dlod(radionSampler, float4(coord2, 0, 0)).a;
|
---|
88 | //weight += tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).r * radrad;
|
---|
89 | weight += tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).r;
|
---|
90 | //clusterRad += radrad;
|
---|
91 | currentEntryPoint++;
|
---|
92 | }
|
---|
93 | /*
|
---|
94 | if(clusterRad >= 0)
|
---|
95 | weight /= clusterRad;
|
---|
96 | else
|
---|
97 | weight = 0;*/
|
---|
98 |
|
---|
99 | weight /= (float) entryPointCount;
|
---|
100 |
|
---|
101 | return weight;
|
---|
102 | }
|
---|
103 |
|
---|
104 | void EntryPointDisplayVS(float4 position :POSITION0,
|
---|
105 | float4 color :COLOR0,
|
---|
106 | uniform float4x4 worldViewProj,
|
---|
107 | out float4 hPos:POSITION,
|
---|
108 | out float2 texCoord: TEXCOORD0)
|
---|
109 | {
|
---|
110 | hPos = mul(worldViewProj, position);
|
---|
111 | texCoord = color.xy;
|
---|
112 | }
|
---|
113 |
|
---|
114 | float4 EntryPointDisplayPS(float2 texCoord : TEXCOORD0,
|
---|
115 | uniform sampler2D weightTexture : register(s0)):COLOR0
|
---|
116 | {
|
---|
117 | //return texCoord.y;
|
---|
118 | return tex2D(weightTexture, texCoord).r;
|
---|
119 | }
|
---|
120 | |
---|