Outline rendering of a Model Target¶
This guide describes the high-level steps to render the outline of a Vuforia Model Target at runtime. Implementing outline rendering requires basic knowledge of the rendering pipeline and familiarity with one or more platform-specific graphics APIs (OpenGL, Metal, DirectX, etc.). The Vuforia Samples provide basic usage of those graphics APIs.
Get the Model Target Mesh¶
The first step is to obtain the mesh of the Model Target at runtime. For that, a Mesh Observer for the given Model Target must be created. The Mesh Observer regularly publishes the latest state of the Model Target’s mesh to the VuState
. A Mesh observation consists of a set of VuMeshObservationBlocks
. Each block comes equipped with a pose (relative to the Mesh Observer’s tracked pose) and a VuMesh
, which contains the triangle geometry of the Model Target. Note that a VuMesh
can be referenced by multiple blocks.
See Mesh Observer for a detailed guide on the setup and observation processing.
Get the Tracked Model Target (Mesh) Pose¶
To align the outline (or any other augmentation) with the tracked Model Target, the Model Target observation is equipped with the necessary pose information. For convenience, the Mesh observation also comes equipped with the same pose as the tracked Model Target.
Render the Model Target outline¶
Outline rendering is a two-pass rendering technique. The following steps assume that the Mesh observations are properly processed and GPU buffers for rendering are created. To transform all meshes to world coordinates, the transform of the observation’s pose information must be used (4x4 matrix).
- Render the front-facing triangles of all meshes of the Model Target to the depth buffer (e.g., no color rendering).
-
Render the back-facing triangles of all meshes with a 2D screen-space offset. The outline effect is achieved by scaling the back-facing triangles so that they are no longer fully covered by the front-facing triangles. This creates an outline along natural edges in the mesh.
The triangles are scaled in screen space. For that, we add an offset to the xy-components of each screen-space vertex position. The offset is comprised of the normalized xy-components of the screen-space vertex normal multiplied by a user-defined scale factor. The scale factor determines the width of the outline. A detailed implementation can be found in the DepthCounter shader that Vuforia Engine provides as part of the Vuforia Unity extension. The shader can be found under
Packages/Vuforia Engine AR/Vuforia/Shaders/Built-In/DepthCounter.shader
.