[896] | 1 | #define SAMPLECUTDIST2 0.01
|
---|
| 2 | #define WEIGHTCUTOFF 0.01
|
---|
| 3 |
|
---|
| 4 | int nRadionColumns;
|
---|
| 5 |
|
---|
| 6 | texture radions;
|
---|
| 7 | sampler radionSampler = sampler_state
|
---|
| 8 | {
|
---|
| 9 | Texture = <radions>;
|
---|
| 10 | MinFilter = Point;
|
---|
| 11 | MagFilter = Point;
|
---|
| 12 | MipFilter = None;
|
---|
| 13 | };
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 | struct vsInputComputeWeights
|
---|
| 17 | {
|
---|
| 18 | float4 pos : POSITION;
|
---|
| 19 | float2 tex : TEXCOORD0;
|
---|
| 20 | };
|
---|
| 21 |
|
---|
| 22 | struct vsOutputComputeWeights
|
---|
| 23 | {
|
---|
| 24 | float4 pos : POSITION;
|
---|
| 25 | float2 tex : TEXCOORD0;
|
---|
| 26 | };
|
---|
| 27 |
|
---|
| 28 | vsOutputComputeWeights
|
---|
| 29 | vsComputeWeights(vsInputComputeWeights input)
|
---|
| 30 | {
|
---|
| 31 | vsOutputComputeWeights output = (vsOutputComputeWeights)0;
|
---|
| 32 | output.pos = input.pos;
|
---|
| 33 | output.tex = input.tex;
|
---|
| 34 | return output;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | float4
|
---|
| 38 | psComputeWeights(vsOutputComputeWeights input) : COLOR0
|
---|
| 39 | {
|
---|
| 40 | float dataColumnWidth = 1.0 / (float)nRadionColumns;
|
---|
| 41 | int bushIndex = input.tex.x * 4096 + input.tex.y * nRadionColumns * 4096;
|
---|
| 42 | int werx = bushIndex % nRadionColumns;
|
---|
| 43 | int wery = bushIndex / nRadionColumns;
|
---|
| 44 | float3 pos = tex2D(radionSampler, float2((werx + 0.25) * dataColumnWidth, (wery + 0.5) / 4096.0) ).xyz;
|
---|
| 45 | float3 dir = tex2D(radionSampler, float2((werx + 0.75) * dataColumnWidth, (wery + 0.5) / 4096.0) ).xyz;
|
---|
| 46 |
|
---|
| 47 | float3 diff = lightPos - pos;
|
---|
| 48 | float dist2 = dot(diff, diff);
|
---|
| 49 | if(dist2 < SAMPLECUTDIST2)
|
---|
| 50 | dist2 = SAMPLECUTDIST2;
|
---|
| 51 | diff = normalize(diff);
|
---|
| 52 | float cosa = - dot(lightDir, diff);
|
---|
| 53 | float cosb = dot(dir, diff);
|
---|
| 54 |
|
---|
| 55 | float4 occProjPos = mul(float4(pos, 1), occWorldToProjMatrix);
|
---|
| 56 | occProjPos /= occProjPos.w;
|
---|
| 57 | float2 occTexPos = mul( occProjPos.xyw, occProjToTexMatrix);
|
---|
| 58 | float visibility = tex2Dlod(depthMapSampler, float4(occTexPos, occProjPos.z, 0) );
|
---|
| 59 |
|
---|
| 60 | float3 lightToPos = pos - lightPos;
|
---|
| 61 | float actualDepth = length(lightToPos);
|
---|
| 62 |
|
---|
| 63 | float ret;
|
---|
| 64 | if( visibility < 0.5 || cosa < 0 || cosb < 0)
|
---|
| 65 | ret = 0.0;
|
---|
| 66 | else
|
---|
| 67 | ret = pow(cosa, 9) * cosb / dist2;
|
---|
| 68 |
|
---|
| 69 | if(ret < 0.000001)
|
---|
| 70 | ret = 0.0;
|
---|
| 71 | // if(ret > WEIGHTCUTOFF)
|
---|
| 72 | // ret = WEIGHTCUTOFF;
|
---|
| 73 |
|
---|
| 74 | return float4(ret, ret, ret, ret);
|
---|
| 75 | // return float4((wery + 0.5) / 4096.0, werx, werx, 1);
|
---|
| 76 | // return float4(actualDepth, 1, 1, 1);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | technique ComputeWeights{
|
---|
| 80 | pass P0
|
---|
| 81 | {
|
---|
| 82 | VertexShader = compile vs_3_0 vsComputeWeights();
|
---|
| 83 | PixelShader = compile ps_3_0 psComputeWeights();
|
---|
| 84 | }
|
---|
| 85 | }
|
---|