I need to draw a Bezier curve and I wanna know if it’s possible to do it using Shaders or OpenCL.
The idea is to send to the OpenGL the control points which will be touched by the curve and the other control points will be calculated in the GPU, once I’ve all the control points then I generate the vertices that describes the curve (maybe with a geometry shader)
In this way I only send to the driver a minimum amount of vertices create the curve.
Here’s an image describing the control points.
- the black control points are the vertices the application send to the driver
- the green control points are calculated in the GPU
- the vertices that describe the curve are generated later in the GPU.
Can I do that using shaders or OpenCL?
Thank you very much.
PD: I’m using OpenGL 3.3
There’s a number of ways in which you could do it; you could upload the start/end/controls as uniform variables and then upload the list of points along the curve (just 0.0, 0.1, 0.2 etc.) as vertices then compute the curve in the shader. Should be lightning fast if you do it using GLSL’s mix() command as Beziers are in reality just layered up linear interpolation.
Thanks for your help but that’s the trivial way of doing that
… and then upload the list of points along the curve (just 0.0, 0.1, 0.2 etc.) …
That’s exactly what I’m trying to avoid.
The question is if there’s a way to calculate such points in the GPU maybe using a geometry shader or using OpenCL? Because I wanna avoid sending those points that can be calculated in GPU and this way have to be a lot faster.
This upload can be done only once with a static VBO, then just reused with little cost. Should be way quicker than using a geometry shader. OpenCL is probably too complex to be useful in this case.
Sure, that way will be the fastest one but I’m doing an algorithm to draw smoothed Bezier curves in a CAD application so the user will add new points while it’s creating the curve and I’ve to calculate the “green control points” (see the picture in the original post) and later I’ve to calculate (and create) the vertices that describe the curve. So I think using a geometry shader or OpenCL will be the faster way because I’ll have to send to the driver only the “black control points” (the points the user add) everytime the user add a new one.
The algorithm work exactly the same as AutoCAD or 3DSMax does. When the user create a new point and move the mouse I’ve to draw a new segment from that point to the mouse’s position. So I’ll have to send a lot of info to the VBO everytime the user moves the mouse.
That’s why I’m trying to send only those points the user add to the GPU.
Can you give me an idea about how to get it done using shaders or OpenCL?
Thank you very much.
I think you misunderstood.
You still only have to send black and green control points dynamically to the vertex shader. The 1D vertex positions will stay static, as said NeXEkho, 0.0 0.1 0.2 etc (to define the t step), and will be used by the vertex shader along with black and green control points to generate 2D or 3D vertex coordinates.
This page talks about something similar (not checked its code).
Beware, this is not GLSL, but Cg, however I hope it will help you understand how this can work :