mob-sakai / SoftMaskForUGUI

Enhance Unity UI (uGUI) with advanced soft-masking features to create more visually appealing effects!
https://github.com/mob-sakai/SoftMaskForUGUI
MIT License
1.91k stars 257 forks source link
components mask smoothing ugui uguicomponent ui unity unity-plugin unity3d

logo SoftMaskForUGUI v2



PRs Welcome

<< ๐Ÿ“ Description | ๐Ÿ“Œ Key Features | ๐ŸŽฎ Demo | โš™ Installation | ๐Ÿš€ Usage | ๐Ÿค Contributing >>

๐Ÿ“ Description

Enhance Unity UI (uGUI) with advanced soft-masking features to create more visually appealing effects!



๐Ÿ“Œ Key Features



๐ŸŽฎ Demo

WebGL Demo



โš™ Installation

This package requires Unity 2019.4 or later.

Install via OpenUPM

Install via UPM (with Package Manager UI)

Install via UPM (Manually)

Install as Embedded Package

  1. Download a source code zip file from Releases and extract it.
  2. Place it in your project's Packages directory.
    • If you want to fix bugs or add features, install it as an embedded package.
    • To update the package, you need to re-download it and replace the contents.



๐Ÿ”„ Upgrading from v1 to v2

If you are currently using SoftMaskForUGUI v1.x, the following breaking changes are included when upgrading to v2:

  1. API changes: Some APIs are obsolete.

    • SoftMask.softness: Use SoftMask.softnessRange instead.
    • SoftMask.partOfParent: Use MaskingShape component instead.
  2. SoftMaskable component: SoftMaskable component is no longer required to be added explicitly. It will be added automatically at runtime as needed.

  3. SoftMaskable shader: SoftMask() function has been updated with additional arguments.

    // Before
    color.a *= SoftMask(IN.vertex, IN.worldPosition);
    // After
    color.a *= SoftMask(IN.vertex, IN.worldPosition, color.a);


To apply these changes automatically, please follow the steps below:

  1. Click Edit > Project Settings to open the Project Settings window and select UI > SoftMask category.

  2. Click on "Upgrade All Assets V1 to V2" to modify the assets.



๐Ÿš€ Usage

Getting Started

  1. Install the package.

  2. Add a SoftMask component instead of Mask component.
    Or, convert an existing Mask component to SoftMask component from the context menu (Convert To SoftMask).

  3. Adjust the soft mask parameters in the inspector.

  4. (Optional) By placing the MaskingShape component under SoftMask, you can add or remove the masking region.

  5. Enjoy!



Comparison of Masking Mode



RectMask2D vs SoftMask

RectMask2D is a built-in component that supports soft masking.
SoftMask provides more advanced soft masking.



Component: SoftMask



Component: MaskingShape



Component: RectTransformFitter



Project Settings



Usage with Scripts

var softMask = gameObject.GetComponent<SoftMask>();
softMask.maskingMode = SoftMask.MaskingMode.SoftMasking;
softMask.downSamplingRate = SoftMask.DownSamplingRate.x2;
softMask.softnessRange = new MinMax01(0.5f, 0.75f);



Usage with TextMeshPro

  1. First, you must import TMP Essential Resources before using.

  2. Open the Package Manager window and select the UI Soft Mask package in the package list and click the TextMeshPro Support > Import button.
    โš ๏ธ If you are using ugui 2.0 (=Unity 2023.2+/6.0+) or TextMeshPro 3.2+/4.0+, click the TextMeshPro Support (ugui 2.0) > Import button instead.

  3. The assets will be imported under Assets/Samples/UI Soft Mask/{version}.



Usage with Your Custom Shaders

Here, let's make UI/Additive custom shader soft-maskable. There are two ways to support SoftMask with custom shaders.



:warning: Limitations

The following are the limitations of SoftMaskForUGUI.



๐Ÿค Contributing

Issues

Issues are incredibly valuable to this project:

Pull Requests

Pull requests offer a fantastic way to contribute your ideas to this repository.
Please refer to CONTRIBUTING.md and develop branch for guidelines.

Support

This is an open-source project developed during my spare time.
If you appreciate it, consider supporting me.
Your support allows me to dedicate more time to development. ๐Ÿ˜Š




License

Author

See Also