[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 |
|
---|
| 46 | struct vsInputWalk
|
---|
| 47 | {
|
---|
| 48 | float4 pos : POSITION;
|
---|
| 49 | float3 normal : NORMAL;
|
---|
| 50 | float2 tex : TEXCOORD0;
|
---|
| 51 | };
|
---|
| 52 |
|
---|
| 53 | struct vsOutputWalk
|
---|
| 54 | {
|
---|
| 55 | float4 pos : POSITION;
|
---|
| 56 | float3 normal : NORMAL;
|
---|
| 57 | float2 tex : TEXCOORD0;
|
---|
| 58 | float4 worldPos : TEXCOORD1;
|
---|
| 59 | float4 occProjPos : TEXCOORD2;
|
---|
| 60 | };
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | vsOutputWalk
|
---|
| 64 | vsWalk(vsInputWalk input)
|
---|
| 65 | {
|
---|
| 66 | vsOutputWalk output = (vsOutputWalk)0;
|
---|
| 67 | output.pos = mul(input.pos, modelToProjMatrix);
|
---|
| 68 |
|
---|
| 69 | output.worldPos = mul(input.pos, modelToWorldMatrix);
|
---|
| 70 | output.occProjPos = mul(output.worldPos, occWorldToProjMatrix);
|
---|
| 71 |
|
---|
[1480] | 72 | output.normal = mul(inverseTransposedModelToWorldMatrix, float4(input.normal.xyz, 0.0));
|
---|
[896] | 73 | output.tex = input.tex;
|
---|
| 74 |
|
---|
| 75 | return output;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 | float4
|
---|
| 80 | psWalk(vsOutputWalk input) : COLOR
|
---|
| 81 | {
|
---|
| 82 | // return 1;
|
---|
| 83 |
|
---|
| 84 | float3 col = 0;
|
---|
[1480] | 85 | for(int iCluster=0; iCluster<32; iCluster++)
|
---|
[896] | 86 | {
|
---|
[1480] | 87 | float4 weight = weightsa[iCluster/4];
|
---|
[896] | 88 | float3 val = tex2D(filteredAtlasSampler, float2(
|
---|
[1480] | 89 | input.tex.x / 32.0 + 1.0 / 32.0 * (iCluster % 32) + 0.0 / 4096.0, 1.0 - input.tex.y + 0.0 / 128.0));
|
---|
[896] | 90 | col += val.xyz * weight.x;
|
---|
[1480] | 91 | iCluster++;
|
---|
| 92 |
|
---|
[896] | 93 | val = tex2D(filteredAtlasSampler, float2(
|
---|
[1480] | 94 | input.tex.x / 32.0 + 1.0 / 32.0 * (iCluster % 32) + 0.0 / 4096.0, 1.0 - input.tex.y + 0.0 / 128.0));
|
---|
[896] | 95 | col += val.xyz * weight.y;
|
---|
[1480] | 96 | iCluster++;
|
---|
| 97 |
|
---|
[896] | 98 | val = tex2D(filteredAtlasSampler, float2(
|
---|
[1480] | 99 | input.tex.x / 32.0 + 1.0 / 32.0 * (iCluster % 32) + 0.0 / 4096.0, 1.0 - input.tex.y + 0.0 / 128.0));
|
---|
[896] | 100 | col += val.xyz * weight.z;
|
---|
[1480] | 101 | iCluster++;
|
---|
| 102 |
|
---|
[896] | 103 | val = tex2D(filteredAtlasSampler, float2(
|
---|
[1480] | 104 | input.tex.x / 32.0 + 1.0 / 32.0 * (iCluster % 32) + 0.0 / 4096.0, 1.0 - input.tex.y + 0.0 / 128.0));
|
---|
[896] | 105 | col += val.xyz * weight.w;
|
---|
| 106 | }
|
---|
| 107 | // col *= 1000.01;
|
---|
[1480] | 108 | // col *= 0.8;
|
---|
[896] | 109 | // col = 0;
|
---|
| 110 |
|
---|
| 111 | input.normal = normalize(input.normal);
|
---|
| 112 |
|
---|
| 113 | input.occProjPos /= input.occProjPos.w;
|
---|
| 114 | float2 occTexPos = mul(input.occProjPos.xyw, occProjToTexMatrix);
|
---|
| 115 | float3 toLight = lightPos - input.worldPos;
|
---|
| 116 | float3 toLightDir = normalize(lightPos - input.worldPos);
|
---|
| 117 | float cosa = dot(input.normal, toLightDir);
|
---|
| 118 | float cosb = dot(lightDir, -toLightDir);
|
---|
| 119 |
|
---|
| 120 | float visibility = tex2Dlod(depthMapSampler, float4(occTexPos, input.occProjPos.z, 0));
|
---|
| 121 | if(cosa > 0 && cosb > 0.0)
|
---|
| 122 | col += cosa.xxx * pow(cosb, 9) * visibility / dot(toLight, toLight);
|
---|
| 123 | return float4(lightPower * col * tex2D(brdfMapSampler, input.tex), 1);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | technique walk{
|
---|
| 127 | pass P0
|
---|
| 128 | {
|
---|
| 129 | VertexShader = compile vs_3_0 vsWalk();
|
---|
| 130 | PixelShader = compile ps_3_0 psWalk();
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | #include "bushToAtlas.fx"
|
---|
| 135 | #include "showTex.fx"
|
---|
| 136 | #include "computeWeights.fx"
|
---|
| 137 | #include "depthMap.fx"
|
---|
[1480] | 138 | #include "dots.fx"
|
---|
| 139 | #include "torch.tx" |
---|