Page 1 of 2

Bezier Goodness

Posted: Sat Sep 07, 2013 10:14 am
by Germanunkol
Image

Download:
Bezier.love
Version 4 - now with shaders, automatic normalmap rendering and different materials.
(28.13 KiB) Downloaded 292 times
(For newest version, check Version on Github.)

Original post:
I love Bezier curves!

Image

Use the code however you want to.

There is still some optiomization that could be done:
  • Change number of segments to draw (currently fixed at 500 in the demo)
  • When moving points, curve is recalculated every frame - could be changed to a max of 20 times a second or so.
Can you tell me how it performs when you move a point? Does anyone get below 45 FPS with less than 20 points?

Re: Bezier Goodness

Posted: Sat Sep 07, 2013 10:45 am
by Roland_Yonaba
Good work!

With LoveNACL (Chrome Browser):
KkF87Ds.jpg
KkF87Ds.jpg (88.16 KiB) Viewed 599 times
With Love:
ctLXrF7.jpg
ctLXrF7.jpg (76.78 KiB) Viewed 599 times

Re: Bezier Goodness

Posted: Sat Sep 07, 2013 12:19 pm
by vrld
Good effort.

Some pointers for further optimization:
  1. You directly evaluate the Bezier basis functions. While this works most of the time, it's not numerically stable, i.e. for some values the calculations can go wrong (caused mainly by the the binomial coefficients). Luckily, there is an easy to understand and numerically stable algorithm: De Casteljau's Algorithm.
  2. While straightforward, the rendering algorithm is suboptimal. A better solution is recursive subdivision. Usually about 3 or 4 recursion steps produce good looking curves. You can also stop recursion if the current segment is "suffieciently smooth". You can check for that using the second forward differences.
Side note: LÖVE 0.9 will introduce a BezierCurve object.

Re: Bezier Goodness

Posted: Sun Sep 08, 2013 12:10 am
by Germanunkol
Hey, thanks for the good advice!

I've implemented a new version using de Casteljau's Algorithm, which was very, very slow at first. Then I used the subdivision algorithm and it's still very slow. I will check again after getting some sleep - maybe I missed something.
The problem with the recursion seems to be that it very quickly grows in computation time when adding more points.

I think it would be no Problem if I only allow cubic Beziers (and automatically split everything above cubic into cubic-and-less Beziers)... I'll have to fiddle with it.

Roland, thanks a lot for the tests! 39 FPS is too low, but then again this is not optimized. Also, the final program will probably not need curves with more than 6 points...

Re: Bezier Goodness

Posted: Sun Sep 08, 2013 3:24 pm
by Germanunkol
I've reworked the rendering algorithm according to vrld's suggestions.

It's now much more configurable (dynamically chooses the number of segments according to a maximum-segment-length setting) and adding more points does not increase the number of rendering points as much any more. Works for me until up to 150 construction points!

New version in first post.

Re: Bezier Goodness

Posted: Fri Sep 20, 2013 1:31 pm
by Germanunkol
Updated:
  • Multiple shapes
  • Only cubic Bezier curves
  • Remove points, create new points between other points
  • Zoom, move, all the good stuff.
    And, best of all:
  • Interior now rendered in separate thread
Bezier.love
Version 3 - also in first post.
(18.58 KiB) Downloaded 200 times
(Also added to first post, and also on github: https://github.com/Germanunkol/BezierDrawing)

Post your creations! :D (Press F5 for screenshot)
Also, tell me if you find any bugs...
Image

Re: Bezier Goodness

Posted: Sat Sep 28, 2013 9:20 pm
by Germanunkol
I'm quadriple-posting. Sorry :(

I am finally getting somewhere. I'm not posting a .love for every change, if you're interested just get it from github.

Added:
  • Real time lighting (used this tutorial and shamelessly ripped most of the shader code from there)
  • Auto-generated normalmap, diffusemap and specular maps
  • Multiple materials (Feel free to add your own. If they're cool I might include them :) )*
  • Duplicate and flip shapes for easy symmetry
  • Move shapes up and down in the layers
Image
Image

* To make a material, simply copy and paste the metal.lua inside the Material subfolder. Then change it around. the profile function and specular functions give the normals and spec-shading at the edge of a shape. So returning 0,0,1 for the profile function just gives you a flat surface, while returning 1, 0, 0.1 gives you sharp edges all pointing left. Dir is the default normal of the edge, amount is the distance from the edge (ranging from 0 to 1).

profileDepth makes the inset larger.

Re: Bezier Goodness

Posted: Sun Sep 29, 2013 11:20 am
by micha
The light effect looks awesome.

Re: Bezier Goodness

Posted: Tue Oct 01, 2013 7:05 am
by Lafolie
Germanunkol wrote:I'm quadriple-posting. Sorry :(
Perfectly acceptable, you posted new, relevant information!
  • Real time lighting (used this tutorial and shamelessly ripped most of the shader code from there)
Thanks so much for this link.

Re: Bezier Goodness

Posted: Sat Nov 02, 2013 11:18 pm
by LoneArtisan
Nil