Remember 3December
Find out where to celebrate your 3D CG art...
Theme color:
  • 1/3
You are here: Homepage /  Blogs /  Duncan's Blog / crosshatch shading
crosshatch shading
Posted: Dec 17, 2008
Category: Tutorials
Social Media:
Bookmark and Share
One can construct crosshatch shaders in Maya without needing any special plugins. The key trick is to use a shader in a shading network as if it were a texture. One can use the outColor of a shader(not assigned to any object) to control the linewidth or other attributes of a procedural texture that is in turn assigned to an objects shader. The attached scenefiles demonstrate some hatching techniques and can be loaded into Maya8.5 or later versions.
The example above is the scene simpleCrosshatch.ma which uses a blinn shader to control the thickness of lines for a grid texture. The left version uses a 2D grid texture and the right a projected grid texture using the concentric projection method.

To setup such a shader first assign a surface shader to your object( the surface shader is a "do nothing" shader that simply has outColor and outTransparency attributes that can be connected to the shading engine) and connect the outColor of a grid texture to the surfaceShader outColor. Make the grid line color black and the fill color white and increase the texture uv repeats until one has the desired line density on the surface.

Now create a blinn shader (it does not need to have a shading network node) and a valueRemap shading utility node. We will use the valueRemap node to both reverse the brightness value from the blinn shader as well as to fine tune how the thickness changes with brightness.

Connect the blinn outColorR to the remapValue inputValue. There is no need to turn color into luminance, as we don't really care about the light color or the blinn shader color in this case.

Connect the remapValue outputValue to both the grid texture uWidth and vWidth. You should have the following shading network:
The shading will be reversed at this point, with lines thick where it is bright and thin where it is light. To reverse this simply edit the value ramp on the the remapValue node so that it is 1.0 at the left and zero at the right. You can also shape this ramp so that the lines get thinner faster.
At this point you should have a result similar to the image at the top left. The right images used the same basic process but with making the grid texture a concentric projection. Note that increasing the color or diffuse on the blinn shader will also make the shading brighter. As well one can texture the color of the blinn shader if desired and the effect of shadows and reflections will be properly captured in the line thickness. One can make the lines wiggle by smearing the uvs (perhaps with a fractal texture on the uvOffset of the grid placement node). As well one could layer different grid textures and control the mix based on distance to camera. The possible variations are endless.
To get a natural look one can create several hand drawn cross hatch textures, each with thicker and farther apart lines, then control the mix based on the surface brightness. For example the texture outColor might go to a remapValue node and then the outColor.R could control the position of a ramp indice to threshold the shaded value. The original crosshatch texture could be painted with a soft brush so that the lines become skinnier as one thresholds it. Under "Toon: Get Examples" there are examples that use a similar technique: inkCrosshatch, pencilShading, pencilScribble and streaked. These are all designed with animation in mind and animate some parameters to create a natural looking giggle. One generally needs to balance looking too 3D and mechnical with looking too noisy and busy.
For very specific cross hatch lines one can actually paint them on a surface with a paint effects brush, either painting each line or possibly creating a brush that paints a bunch of lines for each stroke. The thickness of paint effects lines can be controlled by light intensity: start with a default brush, turn on "illuminated" and "real lights", and make "lighting based width" = 1 then make your object paintable and paint lines on it( the object could simply have a solid white shader ). When you render the lines with be thinner where the surface faces towards the light. If the lines do not thin enough one can increase the light intensity. You will also probably want to select all the strokes and do "share one brush".
Here is an example of this setup(attached scene pfxHatch.ma):
To speed up the scene refresh one can turn off displayAsMesh on all the stroke nodes, or perhaps also make paint effects interactive in the performance options.
Note that if one wanted, one could construct several curves on the surface surface then do pfx: attach brush to curves. This might make it easier to build specific curve shapes.

Instead of simply rendering simple strokes we can turn "tubes=ON" on the brush. The resulting tubes initially stick out from the surface, but they can be made to follow it by the following brush settings:
tubeCompletion = OFF
tubeSegments = 200 (or a relatively large value)
pathFollow = 1.0
lengthFlex = 1.0

One can then also set the number of tubesPerStep as well as the startTubes along with the brush width. The tubeWidth1+2 will need to be set based on how close the various tubes are. In general one just wants them to exactly overlap where there is no light.

Here is the scene pfxHatch2.ma, which has tubes = ON:
The scene pfxHatch3.ma has further modifications to make the lines a bit more curvy:
Here is an animation showing simple rotation of the torus with a depthmap shadowed spotlight. The paint effects lines will change width based on depthmap shadows, but not for raytraced shadows, however the grid texture technique does not have this limitation.
One can easily make the lines wiggly using various brush settings. Experiment with some of the parameters in the displacement block. It can be fun to play with the parameters and see what happens.
In order to post any comments, you must be logged in!
Newest users comments View All 12 Comments
Posted by Duncan Brinsmead on Apr 14, 2009 at 10:40 PM
Looks great!
Duncan
Posted by danjay on Apr 14, 2009 at 06:15 PM
Check out this illustration I did using this technique:
area.autodesk.com/index.php/showcase_images/image_gallery/crosshatch_dancer/
Posted by Longboarder1 on Mar 13, 2009 at 10:27 PM
Awesome! I've been looking every day for an update.
Posted by Duncan Brinsmead on Mar 13, 2009 at 10:04 PM
Yeah I know... I've been rather busy, as lame as that sounds. I'll try to post some more examples in the following week.

Duncan
Posted by pixelmonk on Mar 13, 2009 at 12:06 PM
Wake up Duncan... you haven't posted anything new in your blog for awhile. ;)