# How to apply a after-render 2-D image filter on cycles shader?

I'm interested in the implementation of the polka-dotted non-photorealistic shading in this video in Blender. I know how to code the filter if I have the final rendering result (image) seperated by mesh; But that method is way too hideous because I have to manually apply the filter on every single object, each with a different setting (for example, dot size and color), plus it is not applicable to video rendering due to the enormous amount of frames.

Now the best way I could think of is to make a custom node using OSL in cycles. Say,

/--------------------\           /--------------------\
| Diffuse BSDF       |           | Script             |
|               BSDF ·-----\     |               BSDF ·
· Color              |     |     | Internal           |
· Roughness          |     |     | [polka.osl]        |
· Normal             |     \-----· Shader             |
\--------------------/           · Color              |
· DotSize            |
\--------------------/


Will produce the effect on a simple diffuse shader. But OSL is based on closures, which can't (or at least I think can't) be evaluated by user and can't be accessed in another context, though I could achieve a "shadeless shader" using the method metioned in this question.

I'm not familiar with extending Blender with Python or GLSL, but I would like to know if I could achieve this using them, preferably compatible with Freestyle.

• You could probably do this in the compositor with various bits of layer information. The object index layer can be used to separate objects if necessary. I haven't spent much time with the compositor so I'll leave it to someone else to write an answer. – Sazerac Jul 31 '17 at 3:01
• I think this is exactly what Freestyle Render Engine was made for. Not sure if it suits your needs, but see freestyleintegration.wordpress.com/page/6 – Duarte Farrajota Ramos Jul 31 '17 at 4:08
• @DuarteFarrajotaRamos Freestyle can only render strokes, not fills. – Todd J. York Jul 31 '17 at 4:15
• If can render fills but it requires scripting I think blenderartists.org/forum/… – Duarte Farrajota Ramos Jul 31 '17 at 4:19
• @DuarteFarrajotaRamos Thanks for the link, I forgot this effect was called "halftone". Apparently the halftone part was not Freestyle but was a custom node written in python. I'll take a look at that. – Todd J. York Jul 31 '17 at 4:29