This is the thread for a 9-slice pixel shader I have in development called NinePatch. It seems to work allright, though the code has gotten needlessly complicated due to my inexperience and relative lack of understanding of the pixel shader paradigm. Rather than implement this as an extension or a widget, I've implemented a 9-slice function in hardware.
What is a NinePatch? It is an image map which is sliced evenly into 9 pieces, with the corner pieces remaining unscaled, the center scaling normally (or tiling), and the edges either scaling on one axis, or tiling on one axis. It is insanely useful for creating custom skins for in-game menus. Please see the screenshot for an example of NinePatch in action:
It's really rather simple to use. Simply change the object's appearance to that of the window style you wish to emulate, and tell NinePatch what your scaling ratio is in the events. You can even create animated windows (the borders will animate automatically based on your image used). The image used here was a simple blue window at 96x96 px, with an alpha channel and a drop shadow. All 1 object.
It is, however, not without its flaws.... For the following reasons, this release should be considered an alpha:
* There is a rounding error where the pieces fit together at certain scale levels. This is mitigated somewhat by first sampling the center pixel. (Done already in the code). I'm sure something better-coded wouldn't have this issue.
* The scaling amount isn't perfect in the sides or the center. Allow for some "fudge factor" when designing NinePatches. At high magnifications, the floating point numbers begin introducing more roundoff errors.
* The shader doesn't attempt to correct for cases where the size of a Patch (1/3 the width and height of the image) is larger than the total width/height after scaling. It will simply draw stuff on top of other stuff. It would be nice to see it scale, but it doesn't, and it may never....
Because of the number of instructions used, the shader currently requires PS 3.0. I'm begging anyone who takes a look at this code that if you know how to do this better than I did, please give it a shot. The code is completely unoptimized and it's about 4:30 in the morning and I would say I've just about given up on this thing. Other than these things, this release should be relatively stable (no crashing). Check it out and see what you think.