Toon Ink Lens

 
 
 

Basic Appearance | Taper | Variation | Pressure | Sampling | Background | Lens Effects | Advanced | Render Tree Usage

Category: Toon

Shader Family: Lens

Output: Color

Renders ink contours over the image. Ink can be drawn between different materials, objects, or where there are great discrepancies in distance or direction, for example. Contours are detected using a stratified adaptive stochastic super-sampling technique (!). This means that for each primary-ray sample normally fired to compute an image, the shader fires additional rays into the scene until various conditions are met (that is, until a contour is detected); Quasi-Monte-Carlo (QMC) methods are used to compute the direction of each additional ray. At the intersection of one of these rays with a surface, some information about the intersection point, such as the surface direction or its distance from the camera, is stored for later analysis. After each additional ray is fired, the information gathered at its intersection is compared with that stored for the nominal ray. If a contour is detected, sampling ceases and a user-specified contour-color is composited over the image.

Name

The shader's name. Enter any name you like, or leave the default.

Basic Appearance

Basic ink attributes, such as thickness ("spread") and color.

Bypass

The shader may be bypassed and the image rendered without ink. This parameter is useful because it is texturable. Since rendering ink contours can be very time-consuming, it is often useful to create a garbage matte texture to mask out large areas of the screen that do not require contours, and connect the garbage matte to this parameter in the Render Tree.

Ink Only

Renders ink only. The Ink Only control in this shader's Advanced tab allows for the ink color to be influenced by underlying surface color, or composited over black.

Color

Ink color and alpha. Ink is composited according to its alpha, so an alpha less than 1 will result in underlying surfaces being partially visible through the contours. Local controls for overriding this parameter are available from the Toon Host material shader.

Compositing

Choose from a variety of available transfer modes for controlling the compositing of ink over underlying surface color:

  • Normal. This is the default. It simply takes the foreground.

  • Add. The foreground is added to the background. Thus, no foreground will be visible if the foreground is black. This is useful for compositing such that the foreground appears to glow.

  • Multiply. Multiplies the foreground by the background. The result is always a color darker than either original foreground or background, much like the result of two overhead transparencies stacked and projected from a single projector.

  • Screen. The inverses of the two color values are multiplied. The result is a foreground brighter than either the original foreground or background.

  • Overlay. Either multiplies or screens, depending on the value of the background underneath. The overall result is that the background is not replaced by the foreground, but is mixed with it, while weighted by the value of the original background.

  • Lighten. Compares the values of the foreground and background and chooses the lighter of the two. The overall result is that the foreground can never do anything except make the background lighter.

  • Darken. Compares the values of the foreground and background and chooses the darker of the two. The overall result is that the foreground can never do anything except make the background darker.

  • Difference. The foreground is subtracted from the background, producing an inverted color effect.

  • Hue. Uses the luminance and saturation of the background and the hue of the foreground.

  • Saturation. Uses the hue and luminance of the background and the saturation of the foreground.

  • Value. Uses the hue and saturation of the background and the luminance (value) of the foreground.

  • Soft Light. If the value of the foreground is greater/less than 50% gray, the underlying background is lightened/darkened by the foreground. This is similar to shining a diffuse light on the image.

  • Hard Light. If the value of the foreground is greater/less than 50% gray, the background is screened/multiplied by the foreground. This is similar to shining a harsh light on the image.

  • Exclusion. Similar (though not identical) to Difference mode.

Spread

Controls the thickness of ink contours. Ink spread may be modified by a variety of procedural methods, such as Taper and Variation, and also by local controls in the Toon Host material shader.

The Spread Scale control in this shader's Advanced tab allows spread to remain fixed relative to a specified screen resolution, so that changing resolutions will not affect the relative thickness of ink contours.

Taper

Tapering is a procedural variation of ink spread. For example, surface-direction can be used so that contours are drawn thickest where a surface faces the camera directly, and thinner as a surface curves away. Tapering is a useful way of simulating a variety of artistic techniques for emphasizing object shape and placement.

Anisotropy

Increase ink spread at a preferred angle. This is useful for simulating a calligraphy pen, for example.

Amount

The strength of the effect (a setting of 0 disables it).

Angle

The preferred angle, specified in degrees (such that 0 corresponds to 12:00 on the clock face, 90 to 3:00, etc.).

Direction

Vary contour spread as a function of surface-direction. By default, direction taper alters ink spread according to the degree of a surface's incidence to the camera (such that spread is greatest when a surface faces towards the camera, and least when facing away).

Amount

The strength of the effect (a setting of 0 disables it).

Vector

The direction-based tapering effect relies on an incident vector pointed towards the surface in question. Usually this is the camera direction itself but, alternatively, a user-specified vector or one of a variety of presets may be used.

The Custom Vector can be used to create thicker ink contours on the underside of objects and thinner ink contours on top, for example.

Space

The coordinate space (World | Camera | Object) used for specifying the incident vector.

Selecting camera coordinates will compute incident direction relative to the camera ("Upper Right" remaining in the upper right of the rendered image regardless of camera position or orientation, for example). Camera coordinates would probably be most appropriate to simulating hand-painted techniques, but will also cause ink spread to vary as the camera moves.

Using world coordinates will lock the effect to the direction of a surface regardless of its global orientation, while using object coordinates will rotate the effect along with the surface.

Custom Vector

A three-dimensional (x, y, z) vector. The vector is automatically normalized internally.

Direction

The range of directions on which the effect acts. A value of 0 implies that the surface faces the incident vector (i.e., the surface normal is parallel to the incident vector). A value of 90 implies a surface grazed by the incident vector (i.e., the surface normal is perpendicular to the incident vector).

Spread

The range of spread values to which surface directions are mapped. A Min Spread of 2 would cause spread to increase by a factor of two at the specified Min Direction, for example.

Profile

Specifies a non-linear emphasis to the effect, so that changes in spread may ease-in smoothly or cut in abruptly, for example.

Two power functions, Bias and Gain, are provided. The response of the bias function resembles that of a gamma curve, while the gain function creates an S-shaped profile.

The Power parameter controls the amount of emphasis. Regardless of the function chosen, a Power of 0.5 results in a linear response.

Distance

Vary contour spread as a function of distance from the camera. This can be used to create depth-fading effects (ink contours thicker where they are close to the camera, etc.).

In the case of secondary rays (those spawned as a result of reflection or transparency effects), the distance considered is that accumulated over the entire ray path, beginning at the camera and ending at the current ray-surface intersection.

Amount

The strength of the effect (a setting of 0 disables it).

Vector

The direction-based tapering effect relies on an incident vector pointed towards the surface in question. Usually this is the camera direction itself but, alternatively, a user-specified vector or one of a variety of presets may be used.

The Custom Vector can be used to create thicker ink contours on the underside of objects and thinner ink contours on top, for example.

Distance

The range of distances on which the taper effect acts.

Spread

The range of spread values to which distances are mapped. A Min Spread of 2 would cause spread to increase by a factor of two at the specified Near Distance, for example.

Profile

Specifies a non-linear emphasis to the effect, so that changes in spread may ease-in smoothly or cut in abruptly, for example.

Two power functions, Bias and Gain, are provided. The response of the bias function resembles that of a gamma curve, while the gain function creates an S-shaped profile.

The Power parameter controls the amount of emphasis. Regardless of the function chosen, a Power of 0.5 results in a linear response.

Other

Trace Depth

Varies contour spread as a function of ray-traced depth. Primary rays (eye rays) are considered to have a trace depth of 0, while reflections or transmissions will have trace depths of 1 or greater.

A setting of 1 will result in contour spread being reduced 100% on the first reflection or transmission.

A setting of 0 will have no effect.

Negative settings may be used to cause contours to get thicker when appearing in reflective or through transparent surfaces.

Variation

Allows pseudo-random variation of ink properties, such as spread. Variation is useful to suggest the natural quirks and deviations of an artist's hand.

Spread

Perturbation of ink spread.

Amount

The strength of the effect (a setting of 0 disables it).

Animation

A setting of 0 disables the effect and causes the randomness to be frozen over time. Low values will cause inked lines to crawl over time. Very high values will cause inked lines to chatter.

Basis

Random variations are based on one of the following bases: Ray Direction, Intersection Point, or Intersection Normal. Each of these has a distinct flavor.

Choosing Ray Direction will result in any recognizable patterns remaining more-or-less constant relative to the screen. Other options will result in features seeming to adhere to surface features.

Space

The coordinate space (World | Camera | Object) used for specifying the variation basis.

Selecting camera coordinates will compute variation relative to the camera. Camera coordinates might be appropriate for simulating hand-painted techniques.

Using world coordinates will lock the effect to the direction of a surface regardless of its global orientation, while using object coordinates will rotate the effect along with the surface.

Custom Vector

A three-dimensional (x, y, z) vector. The vector is automatically normalized internally.

Variation

The range of input on which the effect acts.

Spread

The range of spread to which surface directions are mapped.

Profile

Specifies a non-linear emphasis to the effect, so that changes in spread may ease-in smoothly or cut in abruptly, for example.

Two power functions, Bias and Gain, are provided. The response of the bias function resembles that of a gamma curve, while the gain function creates an S-shaped profile.

The Power parameter controls the amount of emphasis. Regardless of the function chosen, a Power of 0.5 results in a linear response.

Frequency

Spatial frequency (x, y, z) of the random variation. Higher values will result in apparently noisier ink contours, while lower values will result in more smoothly varying contours.

Pressure

Simulates varying pressure of pen or brush by altering ink color (saturation and brightness) and alpha, proportional to spread (after Taper and Variation effects are accounted for). It is possible, for example, to create ink that becomes darker and more saturated where it spreads out; or ink that fades away where it spreads least.

Brightness

Varies the intensity of the ink color according to spread.

Enable

Switches on the effect.

Spread

The range of spread values on which the effect acts.

Brightness

The range of brightness to which distances are mapped. A Min Brightness of 0.5 would cause ink to darken to half its original intensity at the specified Min Spread.

Saturation

Varies the ink saturation according to spread. Saturation has parameters with the same names (and corresponding functions) as those for Brightness and Alpha.

Alpha

Varies the ink alpha according to spread. Alpha has parameters with the same names (and corresponding functions) as those for Brightness and Saturation.

Sampling

Control over contour sampling and detection.

Samples

The maximum number of rays fired to locate contours. Increasing this parameter to high values (6 or 7) results in higher-quality contours, while setting lower values (2 or 3) result in proportionately lower quality contours.

In most cases a setting of 4 or 5 will suffice. Thicker contours will require higher settings.

Because increasing this parameter by 1 will slow rendering by a factor of 11/4 on a typical scene, it is essential to use as low a value as possible! This setting should also be balanced with anti-aliasing settings for the entire scene. Typical settings for high quality contours might be:

samples -1 2

contrast 0.200000 0.200000 0.200000

for the scene, and

samples 5

for the shader with a spread setting of 2.0. Faster previews could be accomplished, with some loss in quality, using settings such as

samples -1 1

contrast 0.200000 0.200000 0.200000

samples 4

Trace Depth

Sets the maximum trace depth to which contours are computed. If no reflections or refractions are needed, than a setting of 1 will result in the fastest render. If contours are only necessary for eye rays, and in the first reflective surface, or though the first transparent surface encountered, then a setting of 2 will suffice. Higher settings will result in greater levels of contours traced (as well as longer rendering times).

A warning will be issued if this parameter is set to a value lower than that of the scene's maximum trace depth for reflections, refractions, or their sum.

Boundaries

Contours detected according to various criteria. These options are not mutually exclusive (a contour may be both between materials and also between objects, for example); so turning one option off does not guarantee that all affected contours will disappear.

If an option is not required, turning it off will result in a slight performance increase.

Environment

Enables contour detection at the boundaries between surfaces and the background environment.

Object

Enables contour detection where surfaces intersect or overlap.

Material

Enables contour detection at the boundaries between different materials.

Host Materials

These options allow properties associated with the Toon Host material shader to affect ink placement.

When the Paint option is enabled, ink will be drawn at the boundaries of various paint layers (highlight, rimlight, etc.). This feature might be useful if the final ink contours are to be subsequently filled using a digital ink-and-paint system.

When the Transparency option is enabled, ink will be drawn at the boundary between transparent and opaque surfaces.

With the Shadow option enabled, ink will be drawn between surfaces on which shadows are cast and those unaffected by shadows. The transparency threshold for determining whether a surface is considered opaque or transparent may be adjusted with the Toon Host shader's Transparency > Detection Threshold parameter.

Facet

Detects contours at facet boundaries - this will result at contours being drawn between intersecting, adjoining, or overlapping triangles in the tessellated surface.

Enable switches on the effect.

Merge Coplanar is provided for ignoring facet boundaries between adjacent co-planar triangles.

Thresholds

Contours detected according to surface properties at the ray intersection. These are not mutually exclusive (a contour may be both direction and also distance-related, for example), so setting one parameter to a value of 0 does not guarantee that all affected contours will disappear. Direction and distance contours are only detected within surfaces of the same object, with the same material applied.

Direction

Inks where the difference in surface orientation of sampled points not on the same triangle exceeds this angle. The angle is specified in degrees.

This threshold may be modified by the Depth-Fade Thresholds controls in the Advanced tab of this shader, and also by local controls in the Toon Host material shader.

Distance

Draws a contour where sampled points not on the same triangle exceed this distance from each other.

This threshold may be modified by the Depth-Fade Thresholds controls in the Advanced tab of this shader.

Background

This is a quick way to preview or render a contour image against a specified color (or image) background.

Enable

Activates the effect.

Color

Specifies a background color. Because this parameter is texturable it may be used as the input for other rendering nodes (for example, an image or image sequence).

Because of the effects of alpha pre-multiplication (mental ray's default color format), the alpha-channel value in the final rendered image may differ from that specified here.

Lens Effects

The Lens Effects options allow for a variety of lens-distortion effects useful for simulating distorted perspectives often found in hand-drawn artwork and non-photorealistic rendering.

Fisheye

The fisheye parameters simulate a hemispherical (fisheye) lens capable of rendering a 180-degree field of view with characteristic hemispherical distortion typical of real-world fisheye lenses. These parameters are identical to those of the Lens Effects shader, but have been built into the Toon Ink Lens shader both for speed and to allow distortion of the rendered image rather than the inklines themselves.

Enable

Activates fisheye distortion.

Amount

Adjusts the degree of fisheye distortion. A value of 0.0 effectively "flattens" the lens, while a value of 1.0 results in completely hemispherical distortion.

Distortion is relative to the pass camera's field of view (FOV). Hence, only if FOV is set to 180 degrees, and Distortion to 1.0, will the lens be truly hemispherical.

You can adjust the pass camera's field of view from the Camera property editor.

Scale

X/Y

Adjust the proportions of the image in X and Y.

Uniform

When activated, the X and Y scale values are kept identical, and changing them zooms into or out of the image uniformly. Zooming out reveals an undefined (black) area outside of the area covered by the lens.

Bulge

The bulge parameters allow "bulging" of the lens by altering eye-ray direction. The lens may bulge out (convex, like a fisheye lens) or bulge in (concave). This effect may vary over the surface of the lens, and is best controlled via the render tree.

Enable

Activates bulge distortion.

Amount

Adjusts the amount of bulge distortion. A value of 0.0 effectively disables the bulge effect, while a value of 1.0 results in the full effect (as determined by the Magnitude sliders).

Magnitude

X/Y

Controls horizontal and vertical bulge, respectively. Using the render tree, you can generate scalar values for these parameters by mapping a procedural texture (GradientGradient_Mixer, for example) to screen space, using the Texture Space GeneratorPreset node to compute screen coordinates for each eye ray.

Advanced

Require Host

When enabled, contours are drawn only on surfaces with a Toon Host material shader applied.

Ink Only

Include or Exclude underlying surface color's influence on the ink color. When excluded, ink is composited over black.

Sorting Tolerance

Whenever possible the ink properties of the sample nearest the camera are used when drawing contours. However, when samples occupy nearly the same position in space, it is necessary to use alternative criteria, such as the incidence of a sample relative to the camera, to prevent noisy contours. Sorting Tolerance defines the range of distances (plus-or-minus this value) between two samples within which incidence, rather than distance, is used to determine which sample's contour to draw.

Distribution

Older versions of this shader jittered contour rays' directions in two dimensions (raster space). The current version is able to render ink contours faster and with more accuracy by jittering the rays' directions in one dimension (the angle of a circular target with fixed radius). Select Angular for the improved behavior. Area distribution is provided only for compatibility with older versions.

Spread Scale

Contour spread may be expressed absolutely (in internal units) or relative to a specified screen resolution.

Choosing Relative causes spread to be maintained constant in relation to a specified X. Res (horizontal resolution). Rendering at twice the specified resolution then would result in ink twice as thick, for example.

Choosing Absolute will keep spread constant regardless of rendered resolution.

Fade Sampling Thresholds

Allows altering the Distance and Direction sampling thresholds according to samples' distance from the ray origin (camera or reflecting/refracting surface). This can be used to reduce the apparent detail of faraway objects.

Amount

The strength of the effect (a setting of 0 disables).

Distance

The range of distances over which the Direction Threshold is modified.

Far Thresholds

The thresholds for Direction (in degrees) and Distance where the samples' distance exceeds the specified Far Distance above.

Render Tree Usage

This shader can be applied directly to the camera in the lens shader stack. See Applying Lens Shaders to Cameras.

Alternatively, it may be used with companion Toon Host material shaders to allow some of its parameters to be overridden or modified, depending on settings at the intersected surface.

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License