-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(point-layer): vertex compression
- Loading branch information
Showing
6 changed files
with
104 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,48 @@ | ||
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; | ||
|
||
export default function circleBuffer(layerData) { | ||
const index = []; | ||
const aExtrude = []; | ||
const aRadius = []; | ||
const aColor = []; | ||
const aPickingId = []; | ||
const aPosition = []; | ||
const aPackedData = []; | ||
layerData.forEach(({ size = 0, color, id, coordinates }, i) => { | ||
|
||
if (isNaN(size)) { | ||
size = 0; | ||
} | ||
|
||
// pack color(vec4) into vec2 | ||
const packedColor = [ | ||
packUint8ToFloat(color[0] * 255, color[1] * 255), | ||
packUint8ToFloat(color[2] * 255, color[3] * 255) | ||
]; | ||
|
||
// construct point coords | ||
aExtrude.push(-1, -1, 1, -1, 1, 1, -1, 1); | ||
aRadius.push(size, size, size, size); | ||
aColor.push(...color, ...color, ...color, ...color); | ||
aPickingId.push(id, id, id, id); | ||
[ | ||
[ -1, -1 ], | ||
[ 1, -1 ], | ||
[ 1, 1 ], | ||
[ -1, 1 ] | ||
].forEach(extrude => { | ||
// vec4(color, color, (8-bit size, 4-bit extrude), id) | ||
aPackedData.push( | ||
...packedColor, | ||
size + (extrude[0] + 1) * LEFT_SHIFT8 + (extrude[1] + 1) * LEFT_SHIFT10, | ||
id | ||
); | ||
}); | ||
|
||
aPosition.push(...coordinates, ...coordinates, ...coordinates, ...coordinates); | ||
index.push(...[ 0, 1, 2, 0, 2, 3 ].map(n => n + i * 4)); | ||
}); | ||
return { | ||
aExtrude, | ||
aRadius, | ||
aColor, | ||
aPickingId, | ||
aPosition, | ||
index | ||
index, | ||
aPackedData | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#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 | ||
|
||
vec2 unpack_float(const float packedValue) { | ||
int packedIntValue = int(packedValue); | ||
int v0 = packedIntValue / 256; | ||
return vec2(v0, packedIntValue - v0 * 256); | ||
} | ||
|
||
vec4 decode_color(const vec2 encodedColor) { | ||
return vec4( | ||
unpack_float(encodedColor[0]) / 255.0, | ||
unpack_float(encodedColor[1]) / 255.0 | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import clamp from '@antv/util/lib/clamp'; | ||
|
||
/** | ||
* encode 2 8-bit unsigned int into a 16-bit float | ||
* @param {number} a 8-bit int | ||
* @param {number} b 8-bit int | ||
* @return {number} float | ||
*/ | ||
export function packUint8ToFloat(a, b) { | ||
a = clamp(Math.floor(a), 0, 255); | ||
b = clamp(Math.floor(b), 0, 255); | ||
return 256 * a + b; | ||
} |