forked from keplergl/kepler.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Xun Li <[email protected]>
- Loading branch information
Showing
3 changed files
with
426 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
src/deckgl-layers/src/deckgl-extensions/filter-arrow-layer.ts
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,57 @@ | ||
import {Layer, LayerExtension} from '@deck.gl/core'; | ||
import {LayerContext} from '@deck.gl/core/lib/layer'; | ||
import GL from '@luma.gl/constants'; | ||
|
||
import shaderModule from './filter-shader-module'; | ||
|
||
const VALUE_FILTERED = 1; | ||
|
||
const defaultProps = { | ||
getFiltered: {type: 'accessor', value: VALUE_FILTERED} | ||
}; | ||
|
||
export type FilterArrowExtensionProps = { | ||
getFiltered?: () => number; | ||
}; | ||
|
||
/** | ||
* FilterArrowExtension - a deck.gl extension to filter arrow layer | ||
* | ||
* A simple extension to filter arrow layer based on the result of CPU filteredIndex, | ||
* so we can avoid filtering on the raw Arrow table and recreating geometry attributes. | ||
* Specifically, an attribute `filtered` is added to the layer to indicate whether the feature has been Filtered | ||
* the shader module is modified to discard the feature if filtered value is 0 | ||
* the accessor getFiltered is used to get the value of `filtered` based on the value `filteredIndex` in Arrowlayer | ||
*/ | ||
export default class FilterArrowExtension extends LayerExtension { | ||
static defaultProps = defaultProps; | ||
static extensionName = 'FilterArrowExtension'; | ||
|
||
getShaders(extension: any) { | ||
return { | ||
modules: [shaderModule], | ||
defines: {} | ||
}; | ||
} | ||
|
||
initializeState(this: Layer<FilterArrowExtensionProps>, context: LayerContext, extension: this) { | ||
const attributeManager = this.getAttributeManager(); | ||
if (attributeManager) { | ||
attributeManager.add({ | ||
filtered: { | ||
size: 1, | ||
type: GL.FLOAT, | ||
accessor: 'getFiltered', | ||
shaderAttributes: { | ||
filtered: { | ||
divisor: 0 | ||
}, | ||
instanceFiltered: { | ||
divisor: 1 | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/deckgl-layers/src/deckgl-extensions/filter-shader-module.ts
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,39 @@ | ||
import {project} from '@deck.gl/core'; | ||
|
||
const vs = ` | ||
#ifdef NON_INSTANCED_MODEL | ||
#define FILTER_ARROW_ATTRIB filtered | ||
#else | ||
#define FILTER_ARROW_ATTRIB instanceFiltered | ||
#endif | ||
attribute float FILTER_ARROW_ATTRIB; | ||
`; | ||
|
||
const fs = ``; | ||
|
||
const inject = { | ||
'vs:#decl': ` | ||
varying float is_filtered; | ||
`, | ||
'vs:#main-end': ` | ||
is_filtered = FILTER_ARROW_ATTRIB; | ||
`, | ||
'fs:#decl': ` | ||
varying float is_filtered; | ||
`, | ||
'fs:DECKGL_FILTER_COLOR': ` | ||
// abandon the fragments if it is not filtered | ||
if (is_filtered == 0.) { | ||
discard; | ||
} | ||
` | ||
}; | ||
|
||
export default { | ||
name: 'filter-arrow', | ||
dependencies: [project], | ||
vs: vs, | ||
fs: fs, | ||
inject: inject, | ||
getUniforms: () => {} | ||
}; |
Oops, something went wrong.