mob-sakai b9e0da1316 Refactor
2018-10-06 21:39:09 +09:00
2018-09-30 11:00:07 +09:00
2018-10-06 21:39:09 +09:00
2018-09-26 22:09:40 +09:00
2018-09-26 16:51:12 +09:00
2018-09-29 11:03:31 +09:00
2018-01-25 10:39:59 +09:00
2018-09-29 11:03:31 +09:00
2018-10-05 08:38:36 +09:00
2018-07-17 17:28:11 +09:00

UIEffect

UIEffect contains visual effect components for uGUI element in Unity.

PRs Welcome

<< Description | WebGL Demo | Download | Usage | Development Note >>

What's new? See changelog

Do you want to receive notifications for new releases? Watch this repo





Description

Let's decorate your UI with effects!
You can control parameters as you like from the script as well as inspector.
AnimationClip is supported as a matter of course!

thumbnail image



Available effects

Component Features Screenshot
UIEffect Combine some visual effects.

ToneMode: Grayscale, Sepia, Nega, Pixelation
ColorMode: Multiply, Fill, Additive, Subtract
BlurMode: Fast, Medium, Detail
AdvancedBlur: Enable more beautiful blurring
UICaptured EffectImage Capture a screenshot of a specific frame with effect, and display it.
This effect is non-realtime, light-weight, less-camera, but be effective enough.

Tone Mode: Grayscale, Sepia, Nega, Pixelation
Color Mode: Multiply, Fill, Additive, Subtract
Blur Mode: Fast, Medium, Detail
Quality Mode: Fast, Medium, Detail, Custom
Capture On Enable: When the component is enable, capture screen automatically.
Blur iterations: Number of blur iterations.
Reduction/Downsampling Rate: None, x1, x2, x4, x8
Fit size to screen: Fit RectTransform to the screen.
UIShiny Apply shinning effect to a graphic.
The effect does not require Mask component or normal map.

Parameters: Location, Width, Rotation, Softness, Brightness, Gloss
UIDissolve Apply dissolve effect to a graphic.

ColorMode: Overwrite, Additive, Subtract
Parameters: Location, Width, Rotation, Softness, Color
UIHsvModifier Modify HSV for graphic.

Target: Color, Range
Adjustment: Hue, Saturation, Value
UITransition Effect Apply transition effect with a single channel texture.

EffectMode: Cutoff, Fade



The following effects can be used with the above components.
Component Features Screenshot
UIShadow Add shadow/outline to a graphic.
The performance is better than the default Shadow/Outline component.

ShadowStyle: Shadow, Shadow3, Outline, Outline8
UIGradient Change vertex color as gradient with angle and offset.

Direction: Horizontal, Vertical, Angle, Diagonal
Options: Offset, Color space
UIFlip Flip a graphic.

Direction: Horizontal, Vertical, Both





Demo

WebGL Demo

  • Effect sample
  • Transition
  • Dialog window with blured background
  • Included in unitypackage





Usage

  1. Download UIEffect.unitypackage from Releases.
  2. Import the package into your Unity project. Select Import Package > Custom Package from the Assets menu.
  3. In Unity5.6+, enable TexCoord1 channel of canvas. See also Development Note.
  4. Add any effect component to UI element (Image, RawImage, Text, etc...) from Add Component in inspector.
  5. Enjoy!
Requirement
  • Unity 5.5+ (included Unity 2018.x)
  • No other SDK are required





Example of using

Title Description Screenshot
Lock/unlock contents Use UIEffect for grayscale.
Indicate to user that the content is unavailable.
Silhouette Use UIEffect for filling color.
Soft shadow(outer glow) Use UIEffect and UIShadow for blurring shadow.
To blur only shadow, set Blur Factor to 0.
Colored shadow Use UIEffect and UIShadow for filling colored shadow.
To fill color only shadow, set Color Factor to 0.
Blurred dynamic text Use UIEffect for blurring.
To blur dynamic font cleanly, enable Advanced Blur option.
Text with outline & shadow Use two UIShadow for outline and shadow.
There is less overdraw than default Outline/Shadow (Default: 1 x 5 x 2 = 10 draw calls, UIShadow: 4 + 1 = 5 draw calls).
Shinning button Use UIShiny for shinning button.
Shine the button and indicate to user that you can press the button.
Enable Play On Enable and Loop option to shine it without any AnimationClip.
Blurring the background of a menu Use UIEffectCapturedImage to blur the background of a menu.
UIEffectCapturedImage applies an effect to the screen of the previous frame, without adding a camera or layer.
It's not a real-time post effect, so it's good performance and works well on mobile.
Screen transition Use UITransitionEffect to create screen transition.
You can change transition texture (single channel texture).





Development Note

How does UIEffectCapturedImage work?

image

UIEffectCapturedImage is similar to post effect, but uses CommandBuffer to give effect only on the rendering result (= captured image) of a specific frame.
This effect is non-realtime, light-weight, less-camera, blit only once, but be effective enough.

  • Camera for processing effect is unnecessary.
  • Process effect only once after UIEffectCapturedImage.Capture.
  • Using reduction buffer, keep using memory size small and keep the rendering load are small.
  • When GameObjects with motion are on the screen, a result texture may be stirred.
  • You can overlay and display like as:
    [Screen] | [UIEffectCapturedImage] | [Dialog A] | [UIEffectCapturedImage] | [Dialog B].
    See also Demo.

Why is UIEffect lightweight?

  • UIEffect pre-generates material from a combination of effects. This has the following benefits.
    • Draw call batching If possible, draw calls will decrease.
    • Since only the required material and shader variants are included in the build, the build size will be smaller.

How to control effect parameters for uGUI element WITHOUT MaterialPropertyBlock?

  • In general, you can use MaterialPropertyBlock for renderers to control minor changes in the material without different batches.
  • However, changing the MaterialPropertyBlock of the uGUI element from the script will cause different batches and draw calls to increase.
  • So UIEffect encodes multiple effect parameters to UV1 channel with IMeshModifier.
    • Pack four 6-bit [0-1] (64 steps) parameters into one float value.
    • The parameters are lower precision, but sufficient.
uv1 6-bit [0-1] 6-bit [0-1] 6-bit [0-1] 6-bit [0-1]
x(32bit float) Tone level Empty Blur level Empty
y(32bit float) Red channel Green channel Blue channel Alpha channel
  • In v3.0.0+, UIEffect uploads the parameter value to a shared texture and the shader refers to it.
    This approach has the following advantages:
    • More parameters for the effect are available.
    • The parameter accuracy is improved from 6 bits to 8 bits.
    • ModifyMesh is not called when parameter value is changed.

Note: Unity 5.6+

In Unity 5.6+, Canvas supports Additional Shader Channels.
Please enable TexCoord1 to use UIEffect.
image image

Note: if you include prefabs / scenes containing UIEffect in AssetBundle.

Use script define symbol UIEFFECT_SEPARATE.
Unused shader variants and materials will be excluded from AssetBundles.

Combined mode (default) Separated mode
Script define symbol - UIEFFECT_SEPARATE
Included in build Only used variants Only used variants
Included in AssetBundle All variants (Heavy!) Only used variants
Look in editor comb sep

How to improve performance?

The issue of default Outline component

Graphic with multiple outline components will generate a lot of overdraw.

image

This is an overdraw view of image with three outline components.
Because there are many overdraws, it is very bright!
For each Outline component, increase the mesh by 5 times. (In the case of the Shadow component, it doubles the mesh.)
In the image above, 1 x 5 x 5 x 5 = 125 overdraws are generated.

UIShadow's 'Addition Shadow' feature solves this issue by adding only the necessary mesh, 1 + 4 + 4 + 4 = 13 overdraws are generated.





License

  • MIT
  • © UTJ/UCL

Author

mob-sakai

See Also

Languages
C# 52.9%
ShaderLab 34.1%
HLSL 6.7%
GLSL 6.1%
JavaScript 0.2%