1 | uniform float4x4 WorldViewProj;
|
---|
2 | uniform float4 prmAtlasTilesHalfPixel;
|
---|
3 | uniform sampler2D filteredAtlasSampler : register(s0);
|
---|
4 | uniform sampler1D clusterWeightIndexSampler : register(s1);
|
---|
5 | uniform sampler2D clusterWeightSampler : register(s2);
|
---|
6 | uniform float allClusterCount;
|
---|
7 | uniform float clusterCount; //clustercount / 4
|
---|
8 | //uniform float weights[32];
|
---|
9 |
|
---|
10 | struct vsInputWalk
|
---|
11 | {
|
---|
12 | float4 pos : POSITION;
|
---|
13 | float2 tex : TEXCOORD0;
|
---|
14 | float2 texAtlas : TEXCOORD1;
|
---|
15 | };
|
---|
16 |
|
---|
17 | struct vsOutputWalk
|
---|
18 | {
|
---|
19 | float4 pos : POSITION;
|
---|
20 | float2 tex : TEXCOORD0;
|
---|
21 | float2 texAtlas : TEXCOORD1;
|
---|
22 | };
|
---|
23 |
|
---|
24 |
|
---|
25 | vsOutputWalk vsWalk(vsInputWalk input)
|
---|
26 | {
|
---|
27 | vsOutputWalk output = (vsOutputWalk)0;
|
---|
28 | output.pos = mul(WorldViewProj, input.pos);
|
---|
29 | output.tex = input.tex;
|
---|
30 | output.texAtlas = input.texAtlas;
|
---|
31 | return output;
|
---|
32 | }
|
---|
33 |
|
---|
34 | float4 psWalk(vsOutputWalk input) : COLOR
|
---|
35 | {
|
---|
36 | int2 prmAtlasTiles = prmAtlasTilesHalfPixel.xy;
|
---|
37 | float2 atlasHalfPixel = prmAtlasTilesHalfPixel.zw;
|
---|
38 |
|
---|
39 | float3 col = 0;
|
---|
40 | for(int iCluster=0; iCluster<16; iCluster++)
|
---|
41 | {
|
---|
42 | float2 prmTexPos = float2(
|
---|
43 | (input.texAtlas.x + (iCluster % prmAtlasTiles.x)) / prmAtlasTiles.x,
|
---|
44 | 1.0 - (input.texAtlas.y + (iCluster / prmAtlasTiles.x)) / prmAtlasTiles.y) + atlasHalfPixel;
|
---|
45 |
|
---|
46 | //float4 weight = 0.065;
|
---|
47 | //weight = float4(weights[iCluster/4], weights[iCluster/4 + 1],weights[iCluster/4 + 2], weights[iCluster/4 + 3]);
|
---|
48 | //float4 weight = weights[iCluster/4];
|
---|
49 | float4 weightIndex = tex1D(clusterWeightIndexSampler, ((float)iCluster/4) / clusterCount).r / allClusterCount;
|
---|
50 | float weight1 = tex2D(clusterWeightSampler, float2(weightIndex.r, 0.5)).r;
|
---|
51 | float weight2 = tex2D(clusterWeightSampler, float2(weightIndex.g, 0.5)).r;
|
---|
52 | float weight3 = tex2D(clusterWeightSampler, float2(weightIndex.b, 0.5)).r;
|
---|
53 | float weight4 = tex2D(clusterWeightSampler, float2(weightIndex.a, 0.5)).r;
|
---|
54 | float4 weight = float4(weight1, weight2, weight3, weight4);
|
---|
55 |
|
---|
56 | float3 val = tex2D(filteredAtlasSampler, prmTexPos);
|
---|
57 | col += val.xyz * weight.x;
|
---|
58 | iCluster++;
|
---|
59 |
|
---|
60 | prmTexPos.x += 1.0 / prmAtlasTiles.x;
|
---|
61 | val = tex2D(filteredAtlasSampler, prmTexPos);
|
---|
62 | col += val.xyz * weight.y;
|
---|
63 | iCluster++;
|
---|
64 |
|
---|
65 | prmTexPos.x += 1.0 / prmAtlasTiles.x;
|
---|
66 | val = tex2D(filteredAtlasSampler, prmTexPos);
|
---|
67 | col += val.xyz * weight.z;
|
---|
68 | iCluster++;
|
---|
69 |
|
---|
70 | prmTexPos.x += 1.0 / prmAtlasTiles.x;
|
---|
71 | val = tex2D(filteredAtlasSampler, prmTexPos);
|
---|
72 | col += val.xyz * weight.w;
|
---|
73 | }
|
---|
74 |
|
---|
75 | //return col.xxxx *0.00001 + tex2D(filteredAtlasSampler, float2(input.texAtlas.x /32.0f, 1.0 - input.texAtlas.y));
|
---|
76 | //return float4(1,0,0,1)+col.xxxx*0.0000000001;
|
---|
77 | //return prmAtlasTilesHalfPixel.x*allClusterCount*clusterCount*0.000000000001 + tex2D(filteredAtlasSampler, float2(input.texAtlas.x /32.0f, 1.0 - input.texAtlas.y)).r;
|
---|
78 | return float4(col, 1);
|
---|
79 | }
|
---|
80 |
|
---|