float4x4 modelToWorldMatrix; float4x4 inverseTransposedModelToWorldMatrix; float4x4 modelToProjMatrix; float4x4 occWorldToProjMatrix; float3x3 occProjToTexMatrix; texture brdfMap; //material texture sampler sampler2D brdfMapSampler = sampler_state{ texture = < brdfMap >; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = None; AddressU = Border; AddressV = Wrap; }; texture filteredAtlas; sampler filteredAtlasSampler = sampler_state { Texture = ; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = None; AddressU = Wrap; AddressV = Wrap; }; texture depthMap; sampler2D depthMapSampler = sampler_state{ texture = < depthMap >; MinFilter = Linear; MagFilter = Linear; MipFilter = None; AddressU = Border; AddressV = Border; BorderColor = float4(1, 1, 1, 1); }; float3 lightPos; float3 lightDir; float3 lightPower; float4 weightsa[8]; int4 indicesa[8]; struct vsInputWalk { float4 pos : POSITION; float3 normal : NORMAL; float2 tex : TEXCOORD0; }; struct vsOutputWalk { float4 pos : POSITION; float3 normal : NORMAL; float2 tex : TEXCOORD0; float4 worldPos : TEXCOORD1; float4 occProjPos : TEXCOORD2; }; vsOutputWalk vsWalk(vsInputWalk input) { vsOutputWalk output = (vsOutputWalk)0; output.pos = mul(input.pos, modelToProjMatrix); output.worldPos = mul(input.pos, modelToWorldMatrix); output.occProjPos = mul(output.worldPos, occWorldToProjMatrix); output.normal = mul(float4(input.normal.xyz, 0.0), inverseTransposedModelToWorldMatrix); output.tex = input.tex; return output; } float4 psWalk(vsOutputWalk input) : COLOR { // return 1; float3 col = 0; for(int iCluster=0; iCluster<8; iCluster++) { int4 index = indicesa[iCluster]; float4 weight = weightsa[iCluster]; float3 val = tex2D(filteredAtlasSampler, float2( input.tex.x / 32.0 + 1.0 / 32.0 * (index.x % 32) + 0.0 / 4096.0, 1.0 - input.tex.y + 0.0 / 128.0)); col += val.xyz * weight.x; val = tex2D(filteredAtlasSampler, float2( input.tex.x / 32.0 + 1.0 / 32.0 * (index.y % 32) + 0.0 / 4096.0, 1.0 - input.tex.y + 0.0 / 128.0)); col += val.xyz * weight.y; val = tex2D(filteredAtlasSampler, float2( input.tex.x / 32.0 + 1.0 / 32.0 * (index.z % 32) + 0.0 / 4096.0, 1.0 - input.tex.y + 0.0 / 128.0)); col += val.xyz * weight.z; val = tex2D(filteredAtlasSampler, float2( input.tex.x / 32.0 + 1.0 / 32.0 * (index.w % 32) + 0.0 / 4096.0, 1.0 - input.tex.y + 0.0 / 128.0)); col += val.xyz * weight.w; } // col *= 1000.01; // col *= 0.0001; // col = 0; input.normal = normalize(input.normal); input.occProjPos /= input.occProjPos.w; float2 occTexPos = mul(input.occProjPos.xyw, occProjToTexMatrix); float3 toLight = lightPos - input.worldPos; float3 toLightDir = normalize(lightPos - input.worldPos); float cosa = dot(input.normal, toLightDir); float cosb = dot(lightDir, -toLightDir); float visibility = tex2Dlod(depthMapSampler, float4(occTexPos, input.occProjPos.z, 0)); if(cosa > 0 && cosb > 0.0) col += cosa.xxx * pow(cosb, 9) * visibility / dot(toLight, toLight); return float4(lightPower * col * tex2D(brdfMapSampler, input.tex), 1); } technique walk{ pass P0 { VertexShader = compile vs_3_0 vsWalk(); PixelShader = compile ps_3_0 psWalk(); } } #include "bushToAtlas.fx" #include "showTex.fx" #include "computeWeights.fx" #include "depthMap.fx" #include "dots.fx"