release 0.4.0
|
@ -33,7 +33,6 @@ sysinfo.txt
|
||||||
|
|
||||||
|
|
||||||
# Packages
|
# Packages
|
||||||
*.unitypackage
|
|
||||||
build.app
|
build.app
|
||||||
unity.log
|
unity.log
|
||||||
|
|
||||||
|
@ -44,3 +43,4 @@ _WebGL/
|
||||||
_Standalone/
|
_Standalone/
|
||||||
Assets/TextMesh Pro/
|
Assets/TextMesh Pro/
|
||||||
Assets/TextMesh Pro.meta
|
Assets/TextMesh Pro.meta
|
||||||
|
PackageTest
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
[Ll]ibrary/
|
||||||
|
[Tt]emp/
|
||||||
|
[Oo]bj/
|
||||||
|
[Bb]uild/
|
||||||
|
/[Bb]uilds/
|
||||||
|
/Assets/AssetStoreTools*
|
||||||
|
|
||||||
|
# Autogenerated VS/MD solution and project files
|
||||||
|
ExportedObj/
|
||||||
|
*.csproj
|
||||||
|
*.unityproj
|
||||||
|
*.sln
|
||||||
|
*.suo
|
||||||
|
*.tmp
|
||||||
|
*.user
|
||||||
|
*.userprefs
|
||||||
|
*.pidb
|
||||||
|
*.booproj
|
||||||
|
*.svd
|
||||||
|
|
||||||
|
|
||||||
|
# Unity3D generated meta files
|
||||||
|
*.pidb.meta
|
||||||
|
|
||||||
|
# Unity3D Generated File On Crash Reports
|
||||||
|
sysinfo.txt
|
||||||
|
|
||||||
|
# Mac
|
||||||
|
*.DS_Store
|
||||||
|
|
||||||
|
# Builds
|
||||||
|
*.apk
|
||||||
|
|
||||||
|
|
||||||
|
# Packages
|
||||||
|
build.app
|
||||||
|
unity.log
|
||||||
|
|
||||||
|
.vs/
|
||||||
|
_Android/
|
||||||
|
_iOS/
|
||||||
|
_WebGL/
|
||||||
|
_Standalone/
|
||||||
|
Assets/TextMesh Pro/
|
||||||
|
Assets/TextMesh Pro.meta
|
|
@ -1 +0,0 @@
|
||||||
./../../../../CHANGELOG.md
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
## [0.4.0](https://github.com/mob-sakai/SoftMaskForUGUI/tree/0.4.0) (2019-01-13)
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.3.0...0.4.0)
|
||||||
|
|
||||||
|
**Implemented enhancements:**
|
||||||
|
|
||||||
|
- Integrate with UnityPackageManager [\#22](https://github.com/mob-sakai/SoftMaskForUGUI/issues/22)
|
||||||
|
|
||||||
|
**Fixed bugs:**
|
||||||
|
|
||||||
|
- Flipped soft mask texture [\#25](https://github.com/mob-sakai/SoftMaskForUGUI/issues/25)
|
||||||
|
|
||||||
|
## [v0.3.0](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.3.0) (2019-01-07)
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.2.0...v0.3.0)
|
||||||
|
|
||||||
|
**Implemented enhancements:**
|
||||||
|
|
||||||
|
- Remove TMPro resources in repo [\#21](https://github.com/mob-sakai/SoftMaskForUGUI/issues/21)
|
||||||
|
|
||||||
|
**Fixed bugs:**
|
||||||
|
|
||||||
|
- An error occur when SoftMask is destroyed on editor [\#23](https://github.com/mob-sakai/SoftMaskForUGUI/issues/23)
|
||||||
|
|
||||||
|
## [v0.2.0](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.2.0) (2018-12-21)
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.1.0...v0.2.0)
|
||||||
|
|
||||||
|
**Implemented enhancements:**
|
||||||
|
|
||||||
|
- Set default material on disable [\#17](https://github.com/mob-sakai/SoftMaskForUGUI/issues/17)
|
||||||
|
- Component icon [\#15](https://github.com/mob-sakai/SoftMaskForUGUI/issues/15)
|
||||||
|
- Support TextMeshPro [\#14](https://github.com/mob-sakai/SoftMaskForUGUI/issues/14)
|
||||||
|
- Preview soft mask buffer in inspector [\#13](https://github.com/mob-sakai/SoftMaskForUGUI/issues/13)
|
||||||
|
- Add a SoftMaskable component to the child UI elements of SoftMask From the inspector [\#12](https://github.com/mob-sakai/SoftMaskForUGUI/issues/12)
|
||||||
|
- Render the soft mask buffer only when needed to improve performance [\#11](https://github.com/mob-sakai/SoftMaskForUGUI/issues/11)
|
||||||
|
|
||||||
|
**Fixed bugs:**
|
||||||
|
|
||||||
|
- Doesn't work with overlay canvas on 2018.3 [\#20](https://github.com/mob-sakai/SoftMaskForUGUI/issues/20)
|
||||||
|
|
||||||
|
## [v0.1.0](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.1.0) (2018-11-20)
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/0d87935fa566cd1cb5e54a6f8826bb72fffb29b8...v0.1.0)
|
||||||
|
|
||||||
|
**Implemented enhancements:**
|
||||||
|
|
||||||
|
- Convert existing Mask to SoftMask from context menu [\#10](https://github.com/mob-sakai/SoftMaskForUGUI/issues/10)
|
||||||
|
- Desample soft mask buffer to improve performance [\#9](https://github.com/mob-sakai/SoftMaskForUGUI/issues/9)
|
||||||
|
- Custom shaders supporting [\#8](https://github.com/mob-sakai/SoftMaskForUGUI/issues/8)
|
||||||
|
- Filter raycast only for the visible part [\#7](https://github.com/mob-sakai/SoftMaskForUGUI/issues/7)
|
||||||
|
- Inverse soft mask [\#6](https://github.com/mob-sakai/SoftMaskForUGUI/issues/6)
|
||||||
|
- Nested soft masks [\#5](https://github.com/mob-sakai/SoftMaskForUGUI/issues/5)
|
||||||
|
- Support multiple-sprites and SpriteAtlas [\#4](https://github.com/mob-sakai/SoftMaskForUGUI/issues/4)
|
||||||
|
- Adjust the visible part [\#3](https://github.com/mob-sakai/SoftMaskForUGUI/issues/3)
|
||||||
|
- Compatible with Mask [\#2](https://github.com/mob-sakai/SoftMaskForUGUI/issues/2)
|
||||||
|
- Screen space soft masking [\#1](https://github.com/mob-sakai/SoftMaskForUGUI/issues/1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
|
@ -1 +0,0 @@
|
||||||
./../../../../LICENSE.txt
|
|
|
@ -1 +0,0 @@
|
||||||
./../../../../README.md
|
|
|
@ -0,0 +1,336 @@
|
||||||
|
SoftMaskForUGUI
|
||||||
|
===
|
||||||
|
|
||||||
|
Soft masking for uGUI elements in Unity.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
[](https://github.com/mob-sakai/SoftMaskForUGUI/releases)
|
||||||
|
[](https://github.com/mob-sakai/SoftMaskForUGUI/releases)
|
||||||
|

|
||||||
|
[](https://github.com/mob-sakai/SoftMaskForUGUI/blob/master/LICENSE.txt)
|
||||||
|
[](http://makeapullrequest.com)
|
||||||
|
[](https://twitter.com/intent/follow?screen_name=mob_sakai)
|
||||||
|
|
||||||
|
<< [Description](#Description) | [WebGL Demo](#demo) | [Download](https://github.com/mob-sakai/SoftMaskForUGUI/releases) | [Usage](#usage) | [Development Note](#development-note) >>
|
||||||
|
|
||||||
|
### What's new? [See changelog ](https://github.com/mob-sakai/SoftMaskForUGUI/blob/develop/CHANGELOG.md)
|
||||||
|
### Do you want to receive notifications for new releases? [Watch this repo ](https://github.com/mob-sakai/SoftMaskForUGUI/subscription)
|
||||||
|
### Support me on Patreon! [](https://www.patreon.com/join/2343451?)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<br><br><br><br>
|
||||||
|
## Description
|
||||||
|
|
||||||
|
SoftMask is a smooth masking component for uGUI elements in Unity.
|
||||||
|
By using SoftMask instead of default Mask, rounded edges of UI elements can be expressed beautifully.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### 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.
|
||||||
|

|
||||||
|
* 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](#support-soft-masks-in-your-custom-shaders).
|
||||||
|
* 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.
|
||||||
|

|
||||||
|
* Support TextMeshPro.
|
||||||
|

|
||||||
|
|
||||||
|
#### Known issues
|
||||||
|
|
||||||
|
* SceneView does not display SoftMask properly. It is displayed like Mask. ([By design](#why-is-not-it-displayed-properly-in-sceneview))
|
||||||
|
|
||||||
|
#### Components
|
||||||
|
|
||||||
|
|Component|Description|Screenshot|
|
||||||
|
|-|-|-|
|
||||||
|
|SoftMask|Use instead of Mask for smooth masking.<br><br>**Show Mask Graphic:** Show the graphic that is associated with the Mask render area.<br>**Desampling Rate:** The desampling rate for soft mask buffer. The larger the value, the better the performance but the lower the quality.<br>**Softness:** The value used by the soft mask to select the area of influence defined over the soft mask's graphic.<br>**Ignore Parent:** Should the soft mask ignore parent soft masks?|<img src="https://user-images.githubusercontent.com/12690315/50319746-377a0200-050c-11e9-96ae-a3a0ec81765f.png" width="600px">|
|
||||||
|
|SoftMaskable|Add this component to Graphic under SoftMask for smooth masking.<br><br>**Inverse:** The graphic will be visible only in areas where no mask is present.|<img src="https://user-images.githubusercontent.com/12690315/50319747-39dc5c00-050c-11e9-85fa-dd6ea9065daf.png" width="600px">|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<br><br><br><br>
|
||||||
|
## Demo
|
||||||
|
|
||||||
|
[WebGL Demo](http://mob-sakai.github.io/SoftMaskForUGUI)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<br><br><br><br>
|
||||||
|
## Install
|
||||||
|
|
||||||
|
#### Using UnityPackageManager (for Unity 2018.3+)
|
||||||
|
|
||||||
|
Find the manifest.json file in the Packages folder of your project and edit it to look like this:
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"com.coffee.softmask-for-ugui": "https://github.com/mob-sakai/SoftMaskForUGUI.git#0.4.0",
|
||||||
|
...
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Using .unitypackage file (for Unity 2017.1+)
|
||||||
|
|
||||||
|
Download `*.unitypackage` from [Releases](https://github.com/mob-sakai/SoftMaskForUGUI/releases) and import the package into your Unity project.
|
||||||
|
Select `Assets > Import Package > Custom Package` from the menu.
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<br><br><br><br>
|
||||||
|
## How to play demo
|
||||||
|
|
||||||
|
* Import `SoftMask_Demo.unitypackage` into your project.
|
||||||
|
* The unitypackage exists in `Assets/Assets/Coffee/UIExtensions/SoftMaskForUGUI` or `Packages/Soft Mask For uGUI`.
|
||||||
|

|
||||||
|
* Open SoftMask_Demo scene and play it.
|
||||||
|
* The demo requires `TextMeshPro` and `TextMeshPro Essential Resources`. Import it before playing.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<br><br><br><br>
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
1. Add SoftMask component instead of Mask component.
|
||||||
|
Or, convert existing Mask component to SoftMask component from the context menu.
|
||||||
|

|
||||||
|
2. Add SoftMaskable components to the child UI elements of SoftMask component.
|
||||||
|

|
||||||
|
Or, add SoftMaskable components from the inspector of SoftMask component.
|
||||||
|

|
||||||
|
3. Adjust softness of SoftMask.
|
||||||
|

|
||||||
|
4. Enjoy!
|
||||||
|
|
||||||
|
|
||||||
|
##### Requirement
|
||||||
|
|
||||||
|
* Unity 2017+ *(including Unity 2018.x)*
|
||||||
|
* No other SDK are required
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<br><br><br><br>
|
||||||
|
## Development Note
|
||||||
|
|
||||||
|
#### Support soft masks in your custom shaders
|
||||||
|
|
||||||
|
You can support soft masks in your custom shaders, by adding just 3 lines!
|
||||||
|
|
||||||
|
1. Add `#pragma` and `#include`. `SOFTMASK_EDITOR` is a keyword for editor, not included in the build.
|
||||||
|
```
|
||||||
|
#include "Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc"
|
||||||
|
#pragma shader_feature __ SOFTMASK_EDITOR
|
||||||
|
```
|
||||||
|
2. Apply a soft mask in the fragment shader. `IN.vertex` is clip position.
|
||||||
|
```
|
||||||
|
color.a *= SoftMask(IN.vertex);
|
||||||
|
```
|
||||||
|
|
||||||
|
As an example of implementation, please see [UI-Default-SoftMask.shader](https://raw.githubusercontent.com/mob-sakai/SoftMaskForUGUI/master/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Resources/UI-Default-SoftMask.shader).
|
||||||
|
|
||||||
|
|
||||||
|
<br><br>
|
||||||
|
#### 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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
<br><br>
|
||||||
|
#### Tips: Convert component from context menu
|
||||||
|
|
||||||
|
Converting components from the context menu is very convenient.
|
||||||
|
You can convert multiple components at the same time, without having to remove the source components.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
If the destination component has the same properties as the source component, the value is set automatically.
|
||||||
|
|
||||||
|
In addition, if the destination component is compatible with the source component, it will not lose its reference.
|
||||||
|
For example, if `public Mask mask;` refers to a Mask, converting it to SoftMask in this way does not lose references.
|
||||||
|
|
||||||
|
This way consists of two generic methods.
|
||||||
|
|
||||||
|
```cs
|
||||||
|
/// <summary>
|
||||||
|
/// Verify whether it can be converted to the specified component.
|
||||||
|
/// </summary>
|
||||||
|
protected static bool CanConvertTo<T>(Object context)
|
||||||
|
where T : MonoBehaviour
|
||||||
|
{
|
||||||
|
return context && context.GetType() != typeof(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert to the specified component.
|
||||||
|
/// </summary>
|
||||||
|
protected static void ConvertTo<T>(Object context) where T : MonoBehaviour
|
||||||
|
{
|
||||||
|
var target = context as MonoBehaviour;
|
||||||
|
var so = new SerializedObject(target);
|
||||||
|
so.Update();
|
||||||
|
|
||||||
|
bool oldEnable = target.enabled;
|
||||||
|
target.enabled = false;
|
||||||
|
|
||||||
|
// Find MonoScript of the specified component.
|
||||||
|
foreach (var script in Resources.FindObjectsOfTypeAll<MonoScript>())
|
||||||
|
{
|
||||||
|
if (script.GetClass() != typeof(T))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Set 'm_Script' to convert.
|
||||||
|
so.FindProperty("m_Script").objectReferenceValue = script;
|
||||||
|
so.ApplyModifiedProperties();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
(so.targetObject as MonoBehaviour).enabled = oldEnable;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
In SoftMask, they are implemented as follows.
|
||||||
|
* Mask and SoftMask can be converted to each other.
|
||||||
|
* If conversion is not possible, gray out the context menu.
|
||||||
|
|
||||||
|
```cs
|
||||||
|
[MenuItem("CONTEXT/Mask/Convert To SoftMask", true)]
|
||||||
|
static bool _ConvertToSoftMask(MenuCommand command)
|
||||||
|
{
|
||||||
|
return CanConvertTo<SoftMask>(command.context);
|
||||||
|
}
|
||||||
|
[MenuItem("CONTEXT/Mask/Convert To SoftMask", false)]
|
||||||
|
static void ConvertToSoftMask(MenuCommand command)
|
||||||
|
{
|
||||||
|
ConvertTo<SoftMask>(command.context);
|
||||||
|
}
|
||||||
|
[MenuItem("CONTEXT/Mask/Convert To Mask", true)]
|
||||||
|
static bool _ConvertToMask(MenuCommand command)
|
||||||
|
{
|
||||||
|
return CanConvertTo<Mask>(command.context);
|
||||||
|
}
|
||||||
|
[MenuItem("CONTEXT/Mask/Convert To Mask", false)]
|
||||||
|
static void ConvertToMask(MenuCommand command)
|
||||||
|
{
|
||||||
|
ConvertTo<Mask>(command.context);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
For details, please see [SoftMaskEditor.cs](https://raw.githubusercontent.com/mob-sakai/SoftMaskForUGUI/master/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/Editor/SoftMaskEditor.cs).
|
||||||
|
|
||||||
|
|
||||||
|
<br><br>
|
||||||
|
#### Tips: Shader code for editor only
|
||||||
|
|
||||||
|
Do you know how to implement shader code "for editor only"?
|
||||||
|
SoftMask uses `SOFTMASK_EDITOR` keyword in shader code to determine whether it is running in the editor.
|
||||||
|
|
||||||
|
`#pragma shader_feature __ SOFTMASK_EDITOR`
|
||||||
|
|
||||||
|
`SOFTMASK_EDITOR` keyword is set from the editor script, but it is not set after it is built. Also, this shader variant will be excluded from build.
|
||||||
|
|
||||||
|
```cs
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
material = new Material(shader);
|
||||||
|
material.hideFlags = HideFlags.HideAndDontSave;
|
||||||
|
material.EnableKeyword("SOFTMASK_EDITOR");
|
||||||
|
#endif
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
<br><br>
|
||||||
|
#### Tips: Shader code for SceneView only
|
||||||
|
|
||||||
|
Do you know how to implement shader code "for SceneView only"?
|
||||||
|
SoftMask understands that the current rendering is for SceneView, when SceneView's view projection matrix and UNITY_MATRIX_VP match.
|
||||||
|
|
||||||
|
`fixed isSceneView = 1 - any(UNITY_MATRIX_VP - _SceneViewVP);`
|
||||||
|
|
||||||
|
Actually, because of the movement operation in SceneView, use "approximate" instead of "match".
|
||||||
|
|
||||||
|
```cs
|
||||||
|
float4x4 _SceneViewVP;
|
||||||
|
|
||||||
|
fixed Approximate(float4x4 a, float4x4 b)
|
||||||
|
{
|
||||||
|
float4x4 d = abs(a - b);
|
||||||
|
return step(
|
||||||
|
max(d._m00,max(d._m01,max(d._m02,max(d._m03,
|
||||||
|
max(d._m10,max(d._m11,max(d._m12,max(d._m13,
|
||||||
|
max(d._m20,max(d._m21,max(d._m22,max(d._m23,
|
||||||
|
max(d._m30,max(d._m31,max(d._m32,d._m33))))))))))))))),
|
||||||
|
0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
fixed isSceneView = Approximate(UNITY_MATRIX_VP, _SceneViewVP);
|
||||||
|
```
|
||||||
|
|
||||||
|
`_SceneViewVP` is set every frame from the editor script.
|
||||||
|
|
||||||
|
```cs
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
UnityEditor.EditorApplication.update += ()
|
||||||
|
{
|
||||||
|
Camera cam = UnityEditor.SceneView.lastActiveSceneView.camera;
|
||||||
|
Matrix4x4 vp = cam.projectionMatrix * cam.worldToCameraMatrix;
|
||||||
|
material.SetMatrix("_SceneViewVP", vp);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<br><br><br><br>
|
||||||
|
## License
|
||||||
|
|
||||||
|
* MIT
|
||||||
|
* © UTJ/UCL
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
[mob-sakai](https://github.com/mob-sakai)
|
||||||
|
[](https://twitter.com/intent/follow?screen_name=mob_sakai)
|
||||||
|
[](https://www.patreon.com/join/2343451?)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## See Also
|
||||||
|
|
||||||
|
* GitHub page : https://github.com/mob-sakai/SoftMaskForUGUI
|
||||||
|
* Releases : https://github.com/mob-sakai/SoftMaskForUGUI/releases
|
||||||
|
* Issue tracker : https://github.com/mob-sakai/SoftMaskForUGUI/issues
|
||||||
|
* Current project : https://github.com/mob-sakai/SoftMaskForUGUI/projects/1
|
||||||
|
* Change log : https://github.com/mob-sakai/SoftMaskForUGUI/blob/master/CHANGELOG.md
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"name": "Coffee.SoftMaskForUGUI",
|
||||||
|
"references": [],
|
||||||
|
"includePlatforms": [],
|
||||||
|
"excludePlatforms": []
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8ef573751495a4f88822a98a88954a0b
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"name": "Coffee.SoftMaskForUGUI.Editor",
|
||||||
|
"references": [
|
||||||
|
"Coffee.SoftMaskForUGUI"
|
||||||
|
],
|
||||||
|
"includePlatforms": [
|
||||||
|
"Editor"
|
||||||
|
],
|
||||||
|
"excludePlatforms": []
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e8f1dfda17cbd45ad95e761ca8c9b120
|
||||||
|
AssemblyDefinitionImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -57,7 +57,7 @@ Shader "UI/Default-SoftMask"
|
||||||
#pragma multi_compile __ UNITY_UI_CLIP_RECT
|
#pragma multi_compile __ UNITY_UI_CLIP_RECT
|
||||||
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||||
|
|
||||||
#include "Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc" // Add for soft mask
|
#include "./../../SoftMask.cginc" // Add for soft mask
|
||||||
#pragma shader_feature __ SOFTMASK_EDITOR // Add for soft mask
|
#pragma shader_feature __ SOFTMASK_EDITOR // Add for soft mask
|
||||||
|
|
||||||
struct appdata_t
|
struct appdata_t
|
||||||
|
|
|
@ -126,7 +126,7 @@ SubShader {
|
||||||
#include "Assets/TextMesh Pro/Resources/Shaders/TMPro_Properties.cginc"
|
#include "Assets/TextMesh Pro/Resources/Shaders/TMPro_Properties.cginc"
|
||||||
#include "Assets/TextMesh Pro/Resources/Shaders/TMPro.cginc"
|
#include "Assets/TextMesh Pro/Resources/Shaders/TMPro.cginc"
|
||||||
|
|
||||||
#include "Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc"
|
#include "./../SoftMask.cginc"
|
||||||
#pragma shader_feature __ SOFTMASK_EDITOR
|
#pragma shader_feature __ SOFTMASK_EDITOR
|
||||||
|
|
||||||
struct vertex_t {
|
struct vertex_t {
|
||||||
|
|
|
@ -91,7 +91,7 @@ SubShader {
|
||||||
#include "UnityUI.cginc"
|
#include "UnityUI.cginc"
|
||||||
#include "Assets/TextMesh Pro/Resources/Shaders/TMPro_Properties.cginc"
|
#include "Assets/TextMesh Pro/Resources/Shaders/TMPro_Properties.cginc"
|
||||||
|
|
||||||
#include "Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc"
|
#include "./../SoftMask.cginc"
|
||||||
#pragma shader_feature __ SOFTMASK_EDITOR
|
#pragma shader_feature __ SOFTMASK_EDITOR
|
||||||
|
|
||||||
struct vertex_t {
|
struct vertex_t {
|
||||||
|
|
|
@ -56,7 +56,7 @@ Shader "TextMeshPro/Sprite (SoftMaskable)"
|
||||||
#pragma multi_compile __ UNITY_UI_CLIP_RECT
|
#pragma multi_compile __ UNITY_UI_CLIP_RECT
|
||||||
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
||||||
|
|
||||||
#include "Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc"
|
#include "./../SoftMask.cginc"
|
||||||
#pragma shader_feature __ SOFTMASK_EDITOR
|
#pragma shader_feature __ SOFTMASK_EDITOR
|
||||||
|
|
||||||
struct appdata_t
|
struct appdata_t
|
||||||
|
|
|
@ -22,6 +22,10 @@ fixed Approximately(float4x4 a, float4x4 b)
|
||||||
half SoftMask(float4 clipPos)
|
half SoftMask(float4 clipPos)
|
||||||
{
|
{
|
||||||
half2 view = clipPos.xy/_ScreenParams.xy;
|
half2 view = clipPos.xy/_ScreenParams.xy;
|
||||||
|
#if UNITY_UV_STARTS_AT_TOP
|
||||||
|
view.y = 1.0 - view.y;
|
||||||
|
#endif
|
||||||
|
|
||||||
half alpha =
|
half alpha =
|
||||||
lerp(1, tex2D(_SoftMaskTex, view).a, step(15, _Stencil))
|
lerp(1, tex2D(_SoftMaskTex, view).a, step(15, _Stencil))
|
||||||
* lerp(1, tex2D(_SoftMaskTex, view).b, step(7, _Stencil))
|
* lerp(1, tex2D(_SoftMaskTex, view).b, step(7, _Stencil))
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fdbf04e4a4f2a4ce3aebd88b2e996fbe
|
||||||
|
timeCreated: 1547267633
|
||||||
|
licenseType: Pro
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"name": "com.coffee.softmask-for-ugui",
|
||||||
|
"displayName": "Soft Mask For uGUI",
|
||||||
|
"description": "SoftMask is a smooth masking component for uGUI elements in Unity.\nBy using SoftMask instead of default Mask, rounded edges of UI elements can be expressed beautifully.",
|
||||||
|
"version": "0.4.0",
|
||||||
|
"unity": "2017.1",
|
||||||
|
"license": "MIT",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/mob-sakai/SoftMaskForUGUI.git"
|
||||||
|
},
|
||||||
|
"src": "Assets/Coffee/UIExtensions/SoftMaskForUGUI",
|
||||||
|
"author": "mob-sakai <sakai861104@gmail.com> (https://github.com/mob-sakai)",
|
||||||
|
"dependencies": {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c43fd233e88b347cdabc530c23ffe30a
|
||||||
|
timeCreated: 1547268722
|
||||||
|
licenseType: Pro
|
||||||
|
TextScriptImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 70 KiB |
Before Width: | Height: | Size: 147 KiB After Width: | Height: | Size: 147 KiB |
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 6.4 KiB After Width: | Height: | Size: 6.4 KiB |
|
@ -13262,10 +13262,10 @@ RectTransform:
|
||||||
m_Father: {fileID: 1054913042}
|
m_Father: {fileID: 1054913042}
|
||||||
m_RootOrder: 2
|
m_RootOrder: 2
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0, y: 1}
|
||||||
m_AnchorMax: {x: 0, y: 0}
|
m_AnchorMax: {x: 0, y: 1}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 650, y: -4.7160244}
|
||||||
m_SizeDelta: {x: 0, y: 40.56795}
|
m_SizeDelta: {x: 260, y: 40.56795}
|
||||||
m_Pivot: {x: 0.5, y: 1}
|
m_Pivot: {x: 0.5, y: 1}
|
||||||
--- !u!114 &1369788304
|
--- !u!114 &1369788304
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
@ -15126,10 +15126,10 @@ RectTransform:
|
||||||
m_Father: {fileID: 1054913042}
|
m_Father: {fileID: 1054913042}
|
||||||
m_RootOrder: 1
|
m_RootOrder: 1
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0, y: 1}
|
||||||
m_AnchorMax: {x: 0, y: 0}
|
m_AnchorMax: {x: 0, y: 1}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 390, y: -4.7160244}
|
||||||
m_SizeDelta: {x: 0, y: 40.56795}
|
m_SizeDelta: {x: 260, y: 40.56795}
|
||||||
m_Pivot: {x: 0.5, y: 1}
|
m_Pivot: {x: 0.5, y: 1}
|
||||||
--- !u!114 &1544127206
|
--- !u!114 &1544127206
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
@ -16007,7 +16007,7 @@ MonoBehaviour:
|
||||||
m_HorizontalOverflow: 0
|
m_HorizontalOverflow: 0
|
||||||
m_VerticalOverflow: 0
|
m_VerticalOverflow: 0
|
||||||
m_LineSpacing: 1
|
m_LineSpacing: 1
|
||||||
m_Text: '>> SoftMask v0.3.0 <<'
|
m_Text: '>> SoftMask v0.4.0 <<'
|
||||||
--- !u!222 &1590748270
|
--- !u!222 &1590748270
|
||||||
CanvasRenderer:
|
CanvasRenderer:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -20295,10 +20295,10 @@ RectTransform:
|
||||||
m_Father: {fileID: 1054913042}
|
m_Father: {fileID: 1054913042}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0, y: 1}
|
||||||
m_AnchorMax: {x: 0, y: 0}
|
m_AnchorMax: {x: 0, y: 1}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 130, y: -4.7160244}
|
||||||
m_SizeDelta: {x: 0, y: 40.56795}
|
m_SizeDelta: {x: 260, y: 40.56795}
|
||||||
m_Pivot: {x: 0.5, y: 1}
|
m_Pivot: {x: 0.5, y: 1}
|
||||||
--- !u!114 &1986134048
|
--- !u!114 &1986134048
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
Before Width: | Height: | Size: 391 KiB After Width: | Height: | Size: 391 KiB |
51
CHANGELOG.md
|
@ -1,51 +0,0 @@
|
||||||
# Changelog
|
|
||||||
|
|
||||||
## [v0.3.0](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.3.0) (2019-01-07)
|
|
||||||
|
|
||||||
[Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.2.0...v0.3.0)
|
|
||||||
|
|
||||||
**Implemented enhancements:**
|
|
||||||
|
|
||||||
- Remove TMPro resources in repo [\#21](https://github.com/mob-sakai/SoftMaskForUGUI/issues/21)
|
|
||||||
|
|
||||||
**Fixed bugs:**
|
|
||||||
|
|
||||||
- An error occur when SoftMask is destroyed on editor [\#23](https://github.com/mob-sakai/SoftMaskForUGUI/issues/23)
|
|
||||||
|
|
||||||
## [v0.2.0](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.2.0) (2018-12-21)
|
|
||||||
|
|
||||||
[Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v0.1.0...v0.2.0)
|
|
||||||
|
|
||||||
**Implemented enhancements:**
|
|
||||||
|
|
||||||
- Set default material on disable [\#17](https://github.com/mob-sakai/SoftMaskForUGUI/issues/17)
|
|
||||||
- Component icon [\#15](https://github.com/mob-sakai/SoftMaskForUGUI/issues/15)
|
|
||||||
- Support TextMeshPro [\#14](https://github.com/mob-sakai/SoftMaskForUGUI/issues/14)
|
|
||||||
- Preview soft mask buffer in inspector [\#13](https://github.com/mob-sakai/SoftMaskForUGUI/issues/13)
|
|
||||||
- Add a SoftMaskable component to the child UI elements of SoftMask From the inspector [\#12](https://github.com/mob-sakai/SoftMaskForUGUI/issues/12)
|
|
||||||
- Render the soft mask buffer only when needed to improve performance [\#11](https://github.com/mob-sakai/SoftMaskForUGUI/issues/11)
|
|
||||||
|
|
||||||
**Fixed bugs:**
|
|
||||||
|
|
||||||
- Doesn't work with overlay canvas on 2018.3 [\#20](https://github.com/mob-sakai/SoftMaskForUGUI/issues/20)
|
|
||||||
|
|
||||||
## [v0.1.0](https://github.com/mob-sakai/SoftMaskForUGUI/tree/v0.1.0) (2018-11-20)
|
|
||||||
|
|
||||||
[Full Changelog](https://github.com/mob-sakai/SoftMaskForUGUI/compare/0d87935fa566cd1cb5e54a6f8826bb72fffb29b8...v0.1.0)
|
|
||||||
|
|
||||||
**Implemented enhancements:**
|
|
||||||
|
|
||||||
- Convert existing Mask to SoftMask from context menu [\#10](https://github.com/mob-sakai/SoftMaskForUGUI/issues/10)
|
|
||||||
- Desample soft mask buffer to improve performance [\#9](https://github.com/mob-sakai/SoftMaskForUGUI/issues/9)
|
|
||||||
- Custom shaders supporting [\#8](https://github.com/mob-sakai/SoftMaskForUGUI/issues/8)
|
|
||||||
- Filter raycast only for the visible part [\#7](https://github.com/mob-sakai/SoftMaskForUGUI/issues/7)
|
|
||||||
- Inverse soft mask [\#6](https://github.com/mob-sakai/SoftMaskForUGUI/issues/6)
|
|
||||||
- Nested soft masks [\#5](https://github.com/mob-sakai/SoftMaskForUGUI/issues/5)
|
|
||||||
- Support multiple-sprites and SpriteAtlas [\#4](https://github.com/mob-sakai/SoftMaskForUGUI/issues/4)
|
|
||||||
- Adjust the visible part [\#3](https://github.com/mob-sakai/SoftMaskForUGUI/issues/3)
|
|
||||||
- Compatible with Mask [\#2](https://github.com/mob-sakai/SoftMaskForUGUI/issues/2)
|
|
||||||
- Screen space soft masking [\#1](https://github.com/mob-sakai/SoftMaskForUGUI/issues/1)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
|
|
@ -0,0 +1 @@
|
||||||
|
Assets/Coffee/UIExtensions/SoftMaskForUGUI/CHANGELOG.md
|
|
@ -0,0 +1 @@
|
||||||
|
Assets/Coffee/UIExtensions/SoftMaskForUGUI/LICENSE.md
|
|
@ -6,5 +6,5 @@ EditorBuildSettings:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Scenes:
|
m_Scenes:
|
||||||
- enabled: 1
|
- enabled: 1
|
||||||
path: Assets/Coffee/UIExtensions/SoftMaskForUGUI/Demo/SoftMask_Demo.unity
|
path: Assets/SoftMask_Demo/SoftMask_Demo.unity
|
||||||
guid: aa372e7b286d0416eb942adfc3e442ec
|
guid: aa372e7b286d0416eb942adfc3e442ec
|
||||||
|
|
300
README.md
|
@ -1,300 +0,0 @@
|
||||||
SoftMaskForUGUI
|
|
||||||
===
|
|
||||||
|
|
||||||
Soft masking for uGUI elements in Unity.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
[](https://github.com/mob-sakai/SoftMaskForUGUI/releases)
|
|
||||||
[](https://github.com/mob-sakai/SoftMaskForUGUI/releases)
|
|
||||||

|
|
||||||
[](https://github.com/mob-sakai/SoftMaskForUGUI/blob/master/LICENSE.txt)
|
|
||||||
[](http://makeapullrequest.com)
|
|
||||||
|
|
||||||
<< [Description](#Description) | [WebGL Demo](#demo) | [Download](https://github.com/mob-sakai/SoftMaskForUGUI/releases) | [Usage](#usage) | [Development Note](#development-note) >>
|
|
||||||
|
|
||||||
### What's new? [See changelog ](https://github.com/mob-sakai/SoftMaskForUGUI/blob/develop/CHANGELOG.md)
|
|
||||||
### Do you want to receive notifications for new releases? [Watch this repo ](https://github.com/mob-sakai/SoftMaskForUGUI/subscription)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<br><br><br><br>
|
|
||||||
## Description
|
|
||||||
|
|
||||||
SoftMask is a smooth masking component for uGUI elements in Unity.
|
|
||||||
By using SoftMask instead of default Mask, rounded edges of UI elements can be expressed beautifully.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
#### 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.
|
|
||||||

|
|
||||||
* 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](#support-soft-masks-in-your-custom-shaders).
|
|
||||||
* 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.
|
|
||||||

|
|
||||||
* Support TextMeshPro.
|
|
||||||

|
|
||||||
|
|
||||||
#### Known issues
|
|
||||||
|
|
||||||
* SceneView does not display SoftMask properly. It is displayed like Mask. ([By design](#why-is-not-it-displayed-properly-in-sceneview))
|
|
||||||
|
|
||||||
#### Components
|
|
||||||
|
|
||||||
|Component|Description|Screenshot|
|
|
||||||
|-|-|-|
|
|
||||||
|SoftMask|Use instead of Mask for smooth masking.<br><br>**Show Mask Graphic:** Show the graphic that is associated with the Mask render area.<br>**Desampling Rate:** The desampling rate for soft mask buffer. The larger the value, the better the performance but the lower the quality.<br>**Softness:** The value used by the soft mask to select the area of influence defined over the soft mask's graphic.<br>**Ignore Parent:** Should the soft mask ignore parent soft masks?|<img src="https://user-images.githubusercontent.com/12690315/50319746-377a0200-050c-11e9-96ae-a3a0ec81765f.png" width="600px">|
|
|
||||||
|SoftMaskable|Add this component to Graphic under SoftMask for smooth masking.<br><br>**Inverse:** The graphic will be visible only in areas where no mask is present.|<img src="https://user-images.githubusercontent.com/12690315/50319747-39dc5c00-050c-11e9-85fa-dd6ea9065daf.png" width="600px">|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<br><br><br><br>
|
|
||||||
## Demo
|
|
||||||
|
|
||||||
[WebGL Demo](http://mob-sakai.github.io/SoftMaskForUGUI)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<br><br><br><br>
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
1. Download `*.unitypackage` from [Releases](https://github.com/mob-sakai/SoftMaskForUGUI/releases).
|
|
||||||
2. Import the package into your Unity project. Select `Import Package > Custom Package` from the `Assets` menu.
|
|
||||||

|
|
||||||
3. Add SoftMask component instead of Mask component. Or, convert existing Mask component to SoftMask component from the context menu.
|
|
||||||

|
|
||||||
4. Add SoftMaskable components to the child UI elements of SoftMask component.
|
|
||||||

|
|
||||||
Or, add SoftMaskable components from the inspector of SoftMask component.
|
|
||||||

|
|
||||||
5. Adjust softness of SoftMask.
|
|
||||||

|
|
||||||
6. Enjoy!
|
|
||||||
|
|
||||||
|
|
||||||
##### Requirement
|
|
||||||
|
|
||||||
* Unity 2017+ *(including Unity 2018.x)*
|
|
||||||
* No other SDK are required
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<br><br><br><br>
|
|
||||||
## Development Note
|
|
||||||
|
|
||||||
#### Support soft masks in your custom shaders
|
|
||||||
|
|
||||||
You can support soft masks in your custom shaders, by adding just 3 lines!
|
|
||||||
|
|
||||||
1. Add `#pragma` and `#include`. `SOFTMASK_EDITOR` is a keyword for editor, not included in the build.
|
|
||||||
```
|
|
||||||
#include "Assets/Coffee/UIExtensions/SoftMaskForUGUI/SoftMask.cginc"
|
|
||||||
#pragma shader_feature __ SOFTMASK_EDITOR
|
|
||||||
```
|
|
||||||
2. Apply a soft mask in the fragment shader. `IN.vertex` is clip position.
|
|
||||||
```
|
|
||||||
color.a *= SoftMask(IN.vertex);
|
|
||||||
```
|
|
||||||
|
|
||||||
As an example of implementation, please see [UI-Default-SoftMask.shader](https://raw.githubusercontent.com/mob-sakai/SoftMaskForUGUI/master/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Resources/UI-Default-SoftMask.shader).
|
|
||||||
|
|
||||||
|
|
||||||
<br><br>
|
|
||||||
#### 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.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
<br><br>
|
|
||||||
#### Tips: Convert component from context menu
|
|
||||||
|
|
||||||
Converting components from the context menu is very convenient.
|
|
||||||
You can convert multiple components at the same time, without having to remove the source components.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
If the destination component has the same properties as the source component, the value is set automatically.
|
|
||||||
|
|
||||||
In addition, if the destination component is compatible with the source component, it will not lose its reference.
|
|
||||||
For example, if `public Mask mask;` refers to a Mask, converting it to SoftMask in this way does not lose references.
|
|
||||||
|
|
||||||
This way consists of two generic methods.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
/// <summary>
|
|
||||||
/// Verify whether it can be converted to the specified component.
|
|
||||||
/// </summary>
|
|
||||||
protected static bool CanConvertTo<T>(Object context)
|
|
||||||
where T : MonoBehaviour
|
|
||||||
{
|
|
||||||
return context && context.GetType() != typeof(T);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Convert to the specified component.
|
|
||||||
/// </summary>
|
|
||||||
protected static void ConvertTo<T>(Object context) where T : MonoBehaviour
|
|
||||||
{
|
|
||||||
var target = context as MonoBehaviour;
|
|
||||||
var so = new SerializedObject(target);
|
|
||||||
so.Update();
|
|
||||||
|
|
||||||
bool oldEnable = target.enabled;
|
|
||||||
target.enabled = false;
|
|
||||||
|
|
||||||
// Find MonoScript of the specified component.
|
|
||||||
foreach (var script in Resources.FindObjectsOfTypeAll<MonoScript>())
|
|
||||||
{
|
|
||||||
if (script.GetClass() != typeof(T))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Set 'm_Script' to convert.
|
|
||||||
so.FindProperty("m_Script").objectReferenceValue = script;
|
|
||||||
so.ApplyModifiedProperties();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
(so.targetObject as MonoBehaviour).enabled = oldEnable;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
In SoftMask, they are implemented as follows.
|
|
||||||
* Mask and SoftMask can be converted to each other.
|
|
||||||
* If conversion is not possible, gray out the context menu.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
[MenuItem("CONTEXT/Mask/Convert To SoftMask", true)]
|
|
||||||
static bool _ConvertToSoftMask(MenuCommand command)
|
|
||||||
{
|
|
||||||
return CanConvertTo<SoftMask>(command.context);
|
|
||||||
}
|
|
||||||
[MenuItem("CONTEXT/Mask/Convert To SoftMask", false)]
|
|
||||||
static void ConvertToSoftMask(MenuCommand command)
|
|
||||||
{
|
|
||||||
ConvertTo<SoftMask>(command.context);
|
|
||||||
}
|
|
||||||
[MenuItem("CONTEXT/Mask/Convert To Mask", true)]
|
|
||||||
static bool _ConvertToMask(MenuCommand command)
|
|
||||||
{
|
|
||||||
return CanConvertTo<Mask>(command.context);
|
|
||||||
}
|
|
||||||
[MenuItem("CONTEXT/Mask/Convert To Mask", false)]
|
|
||||||
static void ConvertToMask(MenuCommand command)
|
|
||||||
{
|
|
||||||
ConvertTo<Mask>(command.context);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
For details, please see [SoftMaskEditor.cs](https://raw.githubusercontent.com/mob-sakai/SoftMaskForUGUI/master/Assets/Coffee/UIExtensions/SoftMaskForUGUI/Scripts/Editor/SoftMaskEditor.cs).
|
|
||||||
|
|
||||||
|
|
||||||
<br><br>
|
|
||||||
#### Tips: Shader code for editor only
|
|
||||||
|
|
||||||
Do you know how to implement shader code "for editor only"?
|
|
||||||
SoftMask uses `SOFTMASK_EDITOR` keyword in shader code to determine whether it is running in the editor.
|
|
||||||
|
|
||||||
`#pragma shader_feature __ SOFTMASK_EDITOR`
|
|
||||||
|
|
||||||
`SOFTMASK_EDITOR` keyword is set from the editor script, but it is not set after it is built. Also, this shader variant will be excluded from build.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
material = new Material(shader);
|
|
||||||
material.hideFlags = HideFlags.HideAndDontSave;
|
|
||||||
material.EnableKeyword("SOFTMASK_EDITOR");
|
|
||||||
#endif
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
<br><br>
|
|
||||||
#### Tips: Shader code for SceneView only
|
|
||||||
|
|
||||||
Do you know how to implement shader code "for SceneView only"?
|
|
||||||
SoftMask understands that the current rendering is for SceneView, when SceneView's view projection matrix and UNITY_MATRIX_VP match.
|
|
||||||
|
|
||||||
`fixed isSceneView = 1 - any(UNITY_MATRIX_VP - _SceneViewVP);`
|
|
||||||
|
|
||||||
Actually, because of the movement operation in SceneView, use "approximate" instead of "match".
|
|
||||||
|
|
||||||
```cs
|
|
||||||
float4x4 _SceneViewVP;
|
|
||||||
|
|
||||||
fixed Approximate(float4x4 a, float4x4 b)
|
|
||||||
{
|
|
||||||
float4x4 d = abs(a - b);
|
|
||||||
return step(
|
|
||||||
max(d._m00,max(d._m01,max(d._m02,max(d._m03,
|
|
||||||
max(d._m10,max(d._m11,max(d._m12,max(d._m13,
|
|
||||||
max(d._m20,max(d._m21,max(d._m22,max(d._m23,
|
|
||||||
max(d._m30,max(d._m31,max(d._m32,d._m33))))))))))))))),
|
|
||||||
0.01);
|
|
||||||
}
|
|
||||||
|
|
||||||
fixed isSceneView = Approximate(UNITY_MATRIX_VP, _SceneViewVP);
|
|
||||||
```
|
|
||||||
|
|
||||||
`_SceneViewVP` is set every frame from the editor script.
|
|
||||||
|
|
||||||
```cs
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
UnityEditor.EditorApplication.update += ()
|
|
||||||
{
|
|
||||||
Camera cam = UnityEditor.SceneView.lastActiveSceneView.camera;
|
|
||||||
Matrix4x4 vp = cam.projectionMatrix * cam.worldToCameraMatrix;
|
|
||||||
material.SetMatrix("_SceneViewVP", vp);
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<br><br><br><br>
|
|
||||||
## License
|
|
||||||
|
|
||||||
* MIT
|
|
||||||
* © UTJ/UCL
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Author
|
|
||||||
|
|
||||||
[mob-sakai](https://github.com/mob-sakai)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## See Also
|
|
||||||
|
|
||||||
* GitHub page : https://github.com/mob-sakai/SoftMaskForUGUI
|
|
||||||
* Releases : https://github.com/mob-sakai/SoftMaskForUGUI/releases
|
|
||||||
* Issue tracker : https://github.com/mob-sakai/SoftMaskForUGUI/issues
|
|
||||||
* Current project : https://github.com/mob-sakai/SoftMaskForUGUI/projects/1
|
|
||||||
* Change log : https://github.com/mob-sakai/SoftMaskForUGUI/blob/master/CHANGELOG.md
|
|
|
@ -0,0 +1 @@
|
||||||
|
Assets/Coffee/UIExtensions/SoftMaskForUGUI/README.md
|
10
package.json
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"name": "SoftMaskForUGUI",
|
|
||||||
"version": "0.3.0",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/mob-sakai/SoftMaskForUGUI.git"
|
|
||||||
},
|
|
||||||
"src": "Assets/Coffee/UIExtensions/SoftMaskForUGUI",
|
|
||||||
"license": "MIT"
|
|
||||||
}
|
|
|
@ -0,0 +1 @@
|
||||||
|
Assets/Coffee/UIExtensions/SoftMaskForUGUI/package.json
|
|
@ -1,5 +0,0 @@
|
||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
# NOTE: Set an environment variable `CHANGELOG_GITHUB_TOKEN` by running the following command at the prompt, or by adding it to your shell profile (e.g., ~/.bash_profile or ~/.zshrc):
|
|
||||||
# export CHANGELOG_GITHUB_TOKEN="«your-40-digit-github-token»"
|
|
||||||
bash <(curl -sL 'https://gist.github.com/mob-sakai/a883999a32dd8b1927639e46b3cd6801/raw/unity_release.sh')
|
|
|
@ -0,0 +1,137 @@
|
||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
# NOTE: Run the following command at the prompt
|
||||||
|
# bash <(curl -sL 'https://gist.github.com/mob-sakai/a883999a32dd8b1927639e46b3cd6801/raw/unity_release.sh')
|
||||||
|
# NOTE: Set an environment variable `CHANGELOG_GITHUB_TOKEN` by running the following command at the prompt, or by adding it to your shell profile (e.g., ~/.bash_profile or ~/.zshrc):
|
||||||
|
# export CHANGELOG_GITHUB_TOKEN="«your-40-digit-github-token»"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 1. << Input release version >>
|
||||||
|
echo -e ">> Start Github Release:"
|
||||||
|
PACKAGE_NAME=`node -pe 'require("./package.json").name'`
|
||||||
|
echo -e ">> Package name: ${PACKAGE_NAME}"
|
||||||
|
CURRENT_VERSION=`grep -o -e "\"version\".*$" package.json | sed -e "s/\"version\": \"\(.*\)\".*$/\1/"`
|
||||||
|
|
||||||
|
read -p "[? (1/8) Input release version (for current: ${CURRENT_VERSION}): " RELEASE_VERSION
|
||||||
|
[ -z "${RELEASE_VERSION}" ] && exit
|
||||||
|
|
||||||
|
read -p "[? Are the issues on this release closed all? (y/N):" yn
|
||||||
|
case "$yn" in [yY]*) ;; *) exit ;; esac
|
||||||
|
|
||||||
|
read -p "[? Is package editor only? (y/N):" yn
|
||||||
|
case "$yn" in [yY]*) EDITOR_ONLY=true;; *) ;; esac
|
||||||
|
|
||||||
|
read -p "[? Is package for UnityPackageManager? (y/N):" yn
|
||||||
|
case "$yn" in [yY]*) UNITY_PACKAGE_MANAGER=true;; *) ;; esac
|
||||||
|
|
||||||
|
echo -e ">> OK"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 2. << Update version in package.json >>
|
||||||
|
echo -e "\n>> (2/8) Update version... package.json"
|
||||||
|
[ -L package.json ] && PKG_JSON_PATH=`readlink package.json` || PKG_JSON_PATH=package.json
|
||||||
|
git checkout -B release develop
|
||||||
|
sed -i -e "s/\"version\": \(.*\)/\"version\": \"${RELEASE_VERSION}\",/g" "${PKG_JSON_PATH}"
|
||||||
|
rm "${PKG_JSON_PATH}-e"
|
||||||
|
echo -e ">> OK"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 3. << Check unity editor is exist and no compile error >>
|
||||||
|
UNITY_VER=`sed -e "s/m_EditorVersion: \(.*\)/\1/g" ProjectSettings/ProjectVersion.txt`
|
||||||
|
UNITY_EDITOR="/Applications/Unity/Hub/Editor/${UNITY_VER}/Unity.app/Contents/MacOS/Unity"
|
||||||
|
UNITY_LOG="unity.log"
|
||||||
|
UNITY_ARGS="-quit -batchmode -projectPath `pwd` -logFile $UNITY_LOG"
|
||||||
|
UNITY_PACKAGE_SRC=`node -pe 'require("./package.json").src'`
|
||||||
|
UNITY_PACKAGE_NAME="${PACKAGE_NAME}_${RELEASE_VERSION}.unitypackage"
|
||||||
|
echo -e "\n>> (3/8) Check exporting package is available..."
|
||||||
|
echo -e "Version: $UNITY_VER ($UNITY_EDITOR)"
|
||||||
|
echo -e "Package Source: $UNITY_PACKAGE_SRC"
|
||||||
|
|
||||||
|
# 3-1. Is src directory exist?
|
||||||
|
[ ! -d "$UNITY_PACKAGE_SRC" ] && echo -e "\n>> Error : $UNITY_PACKAGE_SRC is not exist." && exit
|
||||||
|
|
||||||
|
# 3-2. Is runtime compile successfully?
|
||||||
|
set +e
|
||||||
|
if [ "$EDITOR_ONLY" != "true" ]; then
|
||||||
|
echo -e "\n>> compile for runtime..."
|
||||||
|
"$UNITY_EDITOR" $UNITY_ARGS -buildOSX64Player `pwd`/build.app
|
||||||
|
[ $? != 0 ] && echo -e "\n>> Error : \n`cat $UNITY_LOG | grep -E ': error CS|Fatal Error'`" && exit
|
||||||
|
echo -e ">> OK"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 3-3. Is exporting package successfully?
|
||||||
|
echo -e "\n>> Pre export package..."
|
||||||
|
"$UNITY_EDITOR" $UNITY_ARGS -exportpackage $UNITY_PACKAGE_SRC $UNITY_PACKAGE_NAME
|
||||||
|
[ $? != 0 ] && echo -e "\n>> Error : \n`cat $UNITY_LOG | grep -E ': error CS|Fatal Error'`" && exit
|
||||||
|
echo -e ">> OK"
|
||||||
|
set -e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 4. << Generate change log >>
|
||||||
|
CHANGELOG_GENERATOR_ARG=`grep -o -e ".*git\"$" package.json | sed -e "s/^.*\/\([^\/]*\)\/\([^\/]*\).git.*$/--user \1 --project \2/"`
|
||||||
|
CHANGELOG_GENERATOR_ARG="--future-release ${RELEASE_VERSION} ${CHANGELOG_GENERATOR_ARG}"
|
||||||
|
echo -e "\n>> (4/8) Generate change log... ${CHANGELOG_GENERATOR_ARG}"
|
||||||
|
github_changelog_generator ${CHANGELOG_GENERATOR_ARG}
|
||||||
|
|
||||||
|
[ -L CHANGELOG.md ] && git diff -- `readlink CHANGELOG.md` || git diff -- CHANGELOG.md
|
||||||
|
read -p "[? Is the change log correct? (y/N):" yn
|
||||||
|
case "$yn" in [yY]*) ;; *) exit ;; esac
|
||||||
|
echo -e ">> OK"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 5. << Export unitypackage >>
|
||||||
|
echo -e "\n>> (5/8) Export unitypackage..."
|
||||||
|
set +e
|
||||||
|
"$UNITY_EDITOR" $UNITY_ARGS -exportpackage $UNITY_PACKAGE_SRC $UNITY_PACKAGE_NAME
|
||||||
|
[ $? != 0 ] && echo -e "\n>> Error : \n`cat $UNITY_LOG | grep -E ': error CS|Fatal Error'`" && exit
|
||||||
|
set -e
|
||||||
|
echo -e ">> OK"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 6. << Commit release files >>
|
||||||
|
echo -e "\n>> (6/8) Commit release files..."
|
||||||
|
[ -L CHANGELOG.md ] && git add -- "`readlink CHANGELOG.md`" || git add -- CHANGELOG.md
|
||||||
|
[ -L package.json ] && git add -- "`readlink package.json`" || git add -- package.json
|
||||||
|
git commit -m "update change log"
|
||||||
|
echo -e ">> OK"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 7. << Split for upm >>
|
||||||
|
if [ "$UNITY_PACKAGE_MANAGER" == "true" ]; then
|
||||||
|
echo -e "\n>> Split for upm..."
|
||||||
|
git subtree split --prefix="$UNITY_PACKAGE_SRC" --branch upm
|
||||||
|
git push origin upm
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 7. << Merge and push master and develop branch >>
|
||||||
|
echo -e "\n>> (7/8) Merge and push..."
|
||||||
|
git checkout master
|
||||||
|
git merge --no-ff release -m "release $RELEASE_VERSION"
|
||||||
|
git branch -D release
|
||||||
|
git push origin master
|
||||||
|
git checkout develop
|
||||||
|
git merge --ff master
|
||||||
|
git push origin develop
|
||||||
|
echo -e ">> OK"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 8. << Upload unitypackage and release on Github >>
|
||||||
|
echo -e "\n>> (8/8) Releasing..."
|
||||||
|
[ "$UNITY_PACKAGE_MANAGER" == "true" ] && git checkout upm -f
|
||||||
|
gh-release --assets $UNITY_PACKAGE_NAME --name $RELEASE_VERSION --tag_name $RELEASE_VERSION
|
||||||
|
echo -e ">> OK"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
echo -e "\n\n>> $PACKAGE_NAME $RELEASE_VERSION has been successfully released!\n"
|