maplibre / maplibre-gl-js

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

Render to user-supplied framebuffer #4306

Open akre54 opened 2 months ago

akre54 commented 2 months ago

User Story

As a developer I want to be able to render the basemap layers to a framebuffer, similar to deck.gl's _framebuffer option.

Rationale

My goal is to composite these layers separately as Textures, in a program like Photoshop or After Effects, or to do postprocessing on the individual layer passes.

Impact

Right now I can capture the canvas after all layers have been composited, but I'd really like to be able to render just a few layers (say, roads, waterways, etc) to a Framebuffer for editing.

HarelM commented 2 months ago

Rendering to textures is not performant enough for the map. I also don't fully understand the use case. I guess you can create multiple maps one on top of the the other with only the relevant layers and preserve drawing buffet to get it out of the canvas...

akre54 commented 2 months ago

Thanks for the quick reply. My goal is something similar to Blender's Shader Passes. Namely I want to be able to render the passes to AOVs (think normals map, depth buffer, shadows, lighting) to be able to use for video compositing.

Performance is less of a concern for me because frame capture is async. I'm mostly asking for a way to hook into the draw calls and get access to the rendering buffers. I can accomplish this in Deck by passing in a Framebuffer, but an alternative could be to add a callback in the render pipeline.

HarelM commented 2 months ago

This sounds like a very specific case. I'm not sure maplibre has the relevant hooks at the moment. The closest thing I can think of is using the webgl context in a custom layer, but that's not exactly what you need. A lot of the code is done in the shaders themselves too. I would recommend trying to hack out a plugin of some sort to do that, but I'm not sure I would know where to start...

akre54 commented 2 months ago

Thanks @HarelM. I'll do some exploration.

IMO this has lots of other applications but if it's not something the maintainers want to support at the moment I'll try to find a workaround.