Search Unity

Question Making a 2D quiver plot to display Flow Motions (or alternative Ideas)

Discussion in 'General Graphics' started by gordi42, Apr 7, 2021.

  1. gordi42

    gordi42

    Joined:
    Apr 7, 2021
    Posts:
    2
    hey,
    i am currently working on a project to create an interactive ocean modelling tool. The Project is nearly finished (the model is working and the user interface is set up). The model is set up as a bunch of 2d grids, where each point in the grid represents the waveheight, the velocity in x and y dimension as well as topographic boundary conditions. Theses grids are getting updated each frame when the model is running. Currently i am displaying different layers, that the user can activate / deactivate (the waveheight, the magnitude of the velocity and the waterdepth).

    Bildschirmfoto vom 2021-04-07 09-55-09.png

    I am looking for an elegant and performant way to visualize the velocity more detailed (by just displaying the magnitude the important information, the direction of the velocity, is getting lost). I am thinking about a field of arrows, like the quiver plot in matlab or python matplotlib.
    The only Idea i got, how to implement that, is by creating dozens of line renderers and update their scale and rotation for each frame. I can not imagine that it would be a performant solution. (I have never worked with unity before though, and dont know how it behaves when creating heaps of game objects).

    Does anybody of you know a better solution for this. Or is that the way i have to go?

    Kind regards,
    Gordi
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    The fastest solution would be to use a shader of some kind.

    Something like this:
    https://www.shadertoy.com/view/4s23DG
    That example procedurally generates an arrow per virtual grid cell.

    There's a Unity asset by a Unity employee that includes similar (but more advanced) line drawing here:
    https://github.com/keijiro/KinoVision
    That renders actual line geometry on a virtual grid, again all on the GPU. The benefit of this method is the lines can extend far outside the confines of the grid which is harder to do with the previous example.
     
    gordi42 and lilacsky824 like this.
  3. gordi42

    gordi42

    Joined:
    Apr 7, 2021
    Posts:
    2
    Oh that looks fabulous, exactly what i was looking for! Thank you :)