deck.gl icon indicating copy to clipboard operation
deck.gl copied to clipboard

[RFC] Fitting data on terrain surface

Open Pessimistress opened this issue 3 years ago • 1 comments

Target Use Case

As of 8.8, deck.gl always treats the z component of a geospatial position as altitude. This may not be ideal in some circumstances, for example:

  • When a layer containing 2D data is rendered alongside the TerrainLayer, the objects are occluded by the terrain
  • When using deck.gl layers in an overlay on top of a 3D base map (Mapbox/Maplibre/Google Maps), the objects are not aligned with the terrain
  • When using deck.gl layers interleaved with a 3D base map (Mapbox/Maplibre/Google Maps), the objects are occluded by the terrain

Mapbox/Maplibre support fitting user data to the surface of the terrain, namely:

  • Point (circle, icon, text): treat z as relative to the terrain surface, instead of sea level ("shifting")
  • Geometry (polygon, path, bitmap): render as a texture over the terrain mesh ("draping")

This capability is especially favorable when working with GeoJSON, since a spec-conforming GeoJSON is 2D. See user requests e.g. https://github.com/visgl/deck.gl/issues/6644 https://github.com/visgl/deck.gl/discussions/5457

Proposal

  • Add a new operation terrain. If a TerrainLayer has the prop operation: "terrain", instead of drawing to the screen, it supplies 1) an elevation texture; 2) a 3D mesh for other layers to use.
  • Add a new extension TerrainExtension. A 2D layer can use this extension to be fitted over the terrain surface.
  • Add a new effect TerrainEffect to coordinate the resources. This is similar to how the mask effect works.

Sample code snippet:

layers: [
  new TerrainLayer({
    data: 'https://my.tile.server/{x}/{y}/{z}',
    operation: 'terrain'
  }),
  new GeoJsonLayer({
    data: './regions.json',
    extensions: [new TerrainExtension()]
  })
]

@ibgreen @chrisgervang @felixpalmer

Pessimistress avatar Aug 11 '22 16:08 Pessimistress

Very interesting proposal, I like the use of a new operation to define the linkage between the terrain and offset layer.

  • Unlike the mask extension a very common use case will be to draw the TerrainLayer to screen as well as using it as source for other layers. Is it worth supporting a compound draw operation "draw+terrain" in this case? Requiring the user to duplicate the layer seems cumbersome
  • The naming TerrainExtension is implying a geospatial usecase only. It is possible to conceive of non-geospatial usecases, like a PointLayer above an extruded ColumnLayer.OffsetExtension as an alernative?
  • The MaskExtension supports multiple masks by reference using the maskId prop. Support terrainId prop in a similar manner?
  • The implementation of "shifting" seems relatively straightforward as the offset can be performed in the vertex shader by a lookup in the elevation texture, however I think it would be good to clarify how the draping will work. In the case of a bitmap we would apply the bitmap to the mesh, but what happens in the case of polygons/paths? Will they be rasterized into an bitmap prior to draping? Will we attempt to merge the geometries? Will there be limitations on rendering (lighting effects, screenspace line-widths)?

felixpalmer avatar Aug 16 '22 09:08 felixpalmer

Hi, any progress on this? Thanks

radoslavirha avatar Nov 04 '22 14:11 radoslavirha

Hi! Has this made it into master?

alienatorZ avatar Nov 07 '22 02:11 alienatorZ

Has there been any progress on this issue? Thanks!

alienatorZ avatar Dec 06 '22 16:12 alienatorZ

Bumping this feature

alienatorZ avatar Jan 18 '23 22:01 alienatorZ

hi @Pessimistress I want to apply the mask to deck.Tile3DLayer that using google 3d tiles

i have already added polygon over it using TerrainExtension image

all I want is remove or hide this area from other Tiles like masking the given area (invert masking) and you have mentioned TerrainEffect in upper thread and how do I do this please help

nightfury07x avatar Sep 15 '23 09:09 nightfury07x

If a TerrainLayer has the prop operation: "terrain", instead of drawing to the screen, it supplies 1) an elevation texture; 2) a 3D mesh for other layers to use.

how can I access the 3D mesh for other layers to use (ex like three js )

nightfury07x avatar Sep 15 '23 10:09 nightfury07x