The Vuforia VFX library provides a range of object reveal effects for the initial discovery of objects and environments with Vuforia; X-Ray, transparency, and many other visual effects are ready for your use case. These effects and assets are easily applied to any scene in Unity to create stunning visual experiences. The asset package that is available in the Unity Asset Store contains scenes, playback sequences and Prefab components.
The Vuforia VFX Library demonstrates various visual effects that can be added to a Vuforia target in a Unity scene. The package contains sequences and scenes that demonstrate each shading effect, and this guide will show you how to add the shader component and dependencies into your own project.
See the VFX Overview for a list and demonstration of the different Prefab shaders.
See the Tinkering with the Vuforia VFX Library for guides on configuring the Target VFX component for Model Targets, Ground Plane, and for working with multiple visual effects. See also the Minimap for Area Targets to create an accurate navigation aid out of the Area Target mesh.
The VFX Library requires that you configure it with a target Observer.
The assets are optimized for Android and iOS devices. On other platforms, there may be specific steps to support the shaders.
- On Magic Leap 2 devices, enable the Force Multipass in the Project Settings -> XR Plug-in Management -> Magic Leap Settings if you want to use the VFX Library’s multi-pass shaders. This comes at a slightly higher performance cost, and we recommend keeping it disabled if multi-pass shaders are not used. See our Magic Leap 2 guide for setup instructions.
QuickStart VFX Library
- In a Unity Project, import the Vuforia Engine SDK and the Vuforia VFX Library from the Unity Asset Store.
- In the Vuforia Configuration (CmD+Shift+V or Ctrl+Shift+V), change the Play Mode to RECORDING and select either the Model Target or Ground Plane sequence from your Assets/SamplesResources/Recordings/ folder.
- Open and play the scene Main_Menu.
VFX Setup guide.
This section will show how to import and set up the VFX library and apply the shader component to your own Vuforia target. See the Vuforia VFX Library Overview for a list and description of the Prefab shaders and their configurations available in the package.
- If you haven’t already, import the Vuforia Engine for Unity.
- Visit the Unity Asset Store and add the Vuforia VFX Library to your Assets.
- In your Unity project, open the Package Manager.
- Select My Assets in the dropdown menu and download and import the asset package into your Unity project.
- In the Vuforia Configuration, add your license key.
When using the VFX Library, the Vuforia ARCamera GameObject should be configured for an optimal experience that support the visual effects:
- Adjust the Near and Far values of the Clipping Planes depending on the expected size of your scene.
- For example, a Model Target experience where the content is expected to appear within a few meters distance, the Near clip plane distance may be set to 0.05 - 0.1, while the Far clip plane distance should usually be set to a few tens of meters (< 100); setting the right distances ensure the best use of the depth buffer resolution of the device GPU, with the highest possible rendering quality.
- An AR Camera in an Area Target experience should have the setting Near clip plane to 0.1 and Far clip plane to 1000.
- Add the FocusMode.cs script to the ARCamera GameObject. The script lets you specify the focus mode. The recommended focus mode for most applications is FOCUS_MODE_CONTINUOUSAUTO, although for specific situations, a different focus mode can be used. The focus mode is ignored when using Play Mode. See more about the focus mode at Working with the Camera.
- If your scene includes the use of the DepthNormalContour shader, add the CameraDepthMode.cs script to the ARCarmera GameObject and set the field to DepthNormals. Other shaders do not require the script to be added to the camera.
The TargetVFX.cs script is a component that extends from the ShaderVFX.cs base class. This component is where you modify the parameters of the shader. As mentioned earlier, there are many pre-configured Prefabs of this component that you can simply add to your scene as shown here:
The TargetVFX automatically computes, at every frame, the center and axis vectors of the target in Unity World Space while considering the current pose of the Vuforia target and the ARCamera GameObject; informing the shader of the exact world reference frame on which to operate in real-time.
- The Observer parameter takes a
VuforiaBehaviourcomponent to apply the effect to. The TargetVFX then derives the pose and scale (bounding box) information to automatically adjust the shader effect. See more detail below in the Shader VFX class.
- The Target Object is the 3DModel GameObject that the Material will be applied onto. You can add and use the Target Representation on Vuforia targets that support it. See Adding Vuforia Engine Features for details..
NOTE: The material will be applied to all applicable objects that are a child of the Target Object.
- The Material is the material used for the effect by the shader properties that consequently modifies it.
NOTE: At runtime, the script will create and use a copy of the original Material to avoid that the original material gets permanently modified (e.g., when running in Play Mode).
You can also subscribe to the
OnReachedEnd() events to position the activation of the effects based on specific actions. One example would be to trigger the effect as part of a chain of events or on user activation, or step completion.
The Is Target Shown on Target Found parameter is a boolean flag informing whether the TargetVFX.cs script should play automatically as soon as the Vuforia target is detected.
An optional ShowDelay (in seconds) can be set to delay between the detection and the trigger of the VFX.
The Coordinate System parameters specify the names of the shader properties that are used to define the local axis system of the target as these properties will vary depending on the TargetVFX configuration. See Tinkering with the Vuforia VFX Library for details.
The Center X, Y, Z fields represent the center in the local CS (coordinate system) of the target. By default, it is set to (0,0,0), which is the origin of the target CS, but it can be set to custom values to obtain customized translational offsets for the visual effect.
The Shader Scale parameter is used to scale the visual effect so that it can run in the same way on objects of arbitrary size; the Target VFX script automatically computes the scale from the Bounding Box of the Vuforia Target.
The Center Mode parameter allows the developer to specify one of two distinct behaviors:
- TARGET - sets the center of the VFX at the origin of the Vuforia Target reference frame.
- VIEWER - sets the center of the VFX at the viewer (ARCamera) position.
The choice of the Center Mode depends on the application and the intended spatial dynamics that you wish to achieve.
Usually, for AR apps using Model Targets, the VFX should be anchored to the Vuforia Target reference frame, therefore TARGET should be used in such a case.
For AR apps using Ground Plane, the visual effects should also use TARGET to center the effect on the virtual content rendered on the hit test point.
Area Targets on the other hand, should use VIEWER when it’s desired to center the effect on the user. TARGET can be used in scenarios where the effects are used in for example pulsating info points.
The ShaderVFX.cs script is a key component of the library that allows you to configure, control and animate a visual effect through an arbitrary set of shader properties. This class holds the essential parameters that the TargetVFX component depends on.
The Transition mode can be LINEAR or CUBIC and can be selected via a Combo Box.
- LINEAR mode interpolates the property values between start and end values linearly or in “smooth steps”.
- CUBIC mode gradually accelerates the property values at the start value and gradually decelerates the transition at the end values.
The Shader VFX class exposes a set of properties and categorizes them into static and dynamic properties.
- Static shader properties do not change. For example, a VFX using a constant color throughout the duration of the effect will have the _SomeColor property as Static.
- Dynamic shader properties change dynamically during the lifetime of the visual effect by interpolating between a start and an end value, typically used for achieving an animated effect or transition.
For both static and dynamic, the ShaderVFX has properties of 3 types:
- Scalar - Single floating-point value.
- Vector – Represents positional or directional parameters used by the Shader.
- Color – Color(s) to use in the effect.
Learn more on the used parameters used by the shaders in the Tinkering with the Vuforia VFX Library.
VFX Utility Editor
Apply your custom material to a GameObject and all its children in Unity. The VFX Library includes a material options window that lets you apply a single Material to selected objects in the scene. This option lets you easily apply your VFX materials and shaders to your custom models.
- Right-click in the Hierarchy and select Vuforia Engine -> VFX -> Apply Material.
- In the Apply Material window, select the Material and select the parent objects you wish to apply the material to.
- All parent objects’ children will also have the Material applied to them.
- All parent objects’ children will also have the Material applied to them.
- Click Apply.