Skip to content

Commit

Permalink
fix(core): 32 instead of 24 bits for uniqueId in picking
Browse files Browse the repository at this point in the history
Using uint, not float for uniqueIds in shaders. Related to #218
  • Loading branch information
tuner committed Feb 22, 2024
1 parent 17e92fc commit 7ae8b7c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
9 changes: 4 additions & 5 deletions packages/core/src/genomeSpy.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,10 @@ export default class GenomeSpy {
const pixelValue = this._glHelper.readPickingPixel(x, y);

const uniqueId =
pixelValue[0] | (pixelValue[1] << 8) | (pixelValue[2] << 16);
pixelValue[0] |
(pixelValue[1] << 8) |
(pixelValue[2] << 16) |
(pixelValue[3] << 24);

if (uniqueId == 0) {
this._currentHover = null;
Expand All @@ -834,10 +837,6 @@ export default class GenomeSpy {
}

if (!this._currentHover) {
// We are doing an exhaustive search of the data. This is a bit slow with
// millions of items.
// TODO: Optimize by indexing or something

this.viewRoot.visit((view) => {
if (view instanceof UnitView) {
if (
Expand Down
13 changes: 8 additions & 5 deletions packages/core/src/gl/dataToVertices.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ export class GeometryBuilder {
f,
numComponents: largeHp ? 2 : 1,
arrayReference: largeHp ? largeHpArray : undefined,
targetArrayType: isDiscrete(ce.scale.type)
? Uint16Array
: hp
? Uint32Array
: Float32Array,
targetArrayType:
channel == "uniqueId"
? Uint32Array
: isDiscrete(ce.scale.type)
? Uint16Array
: hp
? Uint32Array
: Float32Array,
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/gl/glslScaleGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function generateScaleGlsl(
? "uvec2"
: hp
? "uint"
: discrete
: discrete || channel == "uniqueId"
? "uint"
: "float";

Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/gl/includes/picking.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ out highp vec4 vPickingColor;
bool setupPicking() {
if (uPickingEnabled) {
#ifdef uniqueId_DEFINED
int id = int(getScaled_uniqueId());
// TODO: Take the sign bit into account
uint id = attr_uniqueId;
vPickingColor = vec4(
ivec4(id >> 0, id >> 8, id >> 16, 0xFF) & 0xFF
ivec4(id >> 0, id >> 8, id >> 16, id >> 24) & 0xFF
) / float(0xFF);
#else
vPickingColor = vec4(1.0);
Expand Down

0 comments on commit 7ae8b7c

Please sign in to comment.