Skip to content

Commit

Permalink
Billboard prop for Scatterplot layer (visgl#5956)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorDykhta authored Jul 12, 2021
1 parent 01d819d commit f3b2aab
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/api-reference/layers/scatterplot-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ The minimum line width in pixels. This prop can be used to prevent the stroke fr

The maximum line width in pixels. This prop can be used to prevent the path from getting too thick when zoomed in.

##### `billboard` (Boolean, optional)

- Default: `false`

If `true`, rendered circles always face the camera. If `false` circles face up (i.e. are parallel with the ground plane).

### Data Accessors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ uniform float lineWidthMinPixels;
uniform float lineWidthMaxPixels;
uniform float stroked;
uniform bool filled;
uniform bool billboard;
varying vec4 vFillColor;
varying vec4 vLineColor;
Expand Down Expand Up @@ -72,9 +73,17 @@ void main(void) {
innerUnitRadius = 1.0 - stroked * lineWidthPixels / outerRadiusPixels;
vec3 offset = positions * project_pixel_size(outerRadiusPixels);
DECKGL_FILTER_SIZE(offset, geometry);
gl_Position = project_position_to_clipspace(instancePositions, instancePositions64Low, offset, geometry.position);
if (billboard) {
gl_Position = project_position_to_clipspace(instancePositions, instancePositions64Low, vec3(0.0), geometry.position);
vec3 offset = positions * outerRadiusPixels;
DECKGL_FILTER_SIZE(offset, geometry);
gl_Position.xy += project_pixel_size_to_clipspace(offset.xy);
} else {
vec3 offset = positions * project_pixel_size(outerRadiusPixels);
DECKGL_FILTER_SIZE(offset, geometry);
gl_Position = project_position_to_clipspace(instancePositions, instancePositions64Low, offset, geometry.position);
}
DECKGL_FILTER_GL_POSITION(gl_Position, geometry);
// Apply opacity to instance color, or return instance picking color
Expand Down
3 changes: 3 additions & 0 deletions modules/layers/src/scatterplot-layer/scatterplot-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const defaultProps = {

stroked: false,
filled: true,
billboard: false,

getPosition: {type: 'accessor', value: x => x.position},
getRadius: {type: 'accessor', value: 1},
Expand Down Expand Up @@ -117,6 +118,7 @@ export default class ScatterplotLayer extends Layer {
radiusMaxPixels,
stroked,
filled,
billboard,
lineWidthUnits,
lineWidthScale,
lineWidthMinPixels,
Expand All @@ -131,6 +133,7 @@ export default class ScatterplotLayer extends Layer {
.setUniforms({
stroked: stroked ? 1 : 0,
filled,
billboard,
radiusScale: radiusScale * pointRadiusMultiplier,
radiusMinPixels,
radiusMaxPixels,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions test/render/test-cases/core-layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@ export default [
],
goldenImage: './test/render/golden-images/scatterplot-lnglat.png'
},
{
name: 'scatterplot-lnglat-billboard',
viewState: {
latitude: 37.751537058389985,
longitude: -122.42694203247012,
zoom: 11.5,
pitch: 45,
bearing: 0
},
layers: [
new ScatterplotLayer({
id: 'scatterplot-lnglat-billboard',
data: dataSamples.points,
getPosition: d => d.COORDINATES,
getFillColor: d => [255, 128, 0],
getRadius: d => d.SPACES,
billboard: true,
radiusScale: 30,
radiusMinPixels: 1,
radiusMaxPixels: 30
})
],
goldenImage: './test/render/golden-images/scatterplot-lnglat-billboard.png'
},
{
name: 'line-lnglat',
viewState: {
Expand Down

0 comments on commit f3b2aab

Please sign in to comment.