1 | #define SAMPLECUTDIST2 0.01
|
---|
2 | #define WEIGHTCUTOFF 0.01
|
---|
3 |
|
---|
4 | uniform int nRadionColumns;
|
---|
5 | uniform sampler2D radionSampler : register(s0);
|
---|
6 | uniform float3 lightPos;
|
---|
7 | uniform float3 lightDir;
|
---|
8 |
|
---|
9 | struct vsInputComputeWeights
|
---|
10 | {
|
---|
11 | float4 pos : POSITION;
|
---|
12 | float2 tex : TEXCOORD0;
|
---|
13 | };
|
---|
14 |
|
---|
15 | struct vsOutputComputeWeights
|
---|
16 | {
|
---|
17 | float4 pos : POSITION;
|
---|
18 | float2 tex : TEXCOORD0;
|
---|
19 | };
|
---|
20 |
|
---|
21 | vsOutputComputeWeights
|
---|
22 | vsComputeWeights(vsInputComputeWeights input)
|
---|
23 | {
|
---|
24 | vsOutputComputeWeights output = (vsOutputComputeWeights)0;
|
---|
25 | output.pos = input.pos;
|
---|
26 | output.tex = input.tex;
|
---|
27 | return output;
|
---|
28 | }
|
---|
29 |
|
---|
30 | float4
|
---|
31 | psComputeWeights(vsOutputComputeWeights input) : COLOR0
|
---|
32 | {
|
---|
33 | float dataColumnWidth = 1.0 / (float)nRadionColumns;
|
---|
34 | int bushIndex = input.tex.x * 4096 + input.tex.y * nRadionColumns * 4096;
|
---|
35 | int werx = bushIndex % nRadionColumns;
|
---|
36 | int wery = bushIndex / nRadionColumns;
|
---|
37 | float3 pos = tex2D(radionSampler, float2((werx + 0.25) * dataColumnWidth, (wery + 0.5) / 4096.0) ).xyz;
|
---|
38 | float3 dir = tex2D(radionSampler, float2((werx + 0.75) * dataColumnWidth, (wery + 0.5) / 4096.0) ).xyz;
|
---|
39 |
|
---|
40 | float3 diff = lightPos - pos;
|
---|
41 | float dist2 = dot(diff, diff);
|
---|
42 | if(dist2 < SAMPLECUTDIST2)
|
---|
43 | dist2 = SAMPLECUTDIST2;
|
---|
44 | diff = normalize(diff);
|
---|
45 | float cosa = - dot(lightDir, diff);
|
---|
46 | float cosb = dot(dir, diff);
|
---|
47 |
|
---|
48 | /*
|
---|
49 | float4 occProjPos = mul(float4(pos, 1), occWorldToProjMatrix);
|
---|
50 | occProjPos /= occProjPos.w;
|
---|
51 | float2 occTexPos = mul( occProjPos.xyw, occProjToTexMatrix);
|
---|
52 | float visibility = tex2Dproj(depthMapSampler, float4(occTexPos, occProjPos.z - 0.1, 1) );
|
---|
53 |
|
---|
54 | float3 lightToPos = pos - lightPos;
|
---|
55 | float actualDepth = length(lightToPos);
|
---|
56 | */
|
---|
57 | float visibility = 1;
|
---|
58 |
|
---|
59 | float ret;
|
---|
60 | if( visibility < 0.5 || cosa < 0 || cosb < 0)
|
---|
61 | ret = 0.0;
|
---|
62 | else
|
---|
63 | ret = pow(cosa, 9) * cosb / dist2;
|
---|
64 |
|
---|
65 | if(ret < 0.000001)
|
---|
66 | ret = 0.0;
|
---|
67 |
|
---|
68 | return 1 + ret * 0.0000000001;
|
---|
69 | return float4(ret, ret, ret, ret);
|
---|
70 | } |
---|