User Tag List

Results 1 to 3 of 3

Thread: NinePatch - Custom border scaling made simple

  1. #1
    No Products Registered

    Join Date
    Sep 2007
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    NinePatch - Custom border scaling made simple

    Hello.

    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.

    Attached files Attached files

  2. #2
    No Products Registered

    Join Date
    Sep 2007
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: NinePatch - Custom border scaling made simple

    Demonstrating the edge scaling bug in action:



    Non-corner pieces are scaled improperly from 0-1 rather than adjusted for removing the scale-corrected borders and shifted. The calculations got to be too complex and spaghetti-like for me to handle. (Also, it stopped fitting in a PS2.0 shader program)... This is probably as far as I'm gonna go with this version of the code without a little outside help, for now. Regardless, what do you guys think?

  3. #3
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCSWF Export Module
    Alonso's Avatar
    Join Date
    Jul 2006
    Posts
    681
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This shader is awesome, thanks Nobu!

Similar Threads

  1. Custom made highscore in flash?
    By Outcast in forum SWF/Flash Export Module Version 2.0
    Replies: 7
    Last Post: 18th May 2013, 02:09 PM
  2. Custom border outside the game window?
    By N64Mario in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 13th March 2012, 06:35 AM
  3. Custom made Fonts?
    By Atherton in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 30th December 2010, 11:57 PM
  4. Slopes for custom made platform movement
    By Langol in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 26th September 2007, 05:53 PM
  5. get angle of custom-made ball movement
    By Christina in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 21st September 2006, 07:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •