visgl / deck.gl

WebGL2 powered visualization framework
https://deck.gl
MIT License
12.11k stars 2.08k forks source link

Scatterplot of rectangles? #3326

Closed bclinkinbeard closed 5 years ago

bclinkinbeard commented 5 years ago

How would you go about drawing shapes besides circles with ScatterplotLayer? My immediate use case is I would like to draw a rectangle instead, and I assume that means fragment shader changes, but I'm not really sure where to start. Statically sized rectangles/shapes would be good enough, dynamically sizing them based on the TextLayer they'll be paired with would be even better.

The other thing I thought of was artificially creating polygons at the given location but that seems a little silly maybe. As always, any pointers are appreciated.

Pessimistress commented 5 years ago

@bclinkinbeard the ScatterplotLayer draws a quad and discards the fragments outside of the circle. You can copy its fragment shader and remove the discard logic. See https://deck.gl/#/documentation/developer-guide/writing-custom-layers/subclassed-layers?section=defining-additional-uniforms

bclinkinbeard commented 5 years ago

Awesome, thanks!

bclinkinbeard commented 5 years ago

If I specify my own fragment shader with the same code that's in scatterplot-layer-fragment.glsl.js, I get this error.

luma: GLSL compilation errors in fragment shader my-scatterplot-layer-fragment-shader-1
114: 
115: void main(void) {
116:   geometry.uv = unitPosition;
^^^ ERROR: 'assign' : cannot convert from 'varying highp 2-component vector of float' to 'const highp float'

129:   }
130: 
131:   DECKGL_FILTER_COLOR(gl_FragColor, geometry);
^^^ ERROR: 'DECKGL_FILTER_COLOR' : no matching overloaded function found
Pessimistress commented 5 years ago

We made a change in 7.2 (master). If you're using 7.1 you need to copy the shader from the 7.1-release branch. The old shader will continue to work after 7.2 is released, just sans the new features.

bclinkinbeard commented 5 years ago

Got it, thanks.

heathhenley commented 3 months ago

For anyone who ends up here like I did - the relevant docs are now at: https://deck.gl/docs/developer-guide/custom-layers/subclassed-layers#defining-additional-uniforms

linuxpham commented 2 months ago

what is an example in deckgl version 9?