I've been mulling over how to approach converting Vex to XNA. Vex is the interm format between the Swf to Xaml converter, basically a 2D animation format. Going to Xna would therefore allow converting swf/gdi/xaml to DirectX or Xna for use in Video games, or any other general purpose hardware accelerated 2D animation. I have a feeling this could be very fast, but there are potential bottlenecks too.

Note: GPU's can only create triangles. To create smooth curves, you need a lot of triangles. A lot.

The first thought is to just convert each Line into triangle strips, and each fill into whatever triangles will fill the shape in question. I'm sure this would/will work ok, but there does seem to be the potential of sending an awful lot of triangles every frame! In shader 3 cards (which are pretty new ones) you still can't create vertexes on the card (you can do this in shader 4, but you can't count on people having that at home for a while, not to mention on the xbox360). So if you can't create vertexes, you have to create all the triangles with CPU, then upload them to the GPU, mostly every frame. As you wind over curves and fills, that can really add up. Maybe not to the limit of the card (not sure), but it still really bugs me.

Note: Shaders are basically simple functions that run, in parallel, on up to hundreds on mini CPU's at once. Pixel shaders run a function once for every rendered pixel on the screen.

So an alternate idea we started testing today was to keep bezier points, and put them in nicely sorted trees. Then add only two triangles (to make a rectangle screen) to draw on. All graphics are then created with a pixel shader. The idea would be that each pixel would look up what color it is supposed to be from the tree. That is a bit wasteful compared with line scan etc, but because it is parallel and all done it hardware, it seems it would be plenty fast. Also it is all done on the GPU, freeing up the CPU and the lines of communication. And maybe it just feels cleaner.

Anyway, with a little help from Sky and Free, we got a test file going (yeah, I'm no shader guru, here are some awesome tutorials btw). It isn't using real beziers yet, its more for seeing how it looks, how the code looks, and how it performs. Seems ok so far, the trick will be getting a good file format, and an efficient lookup. There is a screenshot below (this is an animated sample btw), but feel free to download the code and tweak it yourself. Requires all the usual (free) XNA dev tools.

Download sample project

posted on Wednesday, July 18, 2007 3:53 AM
Feedback
  • # RE: Simulating 2D Animation in DirectX/XNA
    The Zman
    Posted @ 7/18/2007 4:12 AM
    Interesting approach - I've seen a similar thing once before in this paper http://research.microsoft.com/~cloop/LoopBlinn05.pdf The math is pretty tough going but you can use the GPU to get some anti aliasing for free. Its similar to what you are trying to do.

    One thing you might worry about is that pixel shaders are run per pixel so as you increase in complexity you can become fill rate bound very quickly especially since with a lot of alpha you can't z-test pixels out in advance. Handling your beziers inside a pixel shader is going to be pretty complex.

    In contrast modern GPUs can handle a LOT of triangles especially if you can batch things well (minimize the draw calls) and vertex shaders are in general cheaper because they are only called once per vertex. Of course triangulation of complex beziers on the fly in realtime is a whole different problem especially if there are holes in the shapes.

    In reality I don't know which is the best for you without some profiling but I'm quite fascinated.

    You can find my email on my website if you want to chat more.


  • # RE: Simulating 2D Animation in DirectX/XNA
    Robin Debreuil
    Posted @ 7/18/2007 4:27 AM
    Wow, awesome link, that will be a great read, thanks!

    Yeah I was thinking I would want to optimize a bit, maybe even sticking two or three 'easy' colored triangles in larger fills and then avoiding the bezier lookup on those. Also we could get speedups limiting the types of beziers there (eg, flat files like swf, and maybe even things like splitting cubic beziers to be 90 degrees or less...) There isn't really pressure on point count like in say swf, so maybe you would optimize the format pretty heavily.

    I think with the right format the math may get easier too, but even if not, one nice thing about that stage is when it works at all, it all works : ).

    I would really appreciate being able to run stuff by you as I progress if that is ok, a little advice can sure go a long way...

    Cheers,
    Robin

    PS, thanks for the great resource, I'm frequent lurker there when working on games : ).

  • # RE: Simulating 2D Animation in DirectX/XNA
    The Zman
    Posted @ 7/18/2007 11:36 AM
    I'd be happy to chat anytime... Glad you are doing some XNA stuff.. the flash stuff was cool but not in my interest area...

Blog Stats

  • Posts - 121
  • Stories - 1
  • Comments - 1441
  • Trackbacks - 47

.Net Blogs

01101 Blogs

Flash Blogs

Graphics

People