Monday, January 11, 2010

Radial 10 bit Gray code - Tutorial

How I made the Radial 10 bit Gray code image procedurally in Photoshop:


  1. Create a 10 bit gray code image (width 10, height 1024). I did this by hand, it's a little tedious. But there is a method: you duplicate the image vertically and then draw a line from the mid points of each tree.
    Then, expand it to a square image:
  2. Transform it radially (Filter, Distort, Polar Coordinates (need to first rotate the image 90 degrees)):
  3. Create some Gaussian blurs of the image, with a few similar large blurs:
  4. Set the blend mode to Difference between 2 of the blur layers:
  5. Add adjustment layers to remap the range, add a gradient, shift the hue, etc:

  6. Add another blur with difference blend mode, and we're done!


I worked in 16 bit mode since there was banding when differencing the similar Gaussian blurs.

    Saturday, January 9, 2010

    New Blog: Scattered Pixels

    I put effort into posts to Beautiful Pixels. I hope you've liked what you've seen the last few years.


    I've started a shadow blog called Scattered Pixels, for random thoughts, images, links. If you'd like more frequent updates from me that are less filtered, subscribe to both.

    Subscribe in a reader to:
    Beautiful Pixels
    Scattered Pixels

    And, maybe to comments:
    Beautiful Comments
    Scattered Comments

    Tuesday, December 29, 2009

    Vincent goes to Google


    Taking a short break, then starting at Google in February.

    Wednesday, November 25, 2009

    Anamorphosis Gamebryo LightSpeed Logo

    We all love Anamorphosis, and have seen it done wonderfully before ([edit] even spectacularly). Well, I've done a few simple things around the office, here's one I just did:

    Vimeo and YouTube videos.




    That was done with painter's masking tape, with the help of Cat, in about 2.5 hours.

    Here's an earlier project, the old Gamebryo logo done with post-it notes:



    Post-it notes were handy after a late night in the office and no prep. The masking tape is obviously much better. Both were done by setting up an image on my laptop and using a projector to cast it into the room. The perspective for both is just in a doorway, to help guide viewers to the right position. Both also are cast in a way that the image is heavily distorted as soon as you move slightly away from the right point.

    Share links if you've done similar projects, or know of good ones. ;)

    [Edit:]
    Falice Varini is the link you want to follow! See e.g. this.

    Tuesday, October 20, 2009

    Pixelated Martini Roller - Game Jam Video

    I've posted about Pixelated Martini Roller before, including a cell phone video recording of an IGDA presentation and a description of the collision. But dear blog readers you've never been able to see a high quality video. Here it is:



    Best watched in High Definition / full screen, with vimeo or youtube.

    If you don't recall, it's one of the Triangle Game Jam games I've worked on, this one from 2008.

    Three.5 of us made the game in 2 days, based on the madlibs jam theme that randomly made the title "Pixelated Martini Roller".

    You're an olive. You like martinis. You roll around and get to umbrellas for checkpoints. Sitting in a martini glass gets you a bit tipsy. You've got more energy and can jump higher. But watch out, stay too long and you get sloppy. You'll stagger around, and your jumps won't land you where you want to go.

    As you get tipsy the screen gets pixelated, and the music sounds like it's had too much to drink too.

    The world was created with an in-game level editor. The objects are just a few images that represent the visual and collision texels.

    We've noted how fun it is to implement hacky collision over and over again in a weekend, but I liked coming up with and working on the pixel based collision we did for this one. I also enjoyed writing the post FX pixels and rushing out the level design in the last hour. ;)

    Thanks for Michael Noland and Nolan Walker for working together on this game with me, and Brad for the title screen.

    Wednesday, October 14, 2009

    Gamma Correct Lighting, On The Moon!

    When I explain gamma correct lighting to people, sometimes they look at images and aren't certain which is supposed to be better.


    E.g. in GPU Gems 3, The Importance of Being Linear two spheres are shown, similar to these:

    Two spheres lit by a directional light. Which has gamma correct math?


    A small thought occurred to me: there's an object people are familiar with that will help them to understand, the moon:
    Two spheres lit by a directional light, compared with an image of the moon.
    Which has gamma correct math?


    Still don't see it.. yes, it's subtle... shall we make it obvious with a gradient?


    Yes, it is but one example, there are many more. But it's a good basic visual example.

    If you'd like to read more on gamma correct rendering:
    [EDIT: See the comments for some nice thoughts from people who've spent more time on this.

    Naty points out another good example in Real Time Rendering.]

    Thanks to "ComputerHotline" on openphoto.net for the image of the moon.

    Sunday, August 30, 2009

    A Weak Smart Pointer, or a Smart Weak Pointer

    Smart pointers simplify many lifetime management scenarios, especially when designing modular components and systems with a multitude of lifetime dependency options available to final applications. Weak pointers are also useful, but are flawed in a multithreaded environment.

    The other day a hybrid smart/weak pointer occurred to me, I'll present it here.

    A refresher:

    • A smart pointer is an object that acts like a native pointer, but whose lifetime controls a dynamically allocated object's lifetime. As long as you hold a smart pointer to an object, it continues to live. Multiple smart pointers can point to one dynamically allocated object, and it will not be deallocated until all smart pointers are released. Implementations typically maintain a reference count and delete the dynamic object when that ref count goes to zero.
    • A weak pointer is an object that acts like a native pointer, but whose value is changed to NULL if the object pointed to is deallocated. Holding onto this type of pointer does not keep an object alive, but you can check it's value and see that it is NULL when the object has been destroyed (a normal pointer would still point to the memory the object used to reside in).

    Discussion:
    Smart pointers are sometimes used for code safety, even when a system does not desire lifetime management responsibility. Weak pointers are a better solution here, allowing a system to keep a reference that will go NULL when the object dies.

    In multithreaded systems weak pointers lose their benefit if the dynamic object can be freed from another thread. A portion of code may check the value of the weak pointer and find the object exists. However, as the object is accessed another thread may free it.

    One work around is to use a short lived smart pointer, which will keep the dynamic object alive from the weak pointer dereference until work is complete. This requires a smart and weak pointer pair implementation designed to support this use case in a multithreaded system, and is also likely quite a performance burden due to the additional reference count manipulation.

    For code that runs infrequently, the smart & weak pointer pair is a good option though. Without any smart or weak pointers the system would need to implement thread-safe API to register and deregister objects, and the systems would need to be tightly coupled (or perhaps use a message system).

    My Idea:
    A smart weak pointer to the rescue? It would be nice to have the same functionality of a smart pointer, knowing that as long as you hold it the object will live, but also indicate to the system that you're willing to let the object die. The only catch is that you need to let the object die at a convenient time for you, so that you can safely handle the situation, but not be required to safely handle it everywhere you use the object.

    Start with a smart pointer implementation. Add an additional ref counter for the smart weak pointers, call it WeakRef. Any smart pointer pointing to an object acts as before. Any smart weak pointer acts the same as a smart pointer, but also increments WeakRef counter. Add a method to check the ref and WeakRef counters to see if they are equal, and if so set the smart weak pointer to NULL and decrement the two counters.

    A system then could use the smart weak pointers just as if they were typical smart pointers, and occasionally check if the smart weak pointer should release it's reference.

    System::OnTick()
    {
    for (lots of work to do)
    {
    Look up the right smart weak pointers to dereference, and use them as normal
    }

    for (all smart weak pointers)
    {
    CheckForRelease(p)
    }
    }
    This works out well for a multithreaded system that accesses a large number of smart pointers frequently, and has a regular opportunity to release them.

    If your system only infrequently dereferences pointers, is single threaded, or performance isn't an issue; the discussion's example of weak pointers with temporary smart pointers would be great for you.