1.0.0-preview.4

# [1.0.0-preview.4](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v1.0.0-preview.3...v1.0.0-preview.4) (2020-06-07)

### Bug Fixes

* fix the tooltip text ([f38f034](f38f034148))

### Features

* add a new option to ignore stencil if it is not needed as a mask ([9edcb2d](9edcb2d22b))
* add a new public property 'useStencil' ([09dbaad](09dbaad203))
* improve performance ([018ec78](018ec78c75))
pull/122/head
semantic-release-bot 2020-06-07 04:19:49 +00:00
parent 9ad7d46a10
commit 9aa9f568b8
10 changed files with 1592 additions and 1582 deletions

View File

@ -1,3 +1,17 @@
# [1.0.0-preview.4](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v1.0.0-preview.3...v1.0.0-preview.4) (2020-06-07)
### Bug Fixes
* fix the tooltip text ([f38f034](https://github.com/mob-sakai/SoftMaskForUGUI/commit/f38f0341480cfd8eda6bea3e488c7ae052b89924))
### Features
* add a new option to ignore stencil if it is not needed as a mask ([9edcb2d](https://github.com/mob-sakai/SoftMaskForUGUI/commit/9edcb2d22be25c285b0a7f853314884c3e9df499))
* add a new public property 'useStencil' ([09dbaad](https://github.com/mob-sakai/SoftMaskForUGUI/commit/09dbaad203fa9eaaa16abf683add04267f82439d))
* improve performance ([018ec78](https://github.com/mob-sakai/SoftMaskForUGUI/commit/018ec78c759745907c2e06d3ab09167939bdb05a))
# [1.0.0-preview.3](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v1.0.0-preview.2...v1.0.0-preview.3) (2020-06-04)

View File

@ -1,84 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at sakai861104@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series of actions.
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 749522d1ca2f64743bbfc6d79fe7b3fd
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,92 +0,0 @@
# How to Contribute
## 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
Thank you for creating them.
<br><br><br>
## Pull Requests
Pull requests are, a great way to get your ideas into this repository.
When deciding if I merge in a pull request I look at the following things:
### Does it state intent
You should be clear which problem you're trying to solve with your contribution.
For example:
```
Add link to code of conduct in README.md
```
Doesn't tell me anything about why you're doing that
```
Add link to code of conduct in README.md because users don't always look in the CONTRIBUTING.md
```
Tells me the problem that you have found, and the pull request shows me the action you have taken to solve it.
### Is it of good quality
- There are no spelling mistakes
- It reads well
- For english language contributions: Has a good score on Grammarly or Hemingway App
### Does it move this repository closer to my vision for the repository
- The aim of this repository is:
- To provide a README.md and assorted documents anyone can copy and paste, into their project
- The content is usable by someone who hasn't written something like this before
- Foster a culture of respect and gratitude in the open source community
### Does it follow the contributor covenant
This repository has a [code of conduct](/CODE_OF_CONDUCT.md), I will remove things that do not respect it.
### Does it follow the development steps
1. Fork the repository.
2. Clone the forked repository to local.
3. Create your branch from `develop` branch.
4. Develop the package.
5. Commit with a message based on [Conventional Commits](https://www.conventionalcommits.org/).
1. Fill out the description, link any related issues and submit your pull request.
**NOTE: Create a pull request to merge into `develop` branch**
#### Commit messages in the most common cases
| Case | Commit message|
| -- | -- |
| Added a new feature | feat: add new feature |
| Added a suggested feature #999 | feat: add new feature<br>Close #999 |
| Fixed a bug | fix: a problem |
| Fixed a reported bug #999 | fix: a problem<br>Close #999 |
| Added features that include breaking changes | feat: add new feature<br><br>BREAKING CHANGE: Details of the changes |
<br><br><br>
## 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. :)
[![](https://user-images.githubusercontent.com/12690315/50731629-3b18b480-11ad-11e9-8fad-4b13f27969c1.png)](https://www.patreon.com/join/2343451?)
[![](https://user-images.githubusercontent.com/12690315/66942881-03686280-f085-11e9-9586-fc0b6011029f.png)](https://github.com/users/mob-sakai/sponsorship)
<br><br><br>
## License
By contributing to this repository, you agree that your contributions will be licensed under its MIT license.

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 306151da6f11d48f784c6af3b1ef390d
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
using UnityEngine.UI;
using Object = UnityEngine.Object;
@ -67,7 +68,7 @@ namespace Coffee.UISoftMask
[SerializeField, Tooltip("The desampling rate for soft mask buffer.")]
private DesamplingRate m_DesamplingRate = DesamplingRate.None;
private DesamplingRate m_DesamplingRate = DesamplingRate.x1;
[SerializeField, Range(0.01f, 1), Tooltip("The value used by the soft mask to select the area of influence defined over the soft mask's graphic.")]
private float m_Softness = 1;
@ -81,10 +82,13 @@ namespace Coffee.UISoftMask
[SerializeField, Tooltip("Is the soft mask a part of parent soft mask?")]
private bool m_PartOfParent = false;
[SerializeField, Tooltip("Self Graphic will not be drawn to soft mask buffer.")]
[SerializeField, Tooltip("Self graphic will not be drawn to soft mask buffer.")]
private bool m_IgnoreSelfGraphic;
[SerializeField, Tooltip("Self graphic will not be written to stencil buffer.")]
private bool m_IgnoreSelfStencil;
/// <summary>
/// The desampling rate for soft mask buffer.
/// </summary>
@ -224,6 +228,20 @@ namespace Coffee.UISoftMask
}
}
public bool ignoreSelfStencil
{
get { return m_IgnoreSelfStencil; }
set
{
if (m_IgnoreSelfStencil == value) return;
m_IgnoreSelfStencil = value;
hasChanged = true;
graphic.SetVerticesDirtyEx();
graphic.SetMaterialDirtyEx();
}
}
Material material
{
@ -253,6 +271,8 @@ namespace Coffee.UISoftMask
public override Material GetModifiedMaterial(Material baseMaterial)
{
hasChanged = true;
if (ignoreSelfStencil) return baseMaterial;
var result = base.GetModifiedMaterial(baseMaterial);
if (m_IgnoreParent && result != baseMaterial)
{
@ -282,9 +302,17 @@ namespace Coffee.UISoftMask
if (ignoreSelfGraphic)
{
verts.Clear();
verts.FillMesh(mesh);
}
else if (ignoreSelfStencil)
{
verts.FillMesh(mesh);
verts.Clear();
}
else
{
verts.FillMesh(mesh);
}
verts.FillMesh(mesh);
}
hasChanged = true;
@ -443,6 +471,7 @@ namespace Coffee.UISoftMask
/// </summary>
static void UpdateMaskTextures()
{
Profiler.BeginSample("UpdateMaskTextures");
foreach (var sm in s_ActiveSoftMasks)
{
if (!sm || sm._hasChanged)
@ -458,6 +487,7 @@ namespace Coffee.UISoftMask
if (!cam)
continue;
Profiler.BeginSample("Check view projection matrix changed (world space)");
var nowVP = cam.projectionMatrix * cam.worldToCameraMatrix;
var previousVP = default(Matrix4x4);
var id = cam.GetInstanceID();
@ -468,6 +498,8 @@ namespace Coffee.UISoftMask
{
sm.hasChanged = true;
}
Profiler.EndSample();
}
var rt = sm.rectTransform;
@ -484,6 +516,7 @@ namespace Coffee.UISoftMask
#endif
}
Profiler.BeginSample("Update changed soft masks");
foreach (var sm in s_ActiveSoftMasks)
{
if (!sm || !sm._hasChanged)
@ -495,16 +528,25 @@ namespace Coffee.UISoftMask
if (!sm._hasStencilStateChanged) continue;
sm._hasStencilStateChanged = false;
Profiler.BeginSample("Notify stencil state changed");
MaskUtilities.NotifyStencilStateChanged(sm);
Profiler.EndSample();
}
Profiler.EndSample();
Profiler.BeginSample("Update previous view projection matrices");
s_PreviousViewProjectionMatrices.Clear();
foreach (var id in s_NowViewProjectionMatrices.Keys)
foreach (var kv in s_NowViewProjectionMatrices)
{
s_PreviousViewProjectionMatrices[id] = s_NowViewProjectionMatrices[id];
s_PreviousViewProjectionMatrices.Add(kv.Key, kv.Value);
}
s_NowViewProjectionMatrices.Clear();
Profiler.EndSample();
Profiler.EndSample();
}
/// <summary>
@ -513,11 +555,14 @@ namespace Coffee.UISoftMask
private void UpdateMaskTexture()
{
if (!graphic || !graphic.canvas) return;
Profiler.BeginSample("UpdateMaskTexture");
_stencilDepth =
MaskUtilities.GetStencilDepth(transform, MaskUtilities.FindRootSortOverrideCanvas(transform));
// Collect children soft masks.
Profiler.BeginSample("Collect children soft masks");
var depth = 0;
s_TmpSoftMasks[0].Add(this);
while (_stencilDepth + depth < 3)
@ -538,12 +583,17 @@ namespace Coffee.UISoftMask
depth++;
}
// Clear.
Profiler.EndSample();
// CommandBuffer.
Profiler.BeginSample("Initialize CommandBuffer");
_cb.Clear();
_cb.SetRenderTarget(softMaskBuffer);
_cb.ClearRenderTarget(false, true, s_ClearColors[_stencilDepth]);
Profiler.EndSample();
// Set view and projection matrices.
Profiler.BeginSample("Set view and projection matrices");
var c = graphic.canvas.rootCanvas;
var cam = c.worldCamera ?? Camera.main;
if (c && c.renderMode != RenderMode.ScreenSpaceOverlay && cam)
@ -577,7 +627,10 @@ namespace Coffee.UISoftMask
#endif
}
Profiler.EndSample();
// Draw soft masks.
Profiler.BeginSample("Draw Mesh");
for (var i = 0; i < s_TmpSoftMasks.Length; i++)
{
var count = s_TmpSoftMasks[i].Count;
@ -604,7 +657,10 @@ namespace Coffee.UISoftMask
s_TmpSoftMasks[i].Clear();
}
Profiler.EndSample();
Graphics.ExecuteCommandBuffer(_cb);
Profiler.EndSample();
}
/// <summary>

View File

@ -71,6 +71,20 @@ namespace Coffee.UISoftMask
set { m_RaycastFilter = value; }
}
/// <summary>
/// Use stencil to mask.
/// </summary>
public bool useStencil
{
get { return m_UseStencil; }
set
{
if (m_UseStencil == value) return;
m_UseStencil = value;
graphic.SetMaterialDirtyEx();
}
}
/// <summary>
/// The graphic associated with the soft mask.
/// </summary>
@ -121,11 +135,14 @@ namespace Coffee.UISoftMask
mat.SetTexture(s_SoftMaskTexId, softMask.softMaskBuffer);
mat.SetInt(s_StencilCompId,
m_UseStencil ? (int) CompareFunction.Equal : (int) CompareFunction.Always);
var root = MaskUtilities.FindRootSortOverrideCanvas(transform);
var stencil = MaskUtilities.GetStencilDepth(transform, root);
mat.SetVector(s_MaskInteractionId, new Vector4(
(m_MaskInteraction & 0x3),
((m_MaskInteraction >> 2) & 0x3),
((m_MaskInteraction >> 4) & 0x3),
((m_MaskInteraction >> 6) & 0x3)
1 <= stencil ? (m_MaskInteraction >> 0 & 0x3) : 0,
2 <= stencil ? (m_MaskInteraction >> 2 & 0x3) : 0,
3 <= stencil ? (m_MaskInteraction >> 4 & 0x3) : 0,
4 <= stencil ? (m_MaskInteraction >> 6 & 0x3) : 0
));
});

View File

@ -7,24 +7,6 @@ float4x4 _GameVP;
float4x4 _GameTVP;
half4 _MaskInteraction;
fixed Approximately(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.0000001);
}
float GetMaskAlpha(float alpha, int stencilId, float interaction)
{
fixed onStencil = step(stencilId, _Stencil);
alpha = lerp(1, alpha, onStencil * step(1, interaction));
return lerp(alpha, 1 - alpha, onStencil * step(2, interaction));
}
#if SOFTMASK_EDITOR
float SoftMaskInternal(float4 clipPos, float4 wpos)
#else
@ -33,7 +15,7 @@ float SoftMaskInternal(float4 clipPos)
{
half2 view = clipPos.xy/_ScreenParams.xy;
#if SOFTMASK_EDITOR
fixed isSceneView = 1 - Approximately(UNITY_MATRIX_VP, _GameVP);
fixed isSceneView = any(UNITY_MATRIX_VP - _GameVP);
float4 cpos = mul(_GameTVP, mul(UNITY_MATRIX_M, wpos));
view = lerp(view, cpos.xy / cpos.w * 0.5 + 0.5, isSceneView);
#if UNITY_UV_STARTS_AT_TOP
@ -44,16 +26,13 @@ float SoftMaskInternal(float4 clipPos)
#endif
fixed4 mask = tex2D(_SoftMaskTex, view);
half alpha = GetMaskAlpha(mask.x, 1, _MaskInteraction.x)
* GetMaskAlpha(mask.y, 3, _MaskInteraction.y)
* GetMaskAlpha(mask.z, 7, _MaskInteraction.z)
* GetMaskAlpha(mask.w, 15, _MaskInteraction.w)
half4 alpha = saturate(lerp(fixed4(1, 1, 1, 1), lerp(mask, 1 - mask, _MaskInteraction - 1), _MaskInteraction))
#if SOFTMASK_EDITOR
* step(0, view.x) * step(view.x, 1) * step(0, view.y) * step(view.y, 1)
#endif
;
return alpha;
return alpha.x * alpha.y * alpha.z * alpha.w;
}
#if SOFTMASK_EDITOR

View File

@ -2,7 +2,7 @@
"name": "com.coffee.softmask-for-ugui",
"displayName": "UI Soft Mask",
"description": "UI Soft Mask is a smooth masking component for Unity UI (uGUI) elements.\nBy using SoftMask instead of the default Mask component, you can beautifully represent the rounded edges of UI elements.",
"version": "1.0.0-preview.3",
"version": "1.0.0-preview.4",
"unity": "2017.1",
"license": "MIT",
"repository": {