Custom WebGL particle/flow layer #16196
Replies: 3 comments 7 replies
-
Ok, I finally managed to make something. I used a custom canvaslayer and rewrote the render function to do all the webgl stuff, and then the animation runs by calling requestAnimationFrame() which again calls map.render(). I have no idea what I am doing, so if anybody is reading I would like to know if this is an anti-pattern. Also, still haven't figured out how to attach the layer to a Source - now i'm just reading the png directly from the render function. A feature, different than the Flowlayer, which reprojects the image into webmercator prior to putting it into the texture, I made the shader calculate the lat/lon for the particle, so that it can look up the vectors directly from the un-reprojected png just using the lat/lon. I think this may be better. Not sure. Also, I have separated the color into a separate layer. I thing this works better than combining color and flow, especially when moving and zooming the map. Ideally I want to clear the whole flow layer when moving the map, and redraw when it stops, but not sure how. Screencast.from.18.sep.2024.kl.01.50.+0200.webm |
Beta Was this translation helpful? Give feedback.
-
Figured it out. Since I am creating my own canvas in the custom Layer class I need to set some css for it not to mess up all the layers. Now, the graticule becomes visible again, and I can change the color of the wind particles in the fragment shader since it is not hidden behind the color layer anymore. Though the slightly grayish particles looked better.
Screencast.from.19.sep.2024.kl.03.59.+0200.webm |
Beta Was this translation helpful? Give feedback.
-
Hi! The streams look great! I'm really interested on how you managed to do this. Do you have a wokring code sample? |
Beta Was this translation helpful? Give feedback.
-
So, I have been building a very crude version of a custom flowlayer for wind illustration, and it's starting to come together, ref img below. Hoping to get some advice on how to proceed.
So far I have a background WebGLTileLayer that creates a continuous heatmap showing wind strength, using OL styling options. This works perfectly. Then I have used a TileLayer on top for the particle animation, drawing it onto a canvas in the loader function, and return the canvas to the TileLayer. Both layers are based on data encoded in RGBA in png files.
I am now looking for advice on how to implement more properly with suitable layers, sources, renderers etc (I find it really hard to understand how all the parts work together from reading OL source):
What would be the best Layer to use/extend for this usecase?
The actual animation is now happening through a framestate.animate = true in a forever postrender event loop. Is this a correct way of telling WebGL to keep drawing? Feels like it requires some compute, but might be the WebGL process itself, and not the framestate.animate = true loop.
How should I split data preparation vs WebGL stuff between source/layer? Do i prepare data in a source, return it to a layer, and then do all the WebGL and rendering there? WebGL functions need access to the map bounds so that i can resize the canvas/layer on zoom&scroll. This is not available in the source/loader function, but is available via framestate from render function in layer.
Beta Was this translation helpful? Give feedback.
All reactions