maplibre / maplibre-gl-js

MapLibre GL JS - Interactive vector tile maps in the browser
https://maplibre.org/maplibre-gl-js/docs/
Other
6.41k stars 690 forks source link

CustomLayerInterface to expose projection matrix parameters #3080

Closed Pessimistress closed 3 months ago

Pessimistress commented 1 year ago

User Story

For our custom layer implementation to properly match the base map in an interleaved 3D context, we need access to the projection matrix parameters.

Rationale

CustomLayerInterface.render currently exposes a single matrix argument that is the combined view projection matrix. In our implementation, coordinate transforms are done on the GPU for better performance, but shader uniforms only support up to 32-bit floats. To compensate for lost precision, we calculate the view matrix and projection matrix separately.

Historically we poke into the source code of the Transform class to try match our calculation with the base map. This has become increasingly problematic as the base map could change its near/far plane calculation between versions. It would be much easier if CustomLayerInterface.render could expose the view and projection matrices separately, or even the individual projection matrix parameters (fov, near, far).

Impact

The matrices/parameters are already calculated internally. Making them visible to a custom layer has minimal overhead but will help create much more robust third-party renderers.

HarelM commented 1 year ago

For far and near plane there's another issue to take into consideration and that's when looking around points below sea level. See #1655.

In general, I don't mind adding more optional parameters to the custom layer render method. Having said that, there is also the following issue which talks about adding more parameters, not sure how to address all these requirements though: #1305

I would suggest to have a more concrete proposal. cc: @Kanahiro