#define SAMPLECUTDIST2 0.01 #define WEIGHTCUTOFF 0.01 int nRadionColumns; texture radions; sampler radionSampler = sampler_state { Texture = ; MinFilter = Point; MagFilter = Point; MipFilter = None; }; struct vsInputComputeWeights { float4 pos : POSITION; float2 tex : TEXCOORD0; }; struct vsOutputComputeWeights { float4 pos : POSITION; float2 tex : TEXCOORD0; }; vsOutputComputeWeights vsComputeWeights(vsInputComputeWeights input) { vsOutputComputeWeights output = (vsOutputComputeWeights)0; output.pos = input.pos; output.tex = input.tex; return output; } float4 psComputeWeights(vsOutputComputeWeights input) : COLOR0 { float dataColumnWidth = 1.0 / (float)nRadionColumns; int bushIndex = input.tex.x * 4096 + input.tex.y * nRadionColumns * 4096; int werx = bushIndex % nRadionColumns; int wery = bushIndex / nRadionColumns; float3 pos = tex2D(radionSampler, float2((werx + 0.25) * dataColumnWidth, (wery + 0.5) / 4096.0) ).xyz; float3 dir = tex2D(radionSampler, float2((werx + 0.75) * dataColumnWidth, (wery + 0.5) / 4096.0) ).xyz; float3 diff = lightPos - pos; float dist2 = dot(diff, diff); if(dist2 < SAMPLECUTDIST2) dist2 = SAMPLECUTDIST2; diff = normalize(diff); float cosa = - dot(lightDir, diff); float cosb = dot(dir, diff); float4 occProjPos = mul(float4(pos, 1), occWorldToProjMatrix); occProjPos /= occProjPos.w; float2 occTexPos = mul( occProjPos.xyw, occProjToTexMatrix); float visibility = tex2Dlod(depthMapSampler, float4(occTexPos, occProjPos.z, 0) ); float3 lightToPos = pos - lightPos; float actualDepth = length(lightToPos); float ret; if( visibility < 0.5 || cosa < 0 || cosb < 0) ret = 0.0; else ret = pow(cosa, 9) * cosb / dist2; if(ret < 0.000001) ret = 0.0; // if(ret > WEIGHTCUTOFF) // ret = WEIGHTCUTOFF; return float4(ret, ret, ret, ret); // return float4((wery + 0.5) / 4096.0, werx, werx, 1); // return float4(actualDepth, 1, 1, 1); } technique ComputeWeights{ pass P0 { VertexShader = compile vs_3_0 vsComputeWeights(); PixelShader = compile ps_3_0 psComputeWeights(); } }