#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.pos + 1.0) / 2.0; output.tex.y = 1.0 - output.tex.y; //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 = tex2Dproj(depthMapSampler, float4(occTexPos, occProjPos.z - 0.1, 1) ); 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; */ float3 diff = lightPos - pos; float dist2 = dot(diff, diff); if(dist2 < SAMPLECUTDIST2) dist2 = SAMPLECUTDIST2; diff = normalize(diff); float cosa = max(dot(lightDir, -diff), 0); float cosb = max(dot(dir, diff), 0); float ret = pow(cosa, 9) * cosb / dist2; return ret; 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(); } } /* float4 psAggregateWeights(vsOutputComputeWeights input, in int rid : VPOS) : COLOR0 { float sumWeight = 0.0; float sumProb = 0.0000001; int iRadion = clusterStarts[rid]; float2 wTex = float2((iRadion / 4096 + 0.5) * dataColumnWidth, (iRadion % 4096 + 0.5) / 4096.0) ); while(iRadion < clusterStarts[rid+1]) { sumWeight += tex2Dlod(weightSampler, float4(wTex, 0, 1)); float sumProb += 1.0; wTex.y += 1.0 / 4096.0; } return (sumWeight / sumProb).xxxx; } technique AggregateWeights{ pass P0 { VertexShader = compile vs_3_0 vsComputeWeights(); PixelShader = compile ps_3_0 psAggregateWeights(); } } */