Home    Blog    Projects    About
« Bezzy DevBlog: Morphing animation Bezzy DevBlog: The big idea behind fills »

Bezzy DevBlog: Dynamic Tessellation, Part 1  (July 22nd, 2008 at 11:59 am)

I’ve spent the past couple of days refactoring a tonne of code. That’s the problem with writing prototype/proof of concept code … eventually you need to go back and make sure it all works! With that out of the way (and the code looking pretty spiffy), I focused my attention on dynamic tessellation. I haven’t come up with an optimal solution yet, but I’ve made some good progress.

First, what the heck is tessellation, and why is my approach dynamic? Tessellation is breaking up smooth paths (in our case, Bézier curves) into a number of smaller lines. The more lines we use, the closer the approximation is to the actual curve, and as a result, the smoother the lines appear to be. Videocards are unable to render Bézier curves, they can only render points, lines and triangles. As a result, tessellation is critical to rendering curves on hardware.

Now the “dynamic” bit. This has to do with how we perceive smoothness. Basically, the bigger a curve appears on screen, the more lines are required to make it appear smooth. By scaling the amount of tessellation we use on the curves, we can ensure that we always have smooth looking curves using a minimal amount of lines.

Let’s take a look at the different approaches I took to solving this problem. I used three paths which I will creatively call (from left to right) Path 1, Path 2 and Path 3. The screenshot on the left shows the paths rendered in debug mode. Each line is coloured differently to make the tessellation obvious. The screenshot on the right shows how it would actually appear.

The naive approach

When I started off with my prototype, I simply used 16 edges for every curve regardless of it’s size or complexity. As you can see, some paths work out better than others. In particular, Path 1 looks terrible.

Length by control points

This method scales the tessellation by using the length of the curve. The longer the curve, the more tessellation required. We calculate the length by finding the distance between p0, c0, c1, p1 and multiplying by the scaling factors.

It then uses this rather arbitrary formula to figure out tessellation:

number of edges = 16 * (quicklength / 10000.0f) + 1
(quicklength is defined as the length sans the square root part … it’s an extra operation I save, and I’m not terribly interested in the actual length, just some form of measuring relative distances)

While Path 2 & 3 are look quite nice, Path 1 has visible edges. This is because the more extreme the shape of the path, the further the control points are from the actual curve. Take a look at the debug screenshot below to see what I mean.

Length by coarse sampling

I solve the issue above by using coarse sampling. Instead of using the control points I sample the curve at t=0.00, 0.25, 0.50, 0.75, 1.00 and find the “quicklength”. This yields better results, but there are still problems.

The middle of Path 1 is too finely tessellated whereas Path 3 isn’t well tessellated at all. The reason for this is that we are uniformly tessellating the curve. Slope plays a big role in how finely tessellated a path should be, and we aren’t taking this into consideration.

What’s next

My next algorithm will non-uniformly tessellate the curve by taking it’s slope into account. Wish me luck!

Posted in Bezzy.

4 Comments

Heeeey! That’s my nickname!

Good work on this stuff. I’m a lover of bezier curves too. Did you know that a circle made from bezier curves isn’t actually a true circle? You have to go all the way up to nurbs before they can be considered the real deal… but that means projecting 4D bezier curves into 3D space and I’m not sure my brain can handle that >_

Comment by Bezzy — September 4, 2008 @ 5:16 pm

Heeeey! That’s my nickname!

Good work on this stuff. I’m a lover of bezier curves too. Did you know that a circle made from bezier curves isn’t actually a true circle? You have to go all the way up to nurbs before they can be considered the real deal… but that means projecting 4D bezier curves into 3D space and I’m not sure my brain can handle that

But yeah, bezier circles are normally good enough for the job - it’s only technically speaking that they’re not true circles.

Then again, I could be talking total crap. Don’t mind me! Just bored, drunk, and googling my own name like a tit.

Comment by Bezzy — September 4, 2008 @ 5:18 pm

Okay, you were probably too drunk to remember you posted this, but on the off chance you come back here …

You’re the guy who’s doing Goo aren’t you? The game looks very freaking cool, can’t wait to get my hands on the full game! I knew Bezzy was someones nickname, but clearly my library was named after the awesome Pierre Bezier. :)

Also, I did know about the bezier curves not being able to do circles thing. I learned this while researching how to draw a circle using bezier curves. My mind was blown!

Comment by Mobeen — September 10, 2008 @ 1:48 am

[…] Part 1 went through the initial attempts at dynamic tessellation. They were good but I wanted to do better. Turns out, doing better is really hard. I ended up using a really simple algorithm that works well most of the time, but still isn’t as “perfect” as I wanted. […]

Pingback by Mobeen Fikree’s Homepage » Bezzy DevBlog: Best of the rest, Part 2 — December 1, 2008 @ 11:48 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Site and contents © Mobeen Fikree. Blog powered by Wordpress.