Highlighting System for Unity Engine available at: http://u3d.as/hUz
1 Overview
1.1 Package overview
2 Integration to your project
2.1 Basic integration
2.2 Hover highlight
2.3 Quick tips
3 API
3.1 Highlighter
3.2 HighlighterBlocker
3.3 HighlighterCore
3.4 HighlightingBase
3.5 HighlightingBlitter
3.6 HighlightingRenderer
3.7 HighlightingPreset
3.8 AntiAliasing
3.9 BlurDirections
3.10 Easing
3.11 HighlighterMode
3.12 LoopMode
3.13 RendererFilterMode
4 Advanced tips
4.1 Using custom transparent shaders
4.2 Anti-aliasing
5 Limitations
6 Known issues
7 Support
8 Changelog
8.1 v5.0
9 Upgrade notes
9.1 Upgrading from v4.3 to v5.0
Highlighting System package allows you to easily integrate outline glow effect for objects highlighting in your Unity project. It allows you to make any object highlightable and works on all major platforms, where Image Effects is supported.
After the package installation, in the Plugins\HighlightingSystem folder you will find all the scripts and shaders required for the Highlighting System to work. All scripts in this folder are in the HighlightingSystem
namespace.
In the HighlightingSystemDemo folder, you will find example scenes and scripts intended to demonstrate how to integrate and use Highlighting System in your own projects. Feel free to completely remove this folder at any time. All scripts in this folder are in the HighlightingSystem.Demo
namespace.
HighlightingRenderer
component to the Camera. Order of this component (among other Image Effects on this Camera) defines when the highlighting buffer will be applied to the rendered frame.
Highlighter
component to the GameObject
's you want to make highlightable.
Highlighter
components as you need. Refer to the Highlighter API to figure out what each option means.
HighlightingRenderer
component to change the look of highlighting. Please note that the highlighting presets are stored (serialized) in the component itself (will be saved in scenes and / or prefabs), and you can manipulate them at runtime using HighlightingRenderer
API.
RaycastController
component to Camera
.
HighlighterHover
component to Camera
or any other persistent GameObject
.
HighlighterHover
to the OnHover
event of the RaycastController
by pressing the + button on the bottom right first, then dragging HighlighterHover
component to the appeared None (Object) field and selecting HighlighterHover > OnHover function. You can also hook any other custom handlers to the OnHover
event this way.
HighlighterHover
component.
See also HighlighterInteractionDemo
class source for an example of more advanced interaction with the Highlighter
's.
Highlighter
- you won't see any effects from tweaking Constant highlighting properties (you can change priorities in Highlighter.UpdateHighlighting()
method source by simply rearranging pieces of code responsible for each highlighting mode).
Highlighter
's directly from scripts by using their API. For example:
using UnityEngine;
using HighlightingSystem;
public class Example : MonoBehaviour
{
// Assign Highlighter component to this field in Inspector
public Highlighter highlighter;
void Awake()
{
highligter.ConstantOn(Color.red);
}
}
using HighlightingSystem;
directive to the beginning of your scripts in order to be able to access Highlighting System API.
HighlighterHover
- to manually highlight object only for a single frame call Hover(Color.red)
on the target Highlighter
(See HighlighterHover.cs and HighlighterInteractionDemo.cs scripts for an example).
HighlighterCore
.
HighlightingRenderer
component - increasing blur iterations will help you to improve outline glow quality, but try to keep this value as low as possible for better performance.
Renderer
class can be highlighted. By default - highlighting of the following renderers is enabled: MeshRenderer
, SkinnedMeshRenderer
, SpriteRenderer
, ParticleSystemRenderer
. Feel free to tune types list globally in the DefaultRendererFilter()
method source as you need, or implement custom RendererFilter
.
class in HighlightingSystem
/ Inherits from: HighlighterCore
Description:
Main component to use on the objects you want to make highlightable.
Three different highlighting modes available (listed in descending priority order):
Highlights object only for a single frame, so you can trigger it every frame for the object under the mouse cursor.
Useful to pay attention on a specific object (game tutorial item for example).
Used to turn on/off constant highlighting on an object (for example, to highlight all pickable items on screen).
Not actually a highlighting mode, but highlighter will turn into occluder only if no other modes are active.
using UnityEngine;
using HighlightingSystem;
public class Example : MonoBehaviour
{
private Highlighter highlighter;
void Awake()
{
highlighter = gameObject.AddComponent<Highlighter>();
highlighter.ConstantOn(Color.red);
}
}
See also: HighlighterCore
Properties:
bool constant
Color constantColor
Easing constantEasing
Easing
.
float constantFadeInTime
color.a
will be changing from 0
to constantColor.a
during that time).
float constantFadeOutTime
color.a
will be changing from constantColor.a
to 0
during that time).
float constantFadeTime
constantFadeInTime
and constantFadeOutTime
at once.
bool constantUseUnscaledTime
Time.unscaledTime
instead of Time.time
when performing constant fade in / out transitions.
List<Transform> filterList
Transform
components to use in filtering. Make sure to trigger SetDirty()
after modifying this list in order for changes to take effect. See also: filterMode
.
RendererFilterMode filterMode
RendererFilterMode
.
bool occluder
HighlighterMode.Occluder
.
bool overlay
HighlighterMode.Overlay
bool tween
float tweenDelay
tweenDelay = -Random.value * tweenDuration;
).
float tweenDuration
Easing tweenEasing
Easing
.
Gradient tweenGradient
LoopMode tweenLoop
LoopMode
.
int tweenRepeatCount
tweenLoop
is set to LoopMode.Loop
or LoopMode.PingPong
.
bool tweenReverse
bool tweenUseUnscaledTime
Time.unscaledTime
instead of Time.time
for tween playback.Public Methods:
void ConstantOff(float time)
void ConstantOffImmediate()
void ConstantOn(Color color, float time)
void ConstantOn(float time)
void ConstantOnImmediate(Color color)
void ConstantOnImmediate()
void ConstantSet(float fadeTime, bool value)
void ConstantSwitch(float time)
void ConstantSwitchImmediate()
void Hover(Color color)
void Off()
void TweenSet(bool value)
void TweenStart()
TweenSet(true)
void TweenStop()
TweenSet(false)
Static Methods:
Color HSVToRGB(float hue, float saturation, float value)
class in HighlightingSystem
/ Inherits from: MonoBehaviour
Description:
Renderer
's on GameObject
's with this component (or any of it's children) will never be highlighted.
class in HighlightingSystem
/ Inherits from: MonoBehaviour
Description:
Base class for all highlighters. If you doesn't want to use provided Highlighter
component and want to implement custom highlighting logic instead - inherit from this class and override UpdateHighlighting()
method where you should update mode
and color
properties. See Highlighter
class sources for an example. Please note that for safety (to avoid exceptions), this class hides MonoBehaviour
's Awake()
, OnEnable()
, OnDisable()
, OnDestroy()
methods from all inheritors, so instead you should override AwakeSafe()
, OnEnableSafe()
, OnDisableSafe()
, OnDestroySafe()
methods correspondingly.
Delegates:
bool RendererFilter(Renderer renderer, List<int> submeshIndices)
globalRendererFilter
and rendererFilter
, which will be triggered after each SetDirty()
call to update renderers which should be highlighted.
In your own implementation of this delegate - return true to highlight renderer passed as an argument and fill submeshIndices list with the list of submesh indices which should be highlighted (or −1 to highlight all of them). Submesh indices correspond to the material indices in Materials list of the Renderer component:
Make sure to keep this delegate implementation as simple as possible or you may experience performance degradation. Refer to the DefaultRendererFilter
for an implementation example.
Properties:
Color color
bool forceRender
HighlighterMode mode
HighlighterMode
.
RendererFilter rendererFilter
HighlighterCore
instance. If set to none - globalRendererFilter
will be used instead.Public Methods:
void SetDirty()
GameObject
renderers and materials. Call this method before or after your highlightable object has changed (added and/or removed) it's child objects or any materials and/or shaders (for example, when your game character has switched it's weapon). Feel free to call this method multiple times in a single update - reinitialization will occur only once at the rendering stage.Static Properties:
RendererFilter globalRendererFilter
rendererFilter
is not explicitly assigned.
ReadOnlyCollection<HighlighterCore> highlighters
using System.Collections.ObjectModel;
directive in your scripts if you want to use this collection.Static Methods:
bool DefaultRendererFilter(Renderer renderer, List<int> submeshIndices)
globalRendererFilter
is not assigned.
static public bool DefaultRendererFilter(Renderer renderer, List<int> submeshIndices)
{
// Do not highlight this renderer if it has HighlighterBlocker in parent
if (renderer.GetComponentInParent<HighlighterBlocker>() != null) { return false; }
bool pass = false;
if (renderer is MeshRenderer) { pass = true; }
else if (renderer is SkinnedMeshRenderer) { pass = true; }
else if (renderer is SpriteRenderer) { pass = true; }
else if (renderer is ParticleSystemRenderer) { pass = true; }
if (pass)
{
// Highlight all submeshes
submeshIndices.Add(-1);
}
return pass;
}
class in HighlightingSystem
/ Inherits from: MonoBehaviour
Description:
Internal base class which implements core Highlighter
's rendering functionality. In most cases you should use HighlightingRenderer
instead.
Properties:
AntiAliasing antiAliasing
RenderTexture
. Set to AntiAliasing.QualitySettings
by default.
HighlightingBlitter blitter
HighlightingBlitter
instance, which will be used to blit highlighting rendering results. Set to null to make HighlightingBase
blit during the OnRenderImage(RenderTexture src, RenderTexture dst)
callback (default behaviour for most Image Effects in Unity).
BlurDirections blurDirections
BlurDirections.Diagonal
). This option allows finer control of solid highlighting modes. BlurDirections.All
is more expensive than BlurDirections.Diagonal
or BlurDirections.Straight
. See Also: BlurDirections
float blurIntensity
float blurMinSpread
blurMinSpread + blurSpread * Iteration Index
. Usually, the sum of blurMinSpread
and blurSpread
lies between 0.5 and 1.0.
float blurSpread
blurMinSpread + blurSpread * Iteration Index
. Usually, the sum of blurMinSpread
and blurSpread
lies between 0.5 and 1.0.
int downsampleFactor
float fillAlpha
Highlighter
's.
bool isSupported
true
if Highlighting System is supported on the current platform. Internally this checks for SystemInfo.supportsImageEffects
, SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGB32)
and isSupported
value of all highlighting shaders.
int iterations
Public Methods:
void Blit(RenderTexture src, RenderTexture dst)
highlightingBuffer
with src RenderTexture
and output result to the dst RenderTexture
. To be used only in custom scripts derived from HighlightingRenderer
component to explicitly control highlighting blit. Make sure to also override OnRenderImage
method. Please note that highlightingBuffer
will be updated for the current frame only during BeforeImageEffectsOpaque
camera event, so calling this method earlier will probably lead to undesired results.
class in HighlightingSystem
/ Inherits from: MonoBehaviour
Description:
You should add this component to the current camera if you want to apply the highlighting buffer rendered on another camera during current camera rendering. You should assign this component instance to the blitter
field in that case. Order of this component (among other Image Effects on this Camera) will define the point at which highlighting buffer will be applied to the rendered frame. Make sure that the Camera with HighlightingBlitter
component has higher depth than the Camera with HighlightingRenderer
which is using this HighlightingBlitter
component instance.
class in HighlightingSystem
/ Inherits from: HighlightingBase
Description:
Main component to assign to the Camera. This class, on top of the core HighlightingBase
implements functionality to manipulate highlighters rendering presets. Highlighting presets stored locally, in each instance of the HighlightingRenderer
component using Unity native serialization system. That means they are saved along with prefabs and/or scenes. To reset to default, copy and paste presets between instances of the HighlightingRenderer
components or between projects – please use Reset, Copy Component and Paste Component Values context menu options correspondingly (you can access them by clicking on a little gear icon to the right):
Properties:
ReadOnlyCollection<HighlightingPreset> presets
ReadOnlyCollection<HighlightingPreset>
. Make sure to add using System.Collections.ObjectModel;
directive in your scripts if you want to use this collection.Public Methods:
bool AddPreset(HighlightingPreset preset, bool overwrite)
void ApplyPreset(HighlightingPreset preset)
void ClearPresets()
bool GetPreset(string name, out HighlightingPreset preset)
bool LoadPreset(string name)
bool RemovePreset(string name)
Static Properties:
struct in HighlightingSystem
/ Inherits from: ValueType
Description:
Struct used to store HighlightingRenderer
(HighlightingBase
) settings.
Properties:
BlurDirections blurDirections
HighlightingBase.blurDirections
.
float blurIntensity
HighlightingBase.blurIntensity
.
float blurMinSpread
HighlightingBase.blurMinSpread
.
float blurSpread
HighlightingBase.blurSpread
.
int downsampleFactor
HighlightingBase.downsampleFactor
.
float fillAlpha
HighlightingBase.fillAlpha
.
int iterations
HighlightingBase.iterations
.
string name
enum in HighlightingSystem
/ Inherits from: Enum
Description:
Anti-aliasing settings to use when rendering highlighting.
Static Properties:
QualitySettings
QualitySettings.antiAliasing
value (or RenderTexture.antiAliasing
of Camera.targetTexture
when rendering to texture).
Disabled
MSAA2x
MSAA4x
MSAA8x
enum in HighlightingSystem
/ Inherits from: Enum
Description:
Defines blur directions of the highlighting buffer.
Static Properties:
Diagonal
Straight
All
enum in HighlightingSystem
/ Inherits from: Enum
Description:
Defines how tween highlighting color gradient value is evaluated or how constant highlighting alpha channel value is eased during fade in and out transitions.
Static Properties:
Linear
y = x;
QuadIn
y = x * x;
QuadOut
y = -x * (x - 2f);
QuadInOut
y = x < 0.5f ? 2f * x * x : 2f * x * (2f - x) - 1f;
CubicIn
y = x * x * x;
CubicOut
x = x - 1f;
y = x * x * x + 1f;
CubicInOut
if (x < 0.5f)
{
y = 4f * x * x * x;
}
else
{
x = 2f * x - 2f;
y = 0.5f * (x * x * x + 2f);
}
SineIn
y = 1f - Mathf.Cos(x * Mathf.PI * 0.5f);
SineOut
y = Mathf.Sin(x * Mathf.PI * 0.5f);
SineInOut
y = -0.5f * (Mathf.Cos(x * Mathf.PI) - 1f);
enum in HighlightingSystem
/ Inherits from: Enum
Description:
Determines how to render each HighlighterCore
instance.
Static Properties:
Disabled
Default
Overlay
Occluder
enum in HighlightingSystem
/ Inherits from: Enum
Description:
Determines how tweenGradient
is sampled outside of a single tween iteration.
Static Properties:
Once
When tween reaches the end of a single iteration - it will automatically stop playing.
Loop
When tween reaches the end of a single iteration - it will start over from the beginning.
PingPong
When tween reaches the end of a single iteration - it will ping pong back between beginning and end.
ClampForever
When tween reaches the end of a single iteration - it will stay at the last color value specified in gradient forever.
enum in HighlightingSystem
/ Inherits from: Enum
Description:
Defines how Highlighter
will utilize filterList
to perform Renderer
's filtering.
Static Properties:
None
Renderer
's found in child Transform
's will be highlighted.
Include
Renderer
's only on Transform
's (and any of their children) specified in filterList
will be highlighted.
Exclude
Renderer
's on Transform
's (and any of their children) specified in filterList
will be excluded from highlighting.
In order to make custom transparent shaders properly highlightable:
RenderType
shader tag is set to TransparentCutout
or Transparent
(check this for more info). Otherwise – such shader will be interpreted by the Highlighting System as an opaque shader, and alpha channel of your material's main texture will not be taken into account.
_MainTex
property of type 2D (Texture). Highlighting System will use texture assigned to this property to detect transparent areas by comparing texture alpha channel with the threshold value, taken from:
_Cutoff
(Float) property if your custom shader has it, or
Highlighter
's internal transparentCutoff
variable otherwise (set to 0.5 by default. You can change this value in the HighlighterRenderer.cs script).
Note that the main texture with its offset and scale values is cached by the Highlighting System only on highlighter's initialization, which takes place after instantiating Highlighter
component and after each call to SetDirty()
. Because of that, your changes to the main texture properties will not be reflected by the highlighting without the call to SetDirty()
method.
Also, please note that if your shader handles _Cutoff
property differently (not with the default alpha clip clip(alpha - _Cutoff)
expression) – the resulting higlighting may differ from what's rendered by your custom shader.
Hardware anti-aliasing (or MSAA, Multi-Sample Anti-Aliasing) is enabled in Unity if Anti Aliasing property is not set to Disabled in Edit > Project Settings > Quality settings. Note that there are multiple quality levels all with their own anti-aliasing settings.
Hardware anti-aliasing has several significant drawbacks:
_CameraDepthTexture
in Image Effects. So if you enable anti-aliasing for the highlighting buffer - imprecisions between anti-aliased color buffer and non-anti-aliased depth texture will produce rendering artifacts (as seen on the left side of this image):
Same issue affects shadows rendering in Unity, so it seems like there is currently no way to fix that:
Due to all of the above – it is not recommended to use hardware anti-aliasing in your project. You can replace it with Antialiasing Image Effect from the Unity Standard Assets package.
Due to the Image Effect nature of the Highlighting System – it has several limitations:
Despite the fact that this can be implemented for simple convex geometry such as this shown on the image above – complex arbitrary meshes will occlude their own parts, so they will become highlighted:
HighlightingRenderer
settings.
This isn't possible to use different highlighting settings on a per-object basis. HighlightingRenderer
settings always apply to the whole image only.
RenderTexture
size. To fix this - either disable hardware anti-aliasing in Quality Settings or reduce your game view screen resolution using Aspect Drop-down.
Here you can find Highlighting System development board which you can use to check if a specific bug fix or a feature is already known or in development: http://trello.com/b/GmwO3VNJ
New hot fixes and tips are always posted here: https://trello.com/c/lTRmC9Yv
Please feel free to send your bug reports, feedback, suggestions, questions or feature requests to:
In order to help me resolve your issue faster – please make sure to provide the following information in your email:
Highlighter
component which is now capable of covering more than 90% of all highlighting use-cases without any scripting.
HighlighterCore
class to implement custom highlighting logic without having to worry about breaking compatibility with the future versions of the package.
Highlighter
/ HighlighterCore
has been optimized and is no longer using Update()
or Coroutines. (See 10000 update calls Unity Blog post for more info)
RendererFilter
's).
fill alpha
value control (affects all Highlighter
's).
using HighlightingSystem.Demo;
directive to reference them from your own scripts.
NullReferenceException
in Highlighter.FillBufferInternal
. https://trello.com/c/zIfJdCkY
_Color
) via MaterialPropertyBlock
also affects highlighting if property name matches. https://trello.com/c/WUfBXE8B
Assets
├──HighlightingSystemDemo
│ ├──Scripts
│ │ ├──Advanced
│ │ │ └──HighlighterItem.cs
│ │ ├──Basic
│ │ │ ├──BooHighlighterController.boo
│ │ │ └──JSHighlighterController.js
│ │ └──Service
│ │ ├──ColorTool.cs
│ │ ├──ScreenSpaceCanvas.cs
│ │ └──WorldSpaceCanvas.cs
│ └──Documentation.pdf
└──Plugins
└──HighlightingSystem
├──Scripts
│ └──Internal
│ └──HighlighterInternal.cs
└──link.xml
HighlighterBase
HighlighterConstant
HighlighterFlashing
HighlighterInteractive
HighlighterOccluder
HighlighterSpectrum
.
If you haven't used these demo components in your project - simply remove them completely along with HighlightingUpgrade
script.
But if you do - you can automatically upgrade them to use Highlighter
component now.
In order to upgrade prefabs - press Upgrade button when you see such message, and save prefab:
In order to upgrade GameObject's in the currently opened scene - open Tools/HighlightingSystem/Upgrade scene from v4.3 to v5.0 utility window, press Upgrade Current Scene (all upgraded components will be logged to console) and save it.
Assets/HighlightingSystemDemo/Scripts/Basic/BooHighlighterController.boo(18,15): BCW0012: WARNING: 'HighlightingSystem.Highlighter.FlashingOn(UnityEngine.Color, UnityEngine.Color, single)' is obsolete.
Refer to the updated Highlighter
, HighlightingBase
and HighlightingRenderer
API.
seeThrough
property of the Highlighter
renamed to overlay
.
ReinitMaterials()
method of the Highlighter
renamed to SetDirty()
;
Highlighter
API methods: SeeThrough(bool state)
, SeeThroughOn()
, SeeThroughOff()
, SeeThroughSwitch()
, OccluderOn()
, OccluderOff()
, OccluderSwitch()
Die()
method of the Highlighter
. Use Destroy(highlighter);
instead.
In memory of my mother Nina and my friend Darwin.
Highlighting System are Copyright © 2011-2024 Deep Dream Games. Unity, Unity Asset Store are Copyright © 2021 Unity Technologies. Microsoft, Xbox, and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. MacBook, iOS, Retina are trademarks of Apple Inc., registered in the U.S. and other countries. NVIDIA, GeForce, GeForce GTX are trademarks and/or registered trademarks of NVIDIA Corporation in the U.S. and/or other countries.