[896] | 1 | float4x4 modelToWorldMatrix;
|
---|
| 2 | float4x4 inverseTransposedModelToWorldMatrix;
|
---|
| 3 | float4x4 modelToProjMatrix;
|
---|
| 4 |
|
---|
| 5 | float4x4 occWorldToProjMatrix;
|
---|
| 6 | float3x3 occProjToTexMatrix;
|
---|
| 7 |
|
---|
| 8 | texture brdfMap; //material texture sampler
|
---|
| 9 | sampler2D brdfMapSampler = sampler_state{
|
---|
| 10 | texture = < brdfMap >;
|
---|
| 11 | MinFilter = LINEAR;
|
---|
| 12 | MagFilter = LINEAR;
|
---|
| 13 | MipFilter = None;
|
---|
| 14 | AddressU = Border;
|
---|
| 15 | AddressV = Wrap;
|
---|
| 16 | };
|
---|
| 17 |
|
---|
| 18 | texture filteredAtlas;
|
---|
| 19 | sampler filteredAtlasSampler = sampler_state
|
---|
| 20 | {
|
---|
| 21 | Texture = <filteredAtlas>;
|
---|
| 22 | MinFilter = LINEAR;
|
---|
| 23 | MagFilter = LINEAR;
|
---|
| 24 | MipFilter = None;
|
---|
| 25 | AddressU = Wrap;
|
---|
| 26 | AddressV = Wrap;
|
---|
| 27 | };
|
---|
| 28 |
|
---|
| 29 | texture depthMap;
|
---|
| 30 | sampler2D depthMapSampler = sampler_state{
|
---|
| 31 | texture = < depthMap >;
|
---|
| 32 | MinFilter = Linear;
|
---|
| 33 | MagFilter = Linear;
|
---|
| 34 | MipFilter = None;
|
---|
| 35 | AddressU = Border;
|
---|
| 36 | AddressV = Border;
|
---|
| 37 | BorderColor = float4(1, 1, 1, 1);
|
---|
| 38 | };
|
---|
| 39 |
|
---|
| 40 | float3 lightPos;
|
---|
| 41 | float3 lightDir;
|
---|
| 42 | float3 lightPower;
|
---|
| 43 |
|
---|
| 44 | float4 weightsa[8];
|
---|
| 45 | int4 indicesa[8];
|
---|
| 46 |
|
---|
| 47 | struct vsInputWalk
|
---|
| 48 | {
|
---|
| 49 | float4 pos : POSITION;
|
---|
| 50 | float3 normal : NORMAL;
|
---|
| 51 | float2 tex : TEXCOORD0;
|
---|
| 52 | };
|
---|
| 53 |
|
---|
| 54 | struct vsOutputWalk
|
---|
| 55 | {
|
---|
| 56 | float4 pos : POSITION;
|
---|
| 57 | float3 normal : NORMAL;
|
---|
| 58 | float2 tex : TEXCOORD0;
|
---|
| 59 | float4 worldPos : TEXCOORD1;
|
---|
| 60 | float4 occProjPos : TEXCOORD2;
|
---|
| 61 | };
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | vsOutputWalk
|
---|
| 65 | vsWalk(vsInputWalk input)
|
---|
| 66 | {
|
---|
| 67 | vsOutputWalk output = (vsOutputWalk)0;
|
---|
| 68 | output.pos = mul(input.pos, modelToProjMatrix);
|
---|
| 69 |
|
---|
| 70 | output.worldPos = mul(input.pos, modelToWorldMatrix);
|
---|
| 71 | output.occProjPos = mul(output.worldPos, occWorldToProjMatrix);
|
---|
| 72 |
|
---|
| 73 | output.normal = mul(float4(input.normal.xyz, 0.0), inverseTransposedModelToWorldMatrix);
|
---|
| 74 | output.tex = input.tex;
|
---|
| 75 |
|
---|
| 76 | return output;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 |
|
---|
| 80 | float4
|
---|
| 81 | psWalk(vsOutputWalk input) : COLOR
|
---|
| 82 | {
|
---|
| 83 | // return 1;
|
---|
| 84 |
|
---|
| 85 | float3 col = 0;
|
---|
| 86 | for(int iCluster=0; iCluster<8; iCluster++)
|
---|
| 87 | {
|
---|
| 88 | int4 index = indicesa[iCluster];
|
---|
| 89 | float4 weight = weightsa[iCluster];
|
---|
| 90 | float3 val = tex2D(filteredAtlasSampler, float2(
|
---|
| 91 | 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));
|
---|
| 92 | col += val.xyz * weight.x;
|
---|
| 93 | val = tex2D(filteredAtlasSampler, float2(
|
---|
| 94 | 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));
|
---|
| 95 | col += val.xyz * weight.y;
|
---|
| 96 | val = tex2D(filteredAtlasSampler, float2(
|
---|
| 97 | 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));
|
---|
| 98 | col += val.xyz * weight.z;
|
---|
| 99 | val = tex2D(filteredAtlasSampler, float2(
|
---|
| 100 | 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));
|
---|
| 101 | col += val.xyz * weight.w;
|
---|
| 102 | }
|
---|
| 103 | // col *= 1000.01;
|
---|
| 104 | // col *= 0.0001;
|
---|
| 105 | // col = 0;
|
---|
| 106 |
|
---|
| 107 | input.normal = normalize(input.normal);
|
---|
| 108 |
|
---|
| 109 | input.occProjPos /= input.occProjPos.w;
|
---|
| 110 | float2 occTexPos = mul(input.occProjPos.xyw, occProjToTexMatrix);
|
---|
| 111 | float3 toLight = lightPos - input.worldPos;
|
---|
| 112 | float3 toLightDir = normalize(lightPos - input.worldPos);
|
---|
| 113 | float cosa = dot(input.normal, toLightDir);
|
---|
| 114 | float cosb = dot(lightDir, -toLightDir);
|
---|
| 115 |
|
---|
| 116 | float visibility = tex2Dlod(depthMapSampler, float4(occTexPos, input.occProjPos.z, 0));
|
---|
| 117 | if(cosa > 0 && cosb > 0.0)
|
---|
| 118 | col += cosa.xxx * pow(cosb, 9) * visibility / dot(toLight, toLight);
|
---|
| 119 | return float4(lightPower * col * tex2D(brdfMapSampler, input.tex), 1);
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | technique walk{
|
---|
| 123 | pass P0
|
---|
| 124 | {
|
---|
| 125 | VertexShader = compile vs_3_0 vsWalk();
|
---|
| 126 | PixelShader = compile ps_3_0 psWalk();
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | #include "bushToAtlas.fx"
|
---|
| 131 | #include "showTex.fx"
|
---|
| 132 | #include "computeWeights.fx"
|
---|
| 133 | #include "depthMap.fx"
|
---|
| 134 | #include "dots.fx" |
---|