Giter Club home page Giter Club logo

softmaskforugui's Introduction

SoftMaskForUGUI

⚠️ NOTE: Do not use the obsolete tags and branches to reference the package. They will be removed in near future. ⚠️

UI Soft Mask is a smooth masking component for Unity UI (uGUI) elements.


PRs Welcome

<< Description | WebGL Demo | Installation | Usage | For Your Custom Shader | Contributing >>





Description

By using SoftMask instead of the default Mask component, you can beautifully represent the rounded edges of UI elements.

Features

  • SoftMask is compatible with Mask.
  • You can adjust the visible part.
  • Text, Image, RawImage can be used as a masking.
  • Support multiple-sprites and SpriteAtlas.
  • Support up to 4 nested soft masks.
  • Support scroll view.
  • Support inversed soft mask.
  • Support overlay, camera space and world space.
  • (Option) Raycast is filtered only for the visible part.
  • Contain soft maskable UI shader.
  • Support soft masks in your custom shaders by adding just 3 lines. For details, please see Development Note.
  • Adjust soft mask buffer size to improve performance.
  • Convert existing Mask to SoftMask from context menu.
  • Render the soft mask buffer only when needed to improve performance.
  • Add a SoftMaskable component to the child UI elements of SoftMask from the inspector.
  • Preview soft mask buffer in inspector.
  • Make multiple holes on one background by 'Parts of parent' option.
  • Support TextMeshPro

Components

Component Description Screenshot
SoftMask Use instead of Mask for smooth masking.

Show Mask Graphic: Show the graphic that is associated with the Mask render area.
Desampling Rate: The desampling rate for soft mask buffer. The larger the value, the better the performance but the lower the quality.
Softness: The value used by the soft mask to select the area of influence defined over the soft mask's graphic.
Ignore Parent: Should the soft mask ignore parent soft masks?
Part Of Parent: Is the soft mask a part of parent soft mask?
softmask
SoftMaskable Add this component to Graphic under SoftMask for smooth masking.

Use Stencil: Use stencil buffer to mask. If disabled, the stencil buffer is ignored.
RaycastFilter: Use soft-masked raycast target. This option is expensive.
Mask Interaction: The interaction for each mask layers.
softmaskable





Demo

WebGL Demo





Installation

Requirement

  • Unity 2017.1 or later (2018.x, 2019.x and 2020.x are included)
  • No other SDK are required

Using OpenUPM (for Unity 2018.3 or later)

This package is available on OpenUPM. You can install it via openupm-cli.

openupm add com.coffee.softmask-for-ugui

Using Git (for Unity 2018.3 or later)

Find the manifest.json file in the Packages folder of your project and edit it to look like this:

{
  "dependencies": {
    "com.coffee.softmask-for-ugui": "https://github.com/mob-sakai/SoftMaskForUGUI.git",
    ...
  },
}

To update the package, change suffix #{version} to the target version.

  • e.g. "com.coffee.softmask-for-ugui": "https://github.com/mob-sakai/SoftMaskForUGUI.git#1.0.0",

Or, use UpmGitExtension to install and update the package.

For Unity 2018.2 or earlier

  1. Download a source code zip file from Releases page
  2. Extract it
  3. Import it into the following directory in your Unity project
    • Packages (It works as an embedded package. For Unity 2018.1 or later)
    • Assets (Legacy way. For Unity 2017.1 or later)





How to play demo

  • For Unity 2019.1 or later
    • Open Package Manager window and select UI Soft Mask package in package list and click Demo > Import in project button
  • For Unity 2018.4 or earlier
    • Click Assets/Samples/UISoftMask/Import Demo from menu

The assets will be imported into Assets/Samples/UI Soft Mask/{version}/Demo.
Open UISoftMask_Demo scene and play it.





Usage

  1. Add a SoftMask component instead of Mask component.
    Or, convert an existing Mask component to SoftMask component from the context menu.
  2. Add a SoftMaskable components to the child UI elements of the SoftMask component.

    Or, add a SoftMaskable components from the inspector of the SoftMask component.
  3. Adjust softness setting of SoftMask.
  4. Enjoy!





Usage with TextMeshPro

To use SoftMask with TextMeshPro, import a sample asset.

  • For Unity 2019.1 or later
    • Open Package Manager window and select UI Soft Mask package in package list and click TextMeshPro Support > Import in project button
  • For Unity 2018.4 or earlier
    • Click Assets/Samples/UISoftMask/Import TextMeshPro Support from menu

The assets will be imported into Assets/Samples/UI Soft Mask/{version}/TextMeshPro Support.

NOTE: You must import TMP Essential Resources before using. They include shaders, fonts, etc.

NOTE: If the shader error is not resolved, reimport the shader. Or, import the TextMeshPro Support again.





Support soft masks with your custom shaders

Only a few steps are needed to support soft mask in your custom shaders!

  1. Duplicate your shader file and add the (SoftMaskable) suffix to the file name.
Your_Custom_Shader.shader
-> Your_Custom_Shader (SoftMaskable).shader
  1. Modify the shader name (defined at the beginning of the shader file) as follows:
  • Add Hidden/ prefix
  • Add (SoftMaskable) suffix
Shader "UI/Your_Custom_Shader"
-> Shader "Hidden/UI/Your_Custom_Shader (SoftMaskable)"
  1. Add #pragma and #include directives, where SOFTMASK_EDITOR is an editor-only keyword and is not included in the build. If you didn't use package manager to install, include SoftMask.cginc in the appropriate path instead.
#include "Packages/com.coffee.softmask-for-ugui/Shaders/SoftMask.cginc"
#pragma shader_feature __ SOFTMASK_EDITOR
  1. Apply a soft mask in the fragment shader.
    This operation determines the final alpha according to the soft mask buffer.
  • IN.vertex: the clip position
  • IN.worldPosition: the world position
color.a *= SoftMask(IN.vertex, IN.worldPosition);

As an example of implementation, please see UI-Default-SoftMask.shader.





Contributing

Issues

Issues are very valuable to this project.

  • Ideas are a valuable source of contributions others can make
  • Problems show where this project is lacking
  • With a question you show where contributors can improve the user experience

Pull Requests

Pull requests are, a great way to get your ideas into this repository.
See CONTRIBUTING.md.

Support

This is an open source project that I am developing in my spare time.
If you like it, please support me.
With your support, I can spend more time on development. :)






License

  • MIT
  • © UTJ/UCL

Author

See Also

softmaskforugui's People

Contributors

iizzaya avatar jnncoutinho avatar manefunction avatar mob-sakai avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

softmaskforugui's Issues

SceneView does not display SoftMask properly

Why is not it displayed properly in SceneView?

SoftMask calculates the final alpha value based on the value of each channel of the soft mask buffer.
The soft mask buffer is a buffer generated based on GameView's screen space.

Since SceneView has a view matrix and a projection matrix independent of GameView, the SceneView's camera can not refer to the soft mask buffer properly.

Therefore, in GameView, it is displayed properly. but in ScreenView, it is displayed like default Mask.

Doesn't work with Screen-Space Overlay

Doesn't work in "Screen Space - Overlay" (shows correctly in the Editor but does not work in-game).

Steps to reproduce the behavior:

  1. Play the included demo.
  2. Scroll to bottom and switch to "Overlay".
  3. Scroll up and notice.
  • Platform: Windows/Editor
  • Unity: 2018.3.8
  • SoftMaskForUGUI: v0.7.1

Capture
Capture1

'Parts of parent' option

From mob-sakai/UnmaskForUGUI#12

I also use the "SoftMaskForUGUI" plugin. That's perfect effect except Inverse SoftMaskable must be the child of SoftMask in Hierarchy. I cannot make multiple holes on one background.
Then I found this plugin "UnmaskForUGUI". It allows me to make multiple holes on one background, but without soft mask effect. Is it possible to use soft mask to make multiple holes on one background?

Doesn't work with 2018.3 Text Mesh Pro Package

Just tried pulling the latest and various shaders try to include Text Mesh Pro cginc files that don't exist as they are managed by Package Manager in /Packages/*

Repro: Try to add your project to a new 2018.3 project with Text Mesh Pro installed via the package manager.

Camera movement affects the mask rendering when on a World Space Canvas.

Hi there!

I have a camera with a script that moves his transform position at update. When playing the game, the camera starts moving the SoftMask instead of letting it at his place, as I show you right here:

Orto1conv

The masked element is on a Canvas with World Space render mode. But furthermore, if I check the maskable element to use Stencil, the movement only applies to the maskable item, the mask stands where I want it.

Orto2

The camera is Orthographic and the hierarchy of the objects is as follows:

image

The behaviour I want is the mask to stay at its place on the real world and not being influenced by the camera movement.

Specs:

  • Platform: Windows 10
  • Unity: [e.g. 2018.2.12f1]
  • SoftMaskForUGUI: v0.7.2

If you want to see some of the code of how I move the camera or some other configurations just ask for it, I will be pleased to show you :)

Despite that, I love the plug-in, great work! 💃

if canvas camera is not set in world space mode, masked contents are not displayed

Describe the bug

  1. When a worldspace camera is used (rather than screen overlay). The Masked content will reduce in width, height as it approaches (0,0)

  2. If worldspace / screenspace camera are chosen and the camera is set in the canvas. The Mask will display nothing.

To Reproduce
Steps to reproduce the behavior:

  1. Import package attached into project with SofMaskForUGUI installed
    2, Check Scene is working Should see UnityChan SoftMasked in a Star
  2. Move Canvas down and or Left
  3. Unity Chan is cropped as approaching (0,0)
    PositionBug.zip

Environment (please complete the following information):

  • Platform Editor (Windows 10 (x64))
  • Unity: [e.g. 2018.3.7f1
  • SoftMaskForUGUI: [e.g. v0.6.0]

Additional context
Add any other context, screenshots or gif animations about the bug here.

Unity 2018.x compile failed

Assets\Coffee\UIExtensions\SoftMaskForUGUI\Scripts\SoftMask.cs(417,33): error CS1061: 'Camera' does not contain a definition for 'reviousViewProjectionMatrix' and no accessible extension method 'reviousViewProjectionMatrix' accepting a first argument of type 'Camera' could be found (are you missing a using directive or an assembly reference?)

Matrix4x4 previousVP = cam.reviousViewProjectionMatrix;

modify to:
Matrix4x4 previousVP = cam.previousViewProjectionMatrix;

Material UI/Default-SoftMask doesn't have _Stencil property

It started happening after tweaking some settings on the mask, and now I can't get it to work again, it is drawing just a pink rectangle.

Edit: I've fixed that by closing the project and deleting the "Library" folder.
Edit2: I'm using Unity 2018.3.1f1

Doesn't work with overlay canvas on 2018.3

Describe the bug
Doesn't work with overlay canvas on 2018.3

To Reproduce
Steps to reproduce the behavior:

  1. Load demo scene
  2. Change canvas render mode to "Screen Space - Overlay"
  3. Play demo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.