fix(point-layer): adjust shift bits in vertex compression

This commit is contained in:
yuqi.pyq 2019-05-30 16:26:34 +08:00
parent ef2a9dd957
commit 865875d478
3 changed files with 17 additions and 23 deletions

View File

@ -1,10 +1,7 @@
import { packUint8ToFloat } from '../../../util/vertex-compress';
// const LEFT_SHIFT2 = 4.0;
// const LEFT_SHIFT4 = 16.0;
const LEFT_SHIFT8 = 256.0;
const LEFT_SHIFT10 = 1024.0;
// const LEFT_SHIFT12 = 4096.0;
const LEFT_SHIFT18 = 262144.0;
const LEFT_SHIFT20 = 1048576.0;
export default function circleBuffer(layerData) {
const index = [];
@ -29,14 +26,15 @@ export default function circleBuffer(layerData) {
[ 1, 1 ],
[ -1, 1 ]
].forEach(extrude => {
// vec4(color, color, (8-bit size, 4-bit extrude), id)
// vec4(color, color, (4-bit extrude, 16-bit size), id)
aPackedData.push(
...packedColor,
size + (extrude[0] + 1) * LEFT_SHIFT8 + (extrude[1] + 1) * LEFT_SHIFT10,
(extrude[0] + 1) * LEFT_SHIFT20 + (extrude[1] + 1) * LEFT_SHIFT18 + size,
id
);
});
// TODO如果使用相对瓦片坐标还可以进一步压缩
aPosition.push(...coordinates, ...coordinates, ...coordinates, ...coordinates);
index.push(...[ 0, 1, 2, 0, 2, 3 ].map(n => n + i * 4));
});

View File

@ -17,20 +17,20 @@ void main() {
// unpack picking_id
float picking_id = a_packed_data.w;
// unpack data(radius(8-bit), extrude(4-bit))
// unpack data(extrude(4-bit), radius(16-bit))
float compressed = a_packed_data.z;
// extrude(4-bit)
vec2 extrude;
extrude.y = floor(compressed * SHIFT_RIGHT10);
compressed -= extrude.y * SHIFT_LEFT10;
extrude.y = extrude.y - 1.;
extrude.x = floor(compressed * SHIFT_RIGHT8);
compressed -= extrude.x * SHIFT_LEFT8;
extrude.x = floor(compressed * SHIFT_RIGHT20);
compressed -= extrude.x * SHIFT_LEFT20;
extrude.x = extrude.x - 1.;
// radius(8-bit)
extrude.y = floor(compressed * SHIFT_RIGHT18);
compressed -= extrude.y * SHIFT_LEFT18;
extrude.y = extrude.y - 1.;
// radius(16-bit)
float radius = compressed;
v_radius = radius;

View File

@ -1,11 +1,7 @@
#define SHIFT_RIGHT2 0.25
#define SHIFT_RIGHT4 0.0625
#define SHIFT_RIGHT8 1.0 / 256.0
#define SHIFT_RIGHT10 1.0 / 1024.0
#define SHIFT_LEFT2 4.0
#define SHIFT_LEFT4 16.0
#define SHIFT_LEFT8 256.0
#define SHIFT_LEFT10 1024.0
#define SHIFT_RIGHT18 1.0 / 262144.0
#define SHIFT_RIGHT20 1.0 / 1048576.0
#define SHIFT_LEFT18 262144.0
#define SHIFT_LEFT20 1048576.0
vec2 unpack_float(const float packedValue) {
int packedIntValue = int(packedValue);