1.0.0-preview.14

# [1.0.0-preview.14](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v1.0.0-preview.13...v1.0.0-preview.14) (2020-10-08)

### Bug Fixes

* incorrect behavior when a world space canvas and an overlay canvas are enabled together ([a6e82fa](a6e82fa2a7)), closes [#107](https://github.com/mob-sakai/SoftMaskForUGUI/issues/107)
pull/122/head
semantic-release-bot 2020-10-08 15:59:24 +00:00
parent 73177082e5
commit 5c54622518
5 changed files with 63 additions and 28 deletions

View File

@ -1,3 +1,10 @@
# [1.0.0-preview.14](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v1.0.0-preview.13...v1.0.0-preview.14) (2020-10-08)
### Bug Fixes
* incorrect behavior when a world space canvas and an overlay canvas are enabled together ([a6e82fa](https://github.com/mob-sakai/SoftMaskForUGUI/commit/a6e82fa2a7baa06aa4e1fb7e4a8099c5e1039d67)), closes [#107](https://github.com/mob-sakai/SoftMaskForUGUI/issues/107)
# [1.0.0-preview.13](https://github.com/mob-sakai/SoftMaskForUGUI/compare/v1.0.0-preview.12...v1.0.0-preview.13) (2020-10-01)

View File

@ -54,8 +54,6 @@ namespace Coffee.UISoftMask
private static int s_ColorMaskId;
private static int s_MainTexId;
private static int s_SoftnessId;
private static int s_GameVPId;
private static int s_GameTVPId;
private static int s_Alpha;
private static int s_PreviousWidth;
private static int s_PreviousHeight;
@ -363,10 +361,6 @@ namespace Coffee.UISoftMask
s_MainTexId = Shader.PropertyToID("_MainTex");
s_SoftnessId = Shader.PropertyToID("_Softness");
s_Alpha = Shader.PropertyToID("_Alpha");
#if UNITY_EDITOR
s_GameVPId = Shader.PropertyToID("_GameVP");
s_GameTVPId = Shader.PropertyToID("_GameTVP");
#endif
}
}
@ -611,12 +605,6 @@ namespace Coffee.UISoftMask
{
var p = GL.GetGPUProjectionMatrix(cam.projectionMatrix, false);
_cb.SetViewProjectionMatrices(cam.worldToCameraMatrix, p);
#if UNITY_EDITOR
var pv = p * cam.worldToCameraMatrix;
_cb.SetGlobalMatrix(s_GameVPId, pv);
_cb.SetGlobalMatrix(s_GameTVPId, pv);
#endif
}
else
{
@ -624,15 +612,6 @@ namespace Coffee.UISoftMask
var vm = Matrix4x4.TRS(new Vector3(-pos.x, -pos.y, -1000), Quaternion.identity, new Vector3(1, 1, -1f));
var pm = Matrix4x4.TRS(new Vector3(0, 0, -1), Quaternion.identity, new Vector3(1 / pos.x, 1 / pos.y, -2 / 10000f));
_cb.SetViewProjectionMatrices(vm, pm);
#if UNITY_EDITOR
var scale = c.transform.localScale.x;
var size = (c.transform as RectTransform).sizeDelta;
var gameVp = Matrix4x4.TRS(new Vector3(0, 0, 0.5f), Quaternion.identity, new Vector3(2 / size.x, 2 / size.y, 0.0005f * scale));
var gameTvp = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(1 / pos.x, 1 / pos.y, -2 / 2000f)) * Matrix4x4.Translate(-pos);
_cb.SetGlobalMatrix(s_GameVPId, gameVp);
_cb.SetGlobalMatrix(s_GameTVPId, gameTvp);
#endif
}
Profiler.EndSample();

View File

@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
using UnityEngine.UI;
using MaskIntr = UnityEngine.SpriteMaskInteraction;
@ -28,6 +30,8 @@ namespace Coffee.UISoftMask
private static int s_SoftMaskTexId;
private static int s_StencilCompId;
private static int s_MaskInteractionId;
private static int s_GameVPId;
private static int s_GameTVPId;
private static List<SoftMaskable> s_ActiveSoftMaskables;
private static int[] s_Interactions = new int[4];
@ -98,6 +102,8 @@ namespace Coffee.UISoftMask
get { return _softMask ? _softMask : _softMask = this.GetComponentInParentEx<SoftMask>(); }
}
public Material modifiedMaterial { get; private set; }
/// <summary>
/// Perform material modification in this function.
/// </summary>
@ -106,6 +112,7 @@ namespace Coffee.UISoftMask
Material IMaterialModifier.GetModifiedMaterial(Material baseMaterial)
{
_softMask = null;
modifiedMaterial = null;
// If this component is disabled, the material is returned as is.
// If the parents do not have a soft mask component, the material is returned as is.
@ -126,15 +133,17 @@ namespace Coffee.UISoftMask
);
// Generate soft maskable material.
var modifiedMaterial = MaterialCache.Register(baseMaterial, _effectMaterialHash, mat =>
modifiedMaterial = MaterialCache.Register(baseMaterial, _effectMaterialHash, mat =>
{
mat.shader = Shader.Find(string.Format("Hidden/{0} (SoftMaskable)", mat.shader.name));
#if UNITY_EDITOR
mat.EnableKeyword("SOFTMASK_EDITOR");
#endif
mat.SetTexture(s_SoftMaskTexId, softMask.softMaskBuffer);
mat.SetInt(s_StencilCompId, m_UseStencil ? (int) CompareFunction.Equal : (int) CompareFunction.Always);
#if UNITY_EDITOR
mat.EnableKeyword("SOFTMASK_EDITOR");
UpdateMaterialForSceneView(mat);
#endif
var root = MaskUtilities.FindRootSortOverrideCanvas(transform);
var stencil = MaskUtilities.GetStencilDepth(transform, root);
mat.SetVector(s_MaskInteractionId, new Vector4(
@ -235,6 +244,11 @@ namespace Coffee.UISoftMask
s_SoftMaskTexId = Shader.PropertyToID("_SoftMaskTex");
s_StencilCompId = Shader.PropertyToID("_StencilComp");
s_MaskInteractionId = Shader.PropertyToID("_MaskInteraction");
#if UNITY_EDITOR
s_GameVPId = Shader.PropertyToID("_GameVP");
s_GameTVPId = Shader.PropertyToID("_GameTVP");
#endif
}
s_ActiveSoftMaskables.Add(this);
@ -258,6 +272,41 @@ namespace Coffee.UISoftMask
}
#if UNITY_EDITOR
private void UpdateMaterialForSceneView(Material mat)
{
if(!mat || !graphic || !graphic.canvas || !mat.shader || !mat.shader.name.EndsWith(" (SoftMaskable)")) return;
// 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)
{
var p = GL.GetGPUProjectionMatrix(cam.projectionMatrix, false);
var pv = p * cam.worldToCameraMatrix;
mat.SetMatrix(s_GameVPId, pv);
mat.SetMatrix(s_GameTVPId, pv);
}
else
{
var pos = c.transform.position;
var scale = c.transform.localScale.x;
var size = (c.transform as RectTransform).sizeDelta;
var gameVp = Matrix4x4.TRS(new Vector3(0, 0, 0.5f), Quaternion.identity, new Vector3(2 / size.x, 2 / size.y, 0.0005f * scale));
var gameTvp = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(1 / pos.x, 1 / pos.y, -2 / 2000f)) * Matrix4x4.Translate(-pos);
mat.SetMatrix(s_GameVPId, gameVp);
mat.SetMatrix(s_GameTVPId, gameTvp);
}
Profiler.EndSample();
}
private void LateUpdate()
{
UpdateMaterialForSceneView(modifiedMaterial);
}
/// <summary>
/// This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
/// </summary>

View File

@ -39,7 +39,7 @@ float SoftMaskInternal(float4 clipPos)
fixed4 mask = tex2D(_SoftMaskTex, view);
half4 alpha = saturate(lerp(fixed4(1, 1, 1, 1), lerp(mask, 1 - mask, _MaskInteraction - 1), _MaskInteraction));
#if SOFTMASK_EDITOR
alpha = lerp(fixed4(1, 1, 1, 1), alpha, step(0, view.x) * step(view.x, 1) * step(0, view.y) * step(view.y, 1));
alpha *= step(0, view.x) * step(view.x, 1) * step(0, view.y) * step(view.y, 1);
#endif
return alpha.x * alpha.y * alpha.z * alpha.w;

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.13",
"version": "1.0.0-preview.14",
"unity": "2017.1",
"license": "MIT",
"repository": {