• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
MarkS

Is it possible to draw Bezier curves without using line segments?

13 posts in this topic

When I started programming at age eight on a 68000-based Mac, I was fascinated by QuickDraw's ability to draw geometric shapes so quickly. This led to years of searching as to how (I started well before the internet was established). I now have an admittedly pointless, but interesting cache of pixel-perfect (midpoint) geometric object drawing code (ellipses, elliptical arcs, lines, etc.). This kind of became a hobby of mine.

One thing that I have noticed is that I have never seen a similar method for drawing Bezier curves. I have seen countless algorithms for drawing them, but they all rely on calculating the end points for line segments and then drawing the line segments. Searching for "midpoint Bezier algorithm" returns vast amounts of results for Bezier subdivision, but nothing about drawing curves pixel by pixel.

I am just curious if anyone here has ever seen or heard of such an algorithm. Sadly, the math is a little beyond my abilities, so rolling my own is out. It just seems like this should be possible. If this cannot be done, what is the reason?
0

Share this post


Link to post
Share on other sites
You can solve a Bezier curve at any location. Drawing it as a series of line segments provides an approximation of the curve, with the tradeoff being between drawing time and resolution. If you reduce your step between endpoints to a small enough increment you end up with pixel-sized segments in between endpoints, at the cost of having to draw more tiny little line segments, but at this level it becomes as close to "pixel perfect" as you can get. So there is nothing difficult or weird with what you want, you just have to use a small enough increment.
0

Share this post


Link to post
Share on other sites
I understand that I can subdivide the curve down so that I am drawing single pixel lines, but that is again drawing lines. What I am looking for is Bezier curve code that draws a Bezier similarly to Bresenham's line drawing code. In other words, the initial pixel is calculated and the rest are incrementally derived from some function. The curve would be plotted pixel by pixel by pixel.

My interest in this is really just personal. I have no need for it, but it always bothered me that I could not find any examples. I am just really curious if this has ever been done, and if so, I would like to see the code.
0

Share this post


Link to post
Share on other sites
[quote name='MarkS' timestamp='1351367116' post='4994488']
When I started programming at age eight on a 68000-based Mac, I was fascinated by QuickDraw's ability to draw geometric shapes so quickly. This led to years of searching as to how (I started well before the internet was established). I now have an admittedly pointless, but interesting cache of pixel-perfect (midpoint) geometric object drawing code (ellipses, elliptical arcs, lines, etc.). This kind of became a hobby of mine.[/quote]
That'd be an interesting bunch of code, regardless of the language they were written in. Do you them up on a website somewhere where I could peruse them?
1

Share this post


Link to post
Share on other sites
[quote name='Servant of the Lord' timestamp='1351372577' post='4994523']
That'd be an interesting bunch of code, regardless of the language they were written in. Do you them up on a website somewhere where I could peruse them?
[/quote]

I have them floating around my hard drive somewhere. They all came from the internet, either in whole or part and most are easy to find. The only difficult one was the elliptical arc code. It took years for me to find a reference on how to do that and modify my ellipse drawing function. If I have time, I'll clean them up and post them.
0

Share this post


Link to post
Share on other sites
[quote name='MarkS' timestamp='1351371589' post='4994517']
I understand that I can subdivide the curve down so that I am drawing single pixel lines, but that is again drawing lines. What I am looking for is Bezier curve code that draws a Bezier similarly to Bresenham's line drawing code. In other words, the initial pixel is calculated and the rest are incrementally derived from some function. The curve would be plotted pixel by pixel by pixel.

My interest in this is really just personal. I have no need for it, but it always bothered me that I could not find any examples. I am just really curious if this has ever been done, and if so, I would like to see the code.
[/quote]

Well, if your line segments are only a single pixel long they're... uh.... just pixels. They're sequentially plotted from the function that is the Bezier curve. You're probably not going to find something as simple and elegant as a Bresenham algorithm for Bezier curves because the curvature is neither constant like a circle, nor easily predictable like an ellipse. You could possibly derive it to obtain the curvature (the curvature can be described as the rate of change of the tangent to the curve with respect to the arc-length, or dT/ds) and match curvature to a pixel pattern, but that just seems needlessly complex. Some quick googling turned up http://www.gamedev.net/topic/156180-curvature-of-a-bezier-solved/ in which a poster posted about how to find the curvature of a Bezier; couldn't say how accurate or correct it is, but it might be a place to start. Seems like, if you know the curvature at pixel N, then you should be able to use it to calculate pixel N+1. But, again, it's probably just easier to evaluate the curve for very small increments of t instead.
1

Share this post


Link to post
Share on other sites
All midpoint algorithms describe the curves with an equation in the form f(x, y) = 0 (with integer or rational* coefficients). A Bézier curve is not in this form. It is a parametric equation in the form (x, y) = P(t). However, it is always possible to transform a Bézier curve to the required form. In the case of a quadratic (or maybe also cubic) curve it may be practical. In general it is probably easier and faster to simply use the subdivision idea. Note that a quadratic Bézier curve is an arc of parabola, so you need an algorithm to draw it if you want to draw a quadratic Bézier curve.

* A polynomial with rational coefficients can be easily converted to a polynomial with integer coefficients by multiplication by an integer constant.
1

Share this post


Link to post
Share on other sites
[quote name='apatriarca' timestamp='1351425855' post='4994675']
All midpoint algorithms describe the curves with an equation in the form f(x, y) = 0 (with integer or rational* coefficients).
[/quote]

I haven't seen this; I always just see lines, circles, and ellipses -- and I guess conic sections most generally. I assume you mean that [i]f[/i] is any [i]polynomial [/i]function of [i]x[/i] and [i]y[/i] (with rational coefficients)? Then is the idea that the state of the algorithm is all the [i]x[sup]i[/sup]y[sup]j[/sup][/i] products or something? I don't see how this works beyond the quadratic case, because the coefficients in Pascal's triangle stop being 1s and 2s (so you lose the fast bit-shift multiplication, and besides, the number of items in each row of Pascal's Triangle grows with O(n), whereas you can just compute the powers directly in O(log(n)) by repeated squaring). Maybe you could point me to a reference?
0

Share this post


Link to post
Share on other sites
I do not know special algorithms outside lines, circles, ellipses and conic sections. However, I think any "midpoint algorithm" to rasterize a curve defined by the implicit equation f(x,y) = 0 follows the following steps:[list=1]
[*]Choose an initial point
[*]Choose the two candidate next points (from the points adjacent to the current one) based on the derivative of the curve at the current point
[*]Evaluates the function f at the midpoint of the two candidate points
[*]Choose the next point based on the sign of the value computed at 3
[*]Repeat steps 2-5 until the last point is rendered
[/list]
This general algorithm comes from my general understanding of the algorithms and not from some reference. However, looking for relevant papers on Google I have found "Rasterization of Nonparametric Curves" by John D. Hobby. I haven't read it but the abstract is the following:

[quote]We examine a class of algorithms for rasterizing algebraic curves based on an implicit form that can be evaluated cheaply in integer arithmetic using finite differences. These algorithms run fast and produce “optimal” digital output, where previously known algorithms have had serious limitations. We extend previous work on conic sections to the cubic and higher order curves, and we solve an important undersampling problem.[/quote]
1

Share this post


Link to post
Share on other sites
[url="http://research.microsoft.com/en-us/um/people/cloop/loopblinn05.pdf"]Let there be GPUs[/url].
Seriously, not talking about this is all messed up.
2

Share this post


Link to post
Share on other sites
Windows 7 performs font rasterization using the GPU directly
This does exactly what you want - which is drawing triangles and shading each pixel according to an implicit equation that derives from a Bezier curve
No slow and messy subdividing and drawing lines etc.
You can get a detailed description of how they do it in "Rendering Vector Art on the GPU" by Charles Loop and Jim Blinn
This is free online: [url="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html"]http://http.develope...gems3_ch25.html[/url]
0

Share this post


Link to post
Share on other sites
about a month ago I made this based on those papers:

http://bwhiting.co.uk/b3d/vector/

no AA though sadly as ddx and ddy unavailable in the shader (shader model 2.0), anyone know another way?
0

Share this post


Link to post
Share on other sites
[quote name='skytiger' timestamp='1351694531' post='4995834']
Windows 7 performs font rasterization using the GPU directly
This does exactly what you want - which is drawing triangles and shading each pixel according to an implicit equation that derives from a Bezier curve
No slow and messy subdividing and drawing lines etc.


You can get a detailed description of how they do it in "Rendering Vector Art on the GPU" by Charles Loop and Jim Blinn
This is free online: [url="http://http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html"]http://http.develope...gems3_ch25.html[/url]
[/quote]
That remains quite complex though. For one, for cubic beziers it's much much easier to recursively split them into quadratic beziers than analyzing them to find out whether they're looping or whatnot to be able to rasterize them like in the paper. Quadratics are so much easier to work with, and approximating a cubic bezier with one or more quadratic is rather easy and doesn't really even result in any noticeable curvature error even when zooming in (while keeping the advantage of pixel perfect curve rendering at any zoom level).
Another thing is that you need to find overlapping "quadratic triangles" to subdivide one of them. Plus of course you need to perform tesselation of the whole thing too, but that's not really specific to using the GPU to rasterize curves.

A much easier to implement approach is to just use the stencil buffer instead of doing tesselation altogether. This also avoid the need to subdivide the "quadratic curve triangles". The downside is that each shape you need to render pretty much needs exclusive access to the stencil buffer, followed by rendering a bounding rectangle to fill the actual inside of the shape using the stencil so you pretty much require two render call for for each independent shape you want to render (and if you do stroking that's a second shape).

And then there's that, although I suspect it's quite heavy on fillrate (plus things like gradients would seem like it would be rather complex to do):
[url="http://ivanleben.blogspot.fr/2010/12/animated-random-access-vector-graphics.html"]http://ivanleben.blo...r-graphics.html[/url]

Otherwise, there is an algorithm similar to bresenham but for bezier curves, which I guess is more what the OP was looking for:
[url="http://smartech.gatech.edu/bitstream/handle/1853/3671/92-16.pdf;jsessionid=A796F2CEFBCE7A61CCC5179357E1970E.smart1?sequence=1"]http://smartech.gate...art1?sequence=1[/url] Edited by Zlodo
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0