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