Evaluate a Cubic Bézier on GPU
来源:互联网 发布:windows 10 live mail 编辑:程序博客网 时间:2024/06/05 21:54
Evaluate a Cubic Bézier on GPU
I’ve made an application as an example for this thread on how to compute/evaluate a Cubic Bézier Curve using a Geometry Shader. The formula is pretty straightforward as described by this wikipedia article (look for Cubic Bézier Curve). I will not go over the bézier math or theory. I assume you have some knowledge in shader programming (GLSL is the case) and some math background would help, while not really a need. All that said, let’s get to work.
On this case we will need 4 points: 2 anchor points (the line end points) and 2 control points. The control points won’t really touch the curve, they work more as directional information on the curve itself.
As we need to send this data to the shader i have decided to use LINES as input primitive, 2 points define a line so it’s perfect, we’ll use that for the 2 anchor points. As for the control points 2 different texture units (glMultiTexCoord3f) attached to the line’s vertex data will do. Using geometry shaders besides setting the input primitive type we also need to set the output type. LINE_STRIP is fine, as it works perfectly for what we’re doing. That’s all on the application side.
On the vertex shader side it’s pretty simple:
What the code is doing is sending the data further down the pipeline to the geometry shader, where all the magic happens. At this stage, having both Anchor and Control points we can now define the curve by a given detail. Think of detail as a number of step-points along the curve which makes it look smoother or flatten (tesselation, subdivision, smoothing, etc).
Both control points are sent by the application for the geometry shader, still, as in the the vertex shader comes before the geometry shader, we will need to send them down on the vertex-shader, otherwise the GS won’t be able to “see” them (i know, hurray for Cg). We’re now almost done. By using the function from the above link(s) and as shown below we compute the curve with a given detail on the geometry shader, by generating new vertices along the curve purely on the gpu side. I think it to be pretty straightforward and the code should be self-explanatory.
What’s next? That is up to you. You’re not going to leave me with all the work, are you ?
Download the example + source.
You will also need to install Vitamin 0.5.6 as the project is built with it.
- Evaluate a Cubic Bézier on GPU
- Finding a Point on a Bézier Curve: De Casteljau's Algorithm(转)
- Finding a Point on a Bézier Curve: De Casteljau's Algorithm
- Bézier curve
- A simple implementation of Bézier curve
- Bézier曲线(翻译)
- Bézier Spline Curves
- Bézier Curve 简略论述(1)
- Bézier Triangles and N-Patches
- 【matlab】绘制贝塞尔曲线 Bézier
- Rational Bézier Curves: Conic Sections
- Bézier curve(贝塞尔曲线)
- 贝塞尔曲线 (Bézier curve) 理论及绘制方法
- 【PPT】OpenCV on a GPU
- A Cubic number and A Cubic Number
- A Cubic number and A Cubic Number
- **A Cubic number and A Cubic Number**
- A Cubic number and A Cubic Number
- C#对字符串的简单加密解密过程C#的SQL数据库登陆密码的加密解密加密还原直接复制代码使用即可
- C# ADO基础(使用using操作数据库)
- Oracle SQL性能优化
- Unity 利用itextSharp导出pdf文档
- PureLayout的使用
- Evaluate a Cubic Bézier on GPU
- 【SCOI2011 Day1】糖果
- 2015 Multi-University Training Contest 3--1011 Work
- swift基础语法
- Java log4j日志记录工具配置说明
- 数据库常见面试题
- 控件——radioButton
- Android播放HLS协议的流媒体
- linux driver 简单实例