Shake tip monday - Cartoon ’shader’ in Shake

I’ve heard a lot of people talking recently about A Scanner Darkly, and the semi-animated look that the film has. (If you haven’t seen the trailer, you can watch it on one of the pages linked to from here)

I don’t know how they did this - I’ve heard rumours that it was rotoscoped by hand, but what I’m about to explain is an automated way to do something similar.

I’m going to be using this image (of Keanu, because he’s the main character in A Scanner Darkly…):

Click here to view larger version

There are two stages to getting the flat shaded look - the shading itself, and the line edges. I’ll start with the shading:

The trick here is to be able to quantize the image. This means taking the full range of 256 colours (for 8-bit - 65536 for 16-bit) and changing them to use only a limited number of colours across that range.

The best way I have found to quantize an image is to compress it down and the expand it back up again. As I mentioned last week, this will usually cause the nodes to concatenate (and therefore have no effect), so a Blur node (with a blur value of 0) is placed between them.

Linking the rHi, gHi and bHi of the Expand node to the same parameters on the Compress node, and then setting the Compress node’s Hi values to 0.04 each gives the following:

Click here to view larger version Click here to view larger version

This looks pretty crappy…..

The next thing to realise is that the human eye is much better at distinguishing shades of brightness than it is different hues… We have the ability to only quantize one channel, so let’s use a different colour space….

The next image is what happens when the source is converted into hls (hue/luminance/saturation) colour space, and then only the green channel (the luminance) is quantized:

Click here to view larger version Click here to view larger version

Much better - the colours are accurate, at least. If you examine this one closely, you’ll see that each section is not a solid colour - the hue and saturation does vary slightly, but it’s enough to fool the eye at first look.

The edges are still a little jagged, though - the best way to smooth these out is just to add a bit of blur on the original image. Yes, this does lose a load of detail, but don’t forget that the detail will be brought back in the black lines…

I also added a blur onto the green (luminance) channel only just before converting it back to RGB, just to soften up the edges a bit - due to the nature of this method, they are heavily aliased to start with.

Click here to view larger version Click here to view larger version

So, let’s leave that as our colour layer - we now need to define the black lines to go over the image….

This is done with (you guessed it) an EdgeDetect node. I’ve chosen to do the edge detect on just the luminance (having converted to HSL again). The Reorder near the end is to take the detected edges and put them into the alpha channel, followed by an Expand to clean it all up.

Click here to view larger version Click here to view larger version

Then, the final step is to integrate the two - using the edge detect as the alpha for a black image, and putting it over the colour layer. (Doing the edges this way means that you can, if you want, easily change what is being shown through the edges…)

Click here to view larger version Click here to view larger version

If you want to take a look at the script that did this, you can grab it from here.

I’ve not tried it with a moving sequence, and would be fascinated to see anything that anyone comes up with using this….

10 Responses to “Shake tip monday - Cartoon ’shader’ in Shake”

  1. Anonymous Says:

    My opinion: it looks like those guys (A Scanner Darkly) really did rotoscope it, but not every single frame, but lets say, every third, and inbetween frames are morphed. So it seems by the feeling I got from watching the trailer.

    The contours are too smooth and too even to be generated out of a bitmap image in my opinion.

    One could do it by mocap and Sketch&Toon shading (cinema 4d) or mental ray or any other toon NPR.

  2. Hugh Macdonald Says:

    Indeed - I’d definately agree that the Scanner trailer is a lot smoother than this method, and the manual method of doing itwould give a lot more flexibility (for a significant amount more time and money….)

  3. Anonymous Says:

    Uuhh, I am not saying that your way of doing it is bad or anything like that. I tried you way the moment I saw it, and it helps visitors of your page occupied (if they dont have anything to do :) ) and they will come back again and again just couse of tips like this. So, I am very greateful!

    I was just making a conversation basicly. I still feel like they did rotoscope it, but not every frame. Morphing every 2nd frame can create very smooth effects (if anyone has seen Yo puta movie, they used this technique quite often to create inbetween frames and smooth continuity).

    Check the facial expressions in the trailer. They lag a bit, dont they?

    Ahhh, just thinking out loud, dont blame me.

    Andraz (www.thirdframestudios.com)

  4. Hugh Macdonald Says:

    I wasn’t at all having a go! It’d be interesting to compare the results from the two methods….

    Another interesting experiment might be to shoot people who have specific make-up on - you could really flatten the colour anyway with make-up, and affect how the skin responds to the light.

    If the skin colour was hugely smoothed, an automated method might give similar results…

    I see what you mean about the facial expressions… Although maybe it was my sound sync that was out….

    I’d be very interested in hearing from someone who actually worked on it - although I’m sure, once the movie is out (I think it’s slated for a 2006 release!) we’ll see loads of making-of stuff…

  5. Andraz Says:

    true true, but you have to admit, its heaps of fun trying to find out how they did it…

    maybe we’ll think of a nother way.

    this thing with makeup.. hmm.. I guess… Like drawing muscle contour on a skin, pumpin up the wrinkles and stuff. Yeah, that could work I guess. And it would definatly simplify the rotoscoping process.

  6. Hugh Macdonald Says:

    I was thinking more about completely flattening the look of the skin - removing all fine detail, so that under even light, it would look a solid colour - that way, the texture of the skin wouldn’t come through, and the quantization would just be happening based on the lighting that’s falling on the face…..

    For roto, though, I’d imagine having extra ‘helpers’ on the face ould make the process a lot easier….

  7. Andraz Says:

    aha so you mean tons of face powder, like chinese opera performers and stuff… Hmm, I guess you are right yeah. That would make job for a script much easier.

    I watched it again and you could do it this way I guess. Remove all the wrinkles and stuff, and then rotoscope the outlines every third frame and morph between them… I guess…

    hmmm..

  8. Craig Says:

    The film is rotoscoped, but with some sweet software. I haven’t seen an article on the current version of their code, but here’s an old article about the earlier version of the tool used for the film “Waking Life” (also by Linklater).

    http://cgw.pennnet.com/Articles/Article_Display.cfm?Section=Archives&Subsection=Display&ARTICLE_ID=134269&KEYWORD=waking%20life

    You may need to register to view the page (free).

  9. Hugh Macdonald Says:

    Thanks for that link, Craig! A fascinating article (although I’ve only read the first paragraph or so, so far….)

    Will have a read through the whole thing when I get home…

  10. Alex Says:

    Wasn’t Linklater one of the creators of Studio Artist? I thought Studio Artist was the software of choice for doing this type of effect.

    Anyways, reading about how people achieve a certain effect in Shake is always very inspiring.
    Thanks!

    Alex

Leave a Reply

You must be logged in to post a comment.