• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Drawing a curved line

Ido-f

Member
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:

Ido-f

Member
@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.
 

Vishnya

Member
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?
You should just find list of points and then draw lines using primitive or draw_line function.
 

Ido-f

Member
You should just find list of points and then draw lines using primitive or draw_line function.
That would give a bunch of straight lines, and require heavy cpu processing instead of fast graphics card calculations.
 

GMWolf

aka fel666
That would give a bunch of straight lines, and require heavy cpu processing instead of fast graphics card calculations.
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.
 

Ido-f

Member
@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?
 

GMWolf

aka fel666
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.
 

Ido-f

Member
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.
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
 

GMWolf

aka fel666
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.
 

Armyk

Member
Hello! I would really want to create a bezier curve shader for game maker studio 2, but I dont know how to implement it.
 

Mike

nobody important
GMC Elder
Why do you need to do a shader? Why not just generate a triangle strip? Or generate a path and render that? A shader for this is a little overkill isn't it?
 

Armyk

Member
Hello again. How would you create a curved line and then draw it wide? You cannot draw path with width. An when you use a triangle strip, you can see a little pixels between the triangles
 

GMWolf

aka fel666
Then you triangle strip isn't very... Good.
You want to make sure you "weld" the corners of your strips together.
One technique is the get the "normals" of each segment edge, add them together, normalize a d multiply by width. That gives you your welded vertex shared between both segments.


Code:
/// Given points A, B, C, getting vertices V1 V2 at intersection B
Nab //normal of segment AB
Nbc //normal of segment BC
V1 = B + normalize( Na + Nb ) * Width.
V2 = B - normalize( Na + Nb ) * Width.
 
Top