Skip to content

Inverted Hull Outline

Vladislav Kantaev edited this page Apr 7, 2024 · 14 revisions

Setup

  • In the project window, right click and select Create/Toon RP/Extensions/Inverted Hull Outline.
  • Go to your pipeline asset and add the newly created asset to the Extensions list.

Effect

Inverted Hull Outline

Inverted hull outlines work by rendering the geometry a second time with geometry inflated along normals and front face culling. This is a very cheap effect suitable even for mobile devices.

A single asset of Inverted Hull Outline can render several passes with different parameters (color, thickness, layer mask, etc.).

The parameters of a pass are:

Name

The name of the pass when displayed in Frame Debugger;

Layer Mask

Outlines are rendered only for opaque objects. We can also specify a mask to limit the effect to particular objects only. For example, we can have layers like NoOutline, RedOutline, etc.

Stencil Layer

Sometimes it is not desirable to have outlines inside the geometry. To prevent drawing them inside geometry, we can enable a certain Stencil Layer for the pass. We also have to set the same layer on the material used by geometry where we do not want inner outlines.

When rendering geometry itself, it will set a certain bit in the stencil bitmask. As a result, outlines are going to check for that bit and skip drawing pixels when it is is.

Stencil Layer on a Material

Outer Outlines Only

Fixed Screen Space Thickness

Because the outlines are rendered as any other geometry, their thickness is affected by perspective distortion. Fixed Screen Space Thickness helps preventing that.

Fixed Screen Space Thickness Off Fixed Screen Space Thickness On
Fixed Screen Space Thickness Off Fixed Screen Space Thickness On

Noise Amplitude and Noise Frequency

For more stylization, we can add slight noise to the thickness of the outlines. Both amplitude and frequency need to be non-zero for this to work.

Noise Off Noise On
Noise Off Noise On

Override Material

If needed, provide a custom material here. Custom outline shaders can be creatd via Shader Graph or manually through code.

Normals Source

Selects where to get the normals for outlines from. See Normals Smoothing for more details.

Vertex Color Thickness Source

📝 Note: this option was removed in favor of overriden materials. To vary thickness based on vertex color, create an Inverted Hull Outline shader graph and provide the necessary logic for the Outline Thickness vertex output.

This is useful when we want to vary the thickness inside a model, or completely prevent outlines on a particular piece of the model. This can be pained in any 3D modelling software or using the bundled Vertex Color Paint.

Depth Bias

An additional depth bias, which can prevent unwanted outlines "leaking" through geometry.

Max Distance and Distance Fade

Max Distance control how far should the outlines be visible, Distance Fade - how smoothly should they fade out.

Setting Max Distance to 0 disables the distance limit.

Pre Pass Ignore Mask

By default, inverted hull outlines are also rendered during all pre-passes. If an outline pass needs to be excluded from some of them, it can be specified in this mask.

Camera Overrides

When enabled, you can specify a custom field of view for rendering the outlines. Used when there are geometries rendering with a custom field of view (e.g., weapons in first person view), and we want to have outlines for them too.

Example Setup

Example

Example Configuration

Here we have two passes:

  • Thick, outer (stencil layer 7) and slightly noisy outlines;
  • Thin, inner (no stencil layer) outlines.

Normals Smoothing

Disconnected Outlines

Depending on the model's geometry, there can be discontinuities within outlines. This is especially a problem for flat shaded low-poly models.

Sometimes a solution might be as simple as smoothing normals in Unity: in import settings, change Normals to Calculate and set a high enough Smooting Angle:

Unity Smoothing

This, however, alters the lighting the model receives, which might not be acceptable. To solve this, we can write smoothed normals to a different vertex attribute (UV2 or Tangents). This way we get both the original lighting and perfectly smooth normals.

Smooth Normals Written to a Different Channel

📝 Note: Tangents should be used for skinned meshes, since Unity computes them as well during skinning (thus, we will have correct normals even after applying bone animation). This, however, interferes with normal mapping since it also requires tangents. A more universal solution is to create a Shader Graph, which computes tangent vectors for normal mapping procedurally. However, it your game does not use normal maps, this is not necessary.

Toon RP provides two ways to do it:

Model Post Processor

  • Add =SmoothedNormals= to the name of the model to mark it for smoothing;
  • Optionally: add =UV= or =Tangents= to specify the channel to write normals to;
    • By default, the channel is UV for usual meshes and Tangents for skinned meshes;
  • Optionally: specify a smoothing angle (e.g., =SmoothedNormals=90 for 90 degrees).

Example name: Horse_=SmoothedNormals=Tangents=.

A benefit of such approach is that if can change the model, new normals will be generated automatically on reimport.

Normals Smoothing Utility

This is an Editor window accessible via Window/Toon RP/Normals Smoothing Utility.

Specify the mesh, smoothing angle, channel, click Compute Smoothed Normals, and select a location to save a newly generated mesh.

📝 Note: the source model should have Read/Write enabled in the import settings.

Normals Smoothing Utility

Vertex Color Paint

To start painting vertex color:

  • Create an asset: Create/Toon RP/Vertex Color Paint;
  • Specify the mesh;
  • Click Open Editor.

This will open an Editor window with an ability to color, move, rotate, clear, and save the model.

Controls:

  • Hold Right Mouse Button and move the mouse to rotate the camera;
  • Hold Right Mouse Button and press W A S D to move the camera;
  • Click the arrow buttons to rotate 90 degrees along different axes;
  • Click Save to save and update to mesh asset.

Vertex Color Paint

Clone this wiki locally