#define SAMPLECUTDIST2 0.01 #define WEIGHTCUTOFF 0.01 uniform int nRadionColumns; uniform sampler2D radionSampler : register(s0); uniform sampler2D entryPointCountSampler : register(s1); uniform sampler2D allWeightsSampler : register(s2); uniform float3 lightPos; uniform float3 lightDir; uniform float clusterCount; 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 = max(dot(lightDir, -diff), 0); float cosb = max(dot(dir, diff), 0); /* 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 visibility = 1; float4 ret = cosa * cosb; //return float4(lightDir + ret.x * 0.00000000001, 1); return ret; //return ret.x*0.0000000001 + 0.5; } float4 psSumWeights(vsOutputComputeWeights input) : COLOR0 { float halfPixel = 0.5 / clusterCount; float iCluster = input.tex.x + halfPixel; int entryPointCount = tex2D(entryPointCountSampler, float2(iCluster, 0.25)); int currentEntryPoint = tex2D(entryPointCountSampler, float2(iCluster, 0.75)); //sum entrypoint weights float weight = 0; float clusterRad = 0; for(int i = 0; i < entryPointCount; i++) { float hp = float2(0.5 / (float) nRadionColumns, 0.5 / 4096.0); float2 coord1 = float2((float)(currentEntryPoint % nRadionColumns) / (float) nRadionColumns, currentEntryPoint / (float) nRadionColumns / 4096.0) + hp; coord1.y = 1.0 - coord1.y; float2 coord2 = coord1 + float2(hp.x / 2.0, 0); float radrad = tex2Dlod(radionSampler, float4(coord2, 0, 0)).a; //weight += tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).r * radrad; weight += tex2Dlod(allWeightsSampler, float4(coord1, 0, 0)).r; //clusterRad += radrad; currentEntryPoint++; } /* if(clusterRad >= 0) weight /= clusterRad; else weight = 0;*/ weight /= (float) entryPointCount; return weight; }