Sunday, August 2, 2009

Hatchety hatch hatch

One of the side projects I've been wanting to working on to help me learn non-photorealistic rendering is a bit of a game. The idea is to choose a particular artist, and see if I can generate images that look like they were produced by that artist using NPR techniques.

The first artist I chose was Edward Gorey, and this is my first attempt to write a shader which recreates his cross-hatching style of pen-and-ink drawings:

Hatch shader, first attempt

This was actually also my first attempt to actually really write a shader at all in the RenderMan shading language. There were some technical challenges and I figured a few things out.

The shader uses a standard Lambertian shading model to calculate an ink intensity value on the surface of the model. This intensity is used as an input to a procedurally generated dither screen, which essentially produces parallel lines of increasing frequency as intensity increases.

Because it uses raster space coordinates to index into the dither screen, it's easy to control the parallel quality and uniform spacing of the lines, thus making it easier to generate an appropriate average value over a given area. However, the downsides to this are that it's difficult to generate hatching which follows contour lines. It's possible to use the parameter values on the surface to easily generate contour lines, but then it becomes difficult to control spacing and hence value, due to the non-uniform distribution of the parameter coordinates over the surface.

I'm not sure of a good way to handle this trade-off, and I think I may need to do it using global information that isn't available to a shader as it's executing. I'm hoping to address this by using Aqsis to generate OpenEXR images which contain other useful data in their channels (eg, surface normals or tangents), and write custom renderers to composite these output images however I want.