Wednesday, November 13, 2013

NPR cell shader material

There is currently an ongoing project at blenderartist on making a NPR (non photo realistic) renderer, called BEER. I've been following it's progress closely and these last two days even tried to contribute somehow.
I created my very own basic cell shader material to demonstrate the absolute basic features that are needed in a workflow with this style. This was a great way to teach myself blender internal shader nodes.

Why blender internal?
- blender is easy to pick by anyone on any platform. Small download size, no need to do system install and always free. (over maya)
- the shader nodes are powerful enough to do interesting things with, they are relatively easy to pick up too.
- they work great in GLSL - in real time. No need to hit the render button every time I make a change, nor kill and crash my laptop every 5 minutes. No noise/waiting (ahem, cycles)
- other existing cell shader solutions don't give me enough artistic control!

The end result is a cell shader material that is designed specifically to:
1. Give you more much needed artistic control over other existing out of the box solutions.
2. Use your comuping resources just for NPR. Take advantage of it's npr nature, so it doesn't waste computing resources on realistic computations (cycles)
3. GLSL enabled- what you see in the viewport is close to what is rendered.

You can download the latest version HERE or at blendswap.

And here is a quick description video of all of it's features:

cell shader in blender internal

Description of the features for those who can't stand listening to my voice for almost 20 minutes:

- dynamic matcap generator:
- Cell shades are selectable colors. So your shadow cell and light cell can be more specific and be complimentary colors for example. Ability to multiply a color layer on top of the cells.
- Cell masks- ability to add permanently light areas and permanently shaded areas with vertex painting masks or uv texture masks.
- Texture mode (to simplify or remove)- ability to use a UV texture + a shadow cell
- (optional) Bump map distortion of the border between the cells.
- Normal dot input- to easily set the direction of light

- cell shader tools:
- color patches - ability to paint additional color patches on top of the cell shaded material. Ability to change each color dynamically (like you would in a vector app)
- rim light - with color,hardness,size and transparency values
- specular - with color, hardness, optional spec bump, spec bump hardness, and specular mask
- extended uv textures- with option to use in multiply or other modes.
- modular/easy to extend

-full color output (with all the effects)
- output of only the dynamic matcap generator.
- Output with all the color patches but none of the extra ligting extras
- greyscale output- to quickly look at your values without a hue.

- better UI (rename/reorder/simplify some elements)
- clean up annoyances in some of the features
- buffer shadows (can affect the dynamic matcap generator)
- make the matcap generator easier to extend when you enter it's group.
- a better way to distort the cells and the silhouette of the character in glsl in various funky ways.

Bugs and limitations found in blender 2.69:
- Some vertex colour layers don't show up in render results (when you have over 8 of them). This is apparently a limitation in blender atm.
- Other minor bugs which I haven't posted to the tracker yet

After the excercise, I want to continue improving once in a while. There are many features I would like to have added and some that I want to simplify and make more straightforward/smart.

This was fun enough to make me want to make a similar material with Maya's shader nodes. Autodesk recently released Maya LT, which comes with a much more powerful (and less buggy?) shader nodes. They call it ShaderFX and it can even import/export glsl, shaderfx, hlsl/other code and be used to author real time shaders - for a video game pipeline.

Now I wish blender could compete on that front but after requesting it, I found that the devs have enough on their plate with glsl to even consider putting resources in working towards such a goal.
Unfortunately mayaLT has no linux version. Maya sucks for ati users on linux too- viewport 2.0 is broken.

A very popular professional cell shading tools plugin to look into is
Unfortunatelly it is only available for 3ds max and that is only available on windows +costs a fortune.
I still need to find a way to replicate some of the nicer features found in it, so I am looking into it's demo version.


  1. Remarkable development, and contribution to the artistic community. I appreciate your aesthetic intent and thoughtful implementation. I will want to try it out and see if it can do some of the things I now do in other packages. Specifically, I would like to have a hand-drawn series of textures contribute to the shading. Currently I do this in Lightwave, with a gradient, in which three(3) different cross-hatch textures contribute to the shading. This is then composited with the cel shading or plain color layer. It helps me generate more of the hand drawn look that I want to achieve. You appear to have part of this implemented so I will give it a try. Thank you again for your efforts and contribution to the larger community of artists.

    1. Hi Paul,
      I am very glad that you like the shader. This implementation is not great gui-wise. And it does lack some of the base features that would take it to the next level.
      I have been busy improving it and will soon release a much improved version, complete with a learning course and example models.
      You can get a cross hatching effect by using the screentone features and the 2d texture node. I have made it better in the new version as well.

  2. Hi Paul,
    Thank you for the kind words. If what you describe is what I think it should be possible to do this with the cell shader tools node. It might take a few extra nodes to have the texture have a gradient mask blending like in Lightwave. I was playing with the cross hatching effect in one of the three susane monkeys that are inside the file at blendswap (the bottom one). Unfortunatelly it wont work if you dont load the missing texture file- its just a screentone:

    I must admit that for that particular test shader inside the file I took inspiration from this paper:
    But changed some things to scratch my curiosity

  3. Todor, I'd love to see you do a video showing this shader in application with one of your past creations. (or a new creation, whichever.)


    1. hi Clay ,
      I am in the process of finalizing the new version that has a much improved feature set (buffer shadows included!). There are some limitations in blender that undermine the glsl functionality here and there:

      but you are right! Monkey head is kind of boring, so I will use this on one of my cartoon characters next time I demo it. :)

  4. This is great. Thank you for taking the time to make and share this! It is really helpful.

    1. Thank you Shira :)
      Keep your eyes peeled, because I am going to be releasing a much more improved version of the shader, complete with example models and a learning course!!