1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Drawing a curved line

Discussion in 'Programming' started by Ido-f, May 29, 2019.

  1. Ido-f

    Ido-f Member

    Joined:
    Feb 19, 2018
    Posts:
    117
    Let's say I want to draw a line from point A to point B, but instead of being a straight line I want it to follow some kind of a curve.
    I want this line to be dynamic, both in the start & end points and in the curve parameters.

    What is a good way of achieving this?

    Edit: I remember seeing a unity streamer using a vertex buffer with tangent data for each vertex and somehow worked with that.
    But even with that data on the vertices, how would I communicate the fragment shader what curve the fragment positions should be interpolated by, instead of producing the regular linear interpolation resulting in a straight line?
     
    Last edited: May 29, 2019
  2. Vishnya

    Vishnya Member

    Joined:
    Jul 6, 2016
    Posts:
    65
    You can use path to create curve line, or use splines
     
  3. Ido-f

    Ido-f Member

    Joined:
    Feb 19, 2018
    Posts:
    117
    @Vishnya Do you have an informative link on what are splines?
    I can't find anything in the manual or online, only on 'skeletal sprites' exported from other programs. Was that what you meant?

    Also, If anyone know a more flexible solution where I'd write most of the code myself, maybe with a vertex buffer, I'd love to hear.
     
  4. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,871
  5. Ido-f

    Ido-f Member

    Joined:
    Feb 19, 2018
    Posts:
    117
    That's maybe a good source for maths, but I don't see anything in there about actually drawing it in Gamemaker. Am I missing something?
     
  6. Vishnya

    Vishnya Member

    Joined:
    Jul 6, 2016
    Posts:
    65
    You should just find list of points and then draw lines using primitive or draw_line function.
     
  7. Ido-f

    Ido-f Member

    Joined:
    Feb 19, 2018
    Posts:
    117
    That would give a bunch of straight lines, and require heavy cpu processing instead of fast graphics card calculations.
     
  8. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    320
    Last edited: May 30, 2019
    Ido-f likes this.
  9. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,363
    Then just increase the number of lines untill it looks like a curve. It's fairly cheap.
    That's how we do things.

    Yeah, you *could" use a B├ęzier curve distance estimator and draw a curve line in a fragment shader using that, but that would most certainly be far more expensive, not to mention complicated.
     
  10. Ido-f

    Ido-f Member

    Joined:
    Feb 19, 2018
    Posts:
    117
    @GMWolf Do you know if tessellation is possible in gamemaker?

    As in, adding vertices in the vertex shader or adding vertices otherwise using the graphics card somehow?
     
  11. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,363
    Nah you can't do that. Besides, if it's not gonna change there is not much point.
    If you really want to reduce overhead just create a vertex buffer of your lines.
    If you then want to move those points you could do it in the vertex shader. No CPU necessary at this point.

    But really you should be fine doing it on the cpu, unless your entire game is made out of curved lines.
     
  12. Ido-f

    Ido-f Member

    Joined:
    Feb 19, 2018
    Posts:
    117
    I guess it'd be easier with the line's width issue as well.
    Oh well, I guess my graphics dreams can wait for later. Thanks for your input
     
  13. GMWolf

    GMWolf aka fel666

    Joined:
    Jun 21, 2016
    Posts:
    3,363
    What is that dream? I'm sure it's feasible with what is available.
    Sure it won't ever be as fast as a system using compute shaders and such. But we should be able to come up with a good solution.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice