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.pos + 1.0) / 2.0;
|
---|
30 | output.tex.y = 1.0 - output.tex.y;
|
---|
31 | return output;
|
---|
32 | }
|
---|
33 |
|
---|
34 | float4 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 = pow(cosa, 9) * cosb / dist2;
|
---|
63 |
|
---|
64 | //float ize = 0;
|
---|
65 | //if(pos.y > 0) ize = 1;
|
---|
66 | //return float4(lightDir + ret.x * 0.00000000001, 1);
|
---|
67 | //return ret;
|
---|
68 | return ret;
|
---|
69 | }
|
---|
70 |
|
---|
71 | float4 psSumWeights(vsOutputComputeWeights input) : COLOR0
|
---|
72 | {
|
---|
73 | float halfPixel = 0.5 / clusterCount;
|
---|
74 | float iCluster = input.tex.x + halfPixel;
|
---|
75 | int entryPointCount = tex2D(entryPointCountSampler, float2(iCluster, 0.25));
|
---|
76 | int currentEntryPoint = tex2D(entryPointCountSampler, float2(iCluster, 0.75));
|
---|
77 | //sum entrypoint weights
|
---|
78 | float weight = 0;
|
---|
79 | float clusterRad = 0;
|
---|
80 | for(int i = 0; i < entryPointCount; i++)
|
---|
81 | {
|
---|
82 | float hp = float2(0.5 / (float) nRadionColumns, 0.5 / 4096.0);
|
---|
83 | float2 coord1 = float2((float)(currentEntryPoint % nRadionColumns) / (float) nRadionColumns,
|
---|
84 | currentEntryPoint / (float) nRadionColumns / 4096.0) + hp;
|
---|
85 | float2 coord2 = coord1 + float2(hp.x / 2.0, 0);
|
---|
86 | float radrad = tex2Dlod(radionSampler, float4(coord2, 0, 0)).a;
|
---|
87 | //weight += tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).r * radrad;
|
---|
88 | weight += tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).r;
|
---|
89 | clusterRad += radrad;
|
---|
90 | currentEntryPoint++;
|
---|
91 | }
|
---|
92 |
|
---|
93 | /*if(clusterRad >= 0)
|
---|
94 | weight /= clusterRad;
|
---|
95 | else
|
---|
96 | weight = 0;*/
|
---|
97 |
|
---|
98 | weight /= (float) entryPointCount;
|
---|
99 |
|
---|
100 | return weight;
|
---|
101 | }
|
---|
102 |
|
---|
103 | void EntryPointDisplayVS(float4 position :POSITION0,
|
---|
104 | float4 color :COLOR0,
|
---|
105 | uniform float4x4 worldViewProj,
|
---|
106 | out float4 hPos:POSITION,
|
---|
107 | out float2 texCoord: TEXCOORD0)
|
---|
108 | {
|
---|
109 | hPos = mul(worldViewProj, position);
|
---|
110 | texCoord = color.xy;
|
---|
111 | }
|
---|
112 |
|
---|
113 | float4 EntryPointDisplayPS(float2 texCoord : TEXCOORD0,
|
---|
114 | uniform sampler2D weightTexture : register(s0)):COLOR0
|
---|
115 | {
|
---|
116 | //return texCoord.y;
|
---|
117 | return texCoord.r;
|
---|
118 | }
|
---|
119 | |
---|