This page may include unlocalized contents


Contour

Models from polyhaven.com Robot model by Ian Robinson


The Contour shader draws lines around an object's silhouette and along prominent internal edges that define an objects shape. Redshift's line drawing is shading based so it works automatically with reflections, refractions, depth of field, and motion blur but it is confined to the inner bounds of an object. Technically, a contour can never render outside of an object's silhouette but a workaround can be used to achieve a similar visual effect as described in the Contour Behavior section below, Breaking Boundaries.

The Contour shader is one of three shaders that make up Redshift's core offering of non-photorealistic tools. The Toon Material is used as the primary shading element to create stylized cel shaded looks, the Contour shader is used to create outlines around your objects, and the Tonemap Pattern texture adds a screen space pattern to your shading to mimic a halftone dot effect and others.

Contour works with all Surface shaders, like the Standard Material, and is not restricted to the Toon Material.


Example Graph

Basic Setup

The Contour shader requires a direct connection to the "Contour" port of the Material Output. Connecting it elsewhere is unsupported.


Thickness based on distance

Contour thickness shrink


To shrink contours as they fade into the distance a State node can be used. Create a State node and use the ray length output into a Change Range node. The ray length produces the distance an object is from the camera so the change range input should be set to the maximum distance in scene units to the minimum distance to control the line thickness into the distance. The change range output should be set to the min and maximum thicknesses for your contours. For example, if the farthest part of your scene is 100 units away you should set the change range input from 100 min to 0 max and if you want your contours to start at full width close to the camera and shrink down to half size in the distance set the output min to 0.5 and the output max to 1.



Contour Behavior

External vs Internal Lines

A scene can exhibit many different scenarios and understanding how contours behave in different conditions is important to getting the most out of them. To start with the basics, External Lines draw a line around the silhouette of an object while Internal Lines draw a silhouette and have the ability to draw lines along interior details of an object. Both types of lines can be used at the same time, however, external lines are always drawn on top of internal lines. In the examples below, external lines are black and internal lines are red, note how the red internal lines are still drawn around the silhouette of an object but they capture additional detail that external lines cannot. Line thickness and other settings have been exaggerated to make the differences readily apparent, thin lines are generally better for more small details.


External Lines Internal Lines External and Internal Lines


However, if an internal line is thicker than an external line it will peek out from under the external lines. In the example below, the black external lines have a thickness of 10 and the red internal lines are animated from a thickness of 0 all the way up to 20. Around the half way point of the animation both lines have the same thickness, but as the thickness continues to climb the red internal lines can be seen next to the external lines along the silhouette of the object.


Internal Line Thickness: 0 - 20
External Line Thickness: 10


How your objects are constructed also has an impact on the appearance of contour lines. Since external lines only draw a line around the silhouette of an object, there can be a large difference between whether your objects are combined into a single mesh or made up of several smaller objects. In the example below, the robot model has been combined into a single mesh which completely changes where the black external lines are visible. By comparison, the red internal lines occupy the same general location but they are now uncovered in many areas.


Separate objects Combined into one mesh


Intersections and Overlaps

Contours can behave differently when other objects intersect with or render in front of an object with a contour, this is dependent on the Detect Separate Meshes parameter. By default, when disabled, overlapping and intersecting objects do not create contours.


Overlapping objects
Detect Separate Meshes: Disabled (default)
Intersecting objects


However, when Detect Separate Meshes is enabled, contours are drawn around the silhouette of overlapping objects and along any mesh intersections. Note that the contour does not draw on top of the overlapping or intersecting object — the blue spheres in the example below — the contour is only ever drawn on the object that has contours applied to it.


Overlapping objects
Detect Separate Meshes: Enabled
Intersecting objects


Breaking Boundaries

Contours cannot be drawn outside the bounds of the objects that they are applied to, but it is possible to create a visual illusion that contours are rendered outside the bounds of an object. Since an object passing in front of an object with contours causes a line to be drawn, this can be leveraged to create a convincing effect that contours have no limits. Essentially, this requires all objects in a scene to use contours, and most importantly, that a background object uses contours so that the edges can be drawn anywhere outside the bounds of an object that appears in front of that background.

In the examples below, the foreground objects have red internal lines and black external lines, while the background cyke object has dark blue internal lines and light blue external lines.


Foreground Contours Background Contours Foreground and Background Contours


With all the different colors, this can start to look like a bit of a visual mess — however, we can leverage this behavior and use it to our advantage to create very stylized looks. In general, this trick works best with contours that have the same color so the difference between foreground and background object contours cannot be distinguished. In the example below, all contours use the same Maxon noise texture to control the thickness modifier, allowing for variable width lines. In the first example, there is no way to distinguish between foreground or background contours resulting in the illusion that the lines are breaking out of the boundary of the foreground objects resulting in a very stylized effect. In the middle example, the background contours have been changed to red to demonstrate the difference. In the last example you can see how the scene looks if no background contours are used, the foreground contours are cleanly cut off along the silhouette of the objects.


Foreground Contours: Black
Background Contours: Black
Black
Red
Black
No Background Contours


Combined with a toon shader and a bump map to distort the tone mapping it is possible to bring all these elements together for different artistic looks.