float4x4 modelToWorldMatrix; float4x4 inverseTransposedModelToWorldMatrix; float4x4 modelToProjMatrix; float4x4 occWorldToProjMatrix; float3x3 occProjToTexMatrix; int2 prmAtlasTiles; float2 atlasHalfPixel; texture brdfMap; //material texture sampler sampler2D brdfMapSampler = sampler_state{ texture = < brdfMap >; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = None; AddressU = Wrap; AddressV = Wrap; }; texture bumpMap; //material texture sampler sampler2D bumpMapSampler = sampler_state{ texture = < bumpMap >; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = None; AddressU = Wrap; AddressV = Wrap; }; texture normalMap; //material texture sampler sampler2D normalMapSampler = sampler_state{ texture = < normalMap >; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = None; AddressU = Wrap; 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 = Clamp; AddressV = Clamp; // AddressU = Border; // AddressV = Border; // BorderColor = float4(65535, 65535, 65535, 65535); }; float3 lightPos; float3 lightDir; float3 lightPower; float4 weightsa[8]; struct vsInputWalk { float4 pos : POSITION; float3 normal : NORMAL; float2 tex : TEXCOORD0; float2 texAtlas : TEXCOORD1; float3 tangent : TEXCOORD2; float3 binormal : TEXCOORD3; }; struct vsOutputWalk { float4 pos : POSITION; float3 normal : NORMAL; float3 tangent : TEXCOORD4; float3 binormal : TEXCOORD5; float2 tex : TEXCOORD0; float2 texAtlas : TEXCOORD1; float4 worldPos : TEXCOORD2; float4 occProjPos : TEXCOORD3; }; 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(inverseTransposedModelToWorldMatrix, float4(input.normal.xyz, 0.0)); output.tangent = mul(inverseTransposedModelToWorldMatrix, float4(input.tangent.xyz, 0.0)); output.binormal = mul(inverseTransposedModelToWorldMatrix, float4(input.binormal.xyz, 0.0)); output.tex = input.tex; output.texAtlas = input.texAtlas; return output; } float4 psWalk(vsOutputWalk input) : COLOR { float3 col = 0; for(int iCluster=0; iCluster<32; iCluster++) { float2 prmTexPos = float2( (input.texAtlas.x + (iCluster % prmAtlasTiles.x)) / prmAtlasTiles.x, 1.0 - (input.texAtlas.y + (iCluster / prmAtlasTiles.x)) / prmAtlasTiles.y) + atlasHalfPixel; float4 weight = weightsa[iCluster/4]; //weight = 0.065; float3 val = tex2D(filteredAtlasSampler, prmTexPos); col += val.xyz * weight.x; iCluster++; prmTexPos.x += 1.0 / prmAtlasTiles.x; val = tex2D(filteredAtlasSampler, prmTexPos); col += val.xyz * weight.y; iCluster++; prmTexPos.x += 1.0 / prmAtlasTiles.x; val = tex2D(filteredAtlasSampler, prmTexPos); col += val.xyz * weight.z; iCluster++; prmTexPos.x += 1.0 / prmAtlasTiles.x; val = tex2D(filteredAtlasSampler, prmTexPos); col += val.xyz * weight.w; } // col *= 1000.01; // col *= 0.8; // col = 0; // get tangent space normal vector /* float3 tNormal = tex2D(normalMapSampler, input.tex).rgb; // which is the transpose of ModelToTangent float3 mNormal = normalize( input.tangent * tNormal.x + input.binormal * tNormal.y + input.normal * tNormal.z ); input.normal = mNormal; */ // return float4(input.normal, 1); 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 = tex2Dproj(depthMapSampler, float4(occTexPos, input.occProjPos.z, 1)); if(cosa > 0 && cosb > 0.0) col += cosa.xxx * pow(cosb, 9) * visibility / dot(toLight, toLight); // return float4(input.tangent,1); // return tex2D(filteredAtlasSampler, float2(input.texAtlas.x / 32.0, 1.0 - input.texAtlas.y)); return float4( lightPower * col * tex2D(brdfMapSampler, input.tex) , 1); // return float4(lightPower * col * tex2D(bumpMapSampler, input.tex), 1); } float4 psWalkIndirect(vsOutputWalk input) : COLOR { float3 col = 0; for(int iCluster=0; iCluster<32; iCluster++) { float2 prmTexPos = float2( (input.texAtlas.x + (iCluster % prmAtlasTiles.x)) / prmAtlasTiles.x, 1.0 - (input.texAtlas.y + (iCluster / prmAtlasTiles.x)) / prmAtlasTiles.y) + atlasHalfPixel; float4 weight = weightsa[iCluster/4]; // weight = 0.065; float3 val = tex2D(filteredAtlasSampler, prmTexPos); col += val.xyz * weight.x; iCluster++; prmTexPos.x += 1.0 / prmAtlasTiles.x; val = tex2D(filteredAtlasSampler, prmTexPos); col += val.xyz * weight.y; iCluster++; prmTexPos.x += 1.0 / prmAtlasTiles.x; val = tex2D(filteredAtlasSampler, prmTexPos); col += val.xyz * weight.z; iCluster++; prmTexPos.x += 1.0 / prmAtlasTiles.x; val = tex2D(filteredAtlasSampler, prmTexPos); col += val.xyz * weight.w; } return float4( lightPower * col * tex2D(brdfMapSampler, input.tex) , 1); // return float4( lightPower * col, 1); } float4 psWalkDirect(vsOutputWalk input) : COLOR { float3 col = 0; 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 = tex2Dproj(depthMapSampler, float4(occTexPos, input.occProjPos.z, 1)); 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); } float4 psWalkAmbient(vsOutputWalk input) : COLOR { float3 col = 0.0001; 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 = tex2Dproj(depthMapSampler, float4(occTexPos, input.occProjPos.z, 1)); 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(); } } technique walkIndirect{ pass P0 { VertexShader = compile vs_3_0 vsWalk(); PixelShader = compile ps_3_0 psWalkIndirect(); } } technique walkAmbient{ pass P0 { VertexShader = compile vs_3_0 vsWalk(); PixelShader = compile ps_3_0 psWalkAmbient(); } } technique walkDirect{ pass P0 { VertexShader = compile vs_3_0 vsWalk(); PixelShader = compile ps_3_0 psWalkDirect(); } } #include "bushToAtlas.fx" #include "normalize.fx" #include "showTex.fx" #include "computeWeights.fx" #include "depthMap.fx" #include "dots.fx" #include "torch.tx"