-
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.
Merge branch 'dev-vertex-compression' into 'master'
Dev vertex compression 对于 point layer(circle) 压缩顶点数据 https://yuque.antfin-inc.com/yuqi.pyq/fgetpa/wxv543#xzVLo 优化后每个顶点只需要一个 vec4 存储颜色、pickingId 等数据: vec4(color, color, pickingId, (extrude.x, extrude.y, radius)) See merge request !31
- Loading branch information
Showing
6 changed files
with
98 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,46 @@ | ||
import { packUint8ToFloat } from '../../../util/vertex-compress'; | ||
|
||
const LEFT_SHIFT18 = 262144.0; | ||
const LEFT_SHIFT20 = 1048576.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, (4-bit extrude, 16-bit size), id) | ||
aPackedData.push( | ||
...packedColor, | ||
(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)); | ||
}); | ||
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,17 @@ | ||
#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); | ||
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; | ||
} |