Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Soft Mask - A replacement of Unity UI Mask with alpha support

Discussion in 'Assets and Asset Store' started by zxkne, Feb 4, 2017.

  1. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    @andrew_pearce_, thank you for the kind words! :)

    I see, you already got the point that Soft Mask doesn't use the stencil buffer. In essence, its working is pretty easy. Soft Mask just adds an additional texture sample into the regular shader that is used to draw UI elements. Note, the masked elements, not the mask itself. Mask itself isn't drawn at all. All the magic of Soft Mask is automatic on-the-fly replacement of a material/shader in a way that doesn't bother you with manual management of materials and shaders (unless you want to).

    Don't be afraid of the shader, it looks ugly but you probably don't need to understand how this sliced/tiled logic works. I just checked it out, it figured out to be even simpler than I thought. You just need to remove the UnityGet2DClipping() part:
    Code (CSharp):
    1. inline float SoftMask_GetMask(float2 maskPosition) {
    2.     float2 uv = SoftMask_GetMaskUV(maskPosition);
    3.     float4 mask = tex2D(_SoftMask, uv) * _SoftMask_ChannelWeights;
    4.     return dot(mask, 1);
    5. }
    6.  
    Which results in this:
    upload_2018-12-20_0-14-28.png
     
    Last edited: Dec 21, 2018
  2. t-seki

    t-seki

    Joined:
    Aug 27, 2014
    Posts:
    2
    iPhone6 iOS8.2 Graphic Metal Error!!
    Do you have any solutions?

    Xcode Log


    Compiler connection failed

    #include <metal_stdlib>
    #include <metal_texture>
    using namespace metal;
    #if !(__HAVE_FMA__)
    #define fma(a,b,c) ((a) * (b) + (c))
    #endif
    #ifndef XLT_REMAP_O
    #define XLT_REMAP_O {0, 1, 2, 3, 4, 5, 6, 7}
    #endif
    constexpr constant uint xlt_remap_o[] = XLT_REMAP_O;
    struct FGlobals_Type
    {
    float4 _SoftMask_Rect;
    float4 _SoftMask_UVRect;
    float4 _SoftMask_ChannelWeights;
    float4 _SoftMask_BorderRect;
    float4 _SoftMask_UVBorderRect;
    half4 _TextureSampleAdd;
    };
    struct Mtl_FragmentIn
    {
    half4 COLOR0 [[ user(COLOR0) ]] ;
    float2 TEXCOORD0 [[ user(TEXCOORD0) ]] ;
    float4 TEXCOORD2 [[ user(TEXCOORD2) ]] ;
    };
    struct Mtl_FragmentOut
    {
    half4 SV_Target0 [[ color(xlt_remap_o[0]) ]];
    };
    fragment Mtl_FragmentOut xlatMtlMain(
    constant FGlobals_Type& FGlobals [[ buffer(0) ]],
    sampler sampler_SoftMask [[ sampler (0) ]],
    sampler sampler_MainTex [[ sampler (1) ]],
    texture2d<half, access::sample > _MainTex [[ texture (0) ]] ,
    texture2d<half, access::sample > _SoftMask [[ texture (1) ]] ,
    Mtl_FragmentIn input [[ stage_in ]])
    {
    Mtl_FragmentOut output;
    float4 u_xlat0;
    half4 u_xlat16_0;
    int2 u_xlati0;
    bool4 u_xlatb0;
    float4 u_xlat1;
    half4 u_xlat16_1;
    bool2 u_xlatb1;
    float4 u_xlat2;
    float4 u_xlat3;
    float2 u_xlat4;
    bool2 u_xlatb4;
    float2 u_xlat8;
    bool2 u_xlatb8;
    float2 u_xlat9;
    u_xlatb0 = (input.TEXCOORD2.xyxy>=FGlobals._SoftMask_BorderRect);
    u_xlat1 = select(float4(0.0, 0.0, 0.0, 0.0), float4(1.0, 1.0, 1.0, 1.0), bool4(u_xlatb0));
    u_xlat2.x = (u_xlatb0.z) ? float(0.0) : u_xlat1.x;
    u_xlat2.y = (u_xlatb0.w) ? float(0.0) : u_xlat1.y;
    u_xlat2.z = (u_xlatb0.z) ? float(0.0) : u_xlat1.x;
    u_xlat2.w = (u_xlatb0.w) ? float(0.0) : u_xlat1.y;
    u_xlat1.xy = u_xlat1.zw * u_xlat1.xy;
    u_xlati0.xy = int2(uint2(u_xlatb0.xy) * 0xffffffffu | uint2(u_xlatb0.zw) * 0xffffffffu);
    u_xlat0.x = (u_xlati0.x != 0) ? float(0.0) : float(1.0);
    u_xlat0.y = (u_xlati0.y != 0) ? float(0.0) : float(1.0);
    u_xlat3 = u_xlat2.zwzw * FGlobals._SoftMask_BorderRect;
    u_xlat2 = u_xlat2 * FGlobals._SoftMask_UVBorderRect;
    u_xlat8.xy = fma(FGlobals._SoftMask_BorderRect.xy, u_xlat0.xy, u_xlat3.zw);
    u_xlat9.xy = fma(FGlobals._SoftMask_Rect.xy, u_xlat0.xy, u_xlat3.xy);
    u_xlat9.xy = fma(FGlobals._SoftMask_BorderRect.zw, u_xlat1.xy, u_xlat9.xy);
    u_xlat8.xy = fma(FGlobals._SoftMask_Rect.zw, u_xlat1.xy, u_xlat8.xy);
    u_xlat8.xy = (-u_xlat9.xy) + u_xlat8.xy;
    u_xlat9.xy = (-u_xlat9.xy) + input.TEXCOORD2.xy;
    u_xlat9.xy = u_xlat9.xy / u_xlat8.xy;
    u_xlatb8.xy = (u_xlat8.xy!=float2(0.0, 0.0));
    u_xlat8.xy = select(float2(0.0, 0.0), u_xlat9.xy, bool2(u_xlatb8.xy));
    u_xlat9.xy = fma(FGlobals._SoftMask_UVBorderRect.xy, u_xlat0.xy, u_xlat2.zw);
    u_xlat0.xy = fma(FGlobals._SoftMask_UVRect.xy, u_xlat0.xy, u_xlat2.xy);
    u_xlat0.xy = fma(FGlobals._SoftMask_UVBorderRect.zw, u_xlat1.xy, u_xlat0.xy);
    u_xlat1.xy = fma(FGlobals._SoftMask_UVRect.zw, u_xlat1.xy, u_xlat9.xy);
    u_xlat1.xy = (-u_xlat0.xy) + u_xlat1.xy;
    u_xlat0.xy = fma(u_xlat8.xy, u_xlat1.xy, u_xlat0.xy);
    u_xlat16_0 = _SoftMask.sample(sampler_SoftMask, u_xlat0.xy);
    u_xlat0 = float4(u_xlat16_0) * FGlobals._SoftMask_ChannelWeights;
    u_xlat0.x = dot(u_xlat0, float4(1.0, 1.0, 1.0, 1.0));
    u_xlatb4.xy = (input.TEXCOORD2.xy>=FGlobals._SoftMask_Rect.xy);
    u_xlat4.xy = select(float2(0.0, 0.0), float2(1.0, 1.0), bool2(u_xlatb4.xy));
    u_xlatb1.xy = (FGlobals._SoftMask_Rect.zw>=input.TEXCOORD2.xy);
    u_xlat1.xy = select(float2(0.0, 0.0), float2(1.0, 1.0), bool2(u_xlatb1.xy));
    u_xlat4.xy = u_xlat4.xy * u_xlat1.xy;
    u_xlat4.x = u_xlat4.y * u_xlat4.x;
    u_xlat0.x = u_xlat4.x * u_xlat0.x;
    u_xlat16_1 = _MainTex.sample(sampler_MainTex, input.TEXCOORD0.xy);
    u_xlat16_1 = u_xlat16_1 + FGlobals._TextureSampleAdd;
    u_xlat1 = float4(u_xlat16_1) * float4(input.COLOR0);
    u_xlat1.w = u_xlat0.x * u_xlat1.w;
    output.SV_Target0 = half4(u_xlat1);
    return output;
    }
     
  3. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Hello! It looks like a random error in the shader compiler. Have you tried to rebuild/reopen Unity project or reimport Soft Mask shaders?

    Could you provide a bit more information about the issue?
    1. When this error occurs? During import, build or at runtime?
    2. Which version of Unity are you using?
    3. Could you provide a minimal example that reproduces the issue?
     
  4. t-seki

    t-seki

    Joined:
    Aug 27, 2014
    Posts:
    2
    It was useless even to make a minimum configuration of the project.

    > When this error occurs? During import, build or at runtime?
    While running in the iPhone6 (iOS8.2)

    > Which version of Unity are you using?
    Unity 2017.4.10f1
    Xcode 9.2
    SoftMask 1.3.1

    > Could you provide a minimal example that reproduces the issue?
    Please check the attached image
     

    Attached Files:

  5. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    @Toshikazu-Seki, thank you for the detailed info!

    Unfortunately, I have no chance to test the solution on the actual iOS device. I can provide you a refund if you send me the invoice number in PM or email.

    I'm still pretty sure that it's a Metal shader compiler's issue just because a compiler should never fail with this kind of error. If it's not critical for you to use Metal on this version of iOS, you could try OpenGL as this ticket suggests (here's yet another case).
     
  6. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    324
    Hi! Does it work on mobile devices ?
     
  7. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Hi!

    Well, it depends on what you mean by 'work'. It definitely works in terms that you could use it in a mobile project and it will behave the same way as at desktop platforms. If you're asking about performance on mobile, I couldn't give you a definitive answer. SoftMask shader is more complicated than a regular UI shader. It adds one additional texture sample and some computation complexity amount of which depends on the mask type (Simple, Sliced, etc). That is, shader performance depends on how many UI elements is under a mask (because this shader is only used for masked elements). CPU performance depends mostly on how frequently the mask's transform changes and how often new elements go under a mask and back.

    If doubt, you may give it a try. If performance wouldn't satisfy you, I'll provide a refund.
     
  8. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    267
    Hello

    I own both this asset and "Procedural UI Image" by Josh H, they're both great on their own, and I'm happy with both... but they're not compatible between them.

    Do you think there could be something in your side you could do to make them compatible? or do you think it should be on the Procedural UI Image asset side?
     
  9. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Hello again, @daville!

    Josh contacted me some time ago about potential integration between our packages. We discussed some details and now I'm planning to include the simplest possible integration into the next version. 'The simplest possible' means that Soft Mask will be able to mask Procedural Images the same way as other UI elements but it still will be not possible to use a Procedural Image as a mask. I'm thinking about using RenderTexture to solve this second problem (and also make it possible to use, say, texts as the mask source) but it's not for the nearest future.

    If you're interested exactly in masking Procedural Images by a Soft Mask, keep reading because I've good news for you!

    Soft Mask may be easily extended to support custom shaders. I've used this feature and implemented support of Procedural Image shader:

    softmask-and-proceduraluiimage.gif

    To achieve this result you only need to add two files to your project:

    project-content.png
    Take a look at these two files:
    1. ProceduralImageRuntime-SoftMask.shader
    2. ProceduralUIImageMaterialReplacer.cs
    The first one is a copy of the original Procedural UI Image shader with some special instructions added. I can't share the full shader here because it's a part of a third-party asset. But I provide you a patch that you could apply to the original shader (Assets/ProceduralUIImage/Resources/Shaders/ProceduralImageRuntime.shader).

    The second file is a simple script that tells Soft Mask that the original Procedural UI Image shader should be replaced by the new one when an element using it is nested into a Soft Mask.

    Both the patch and script could be found in a zip archive attached to this post. Also, note that the resulted shader should reside in the Resources subfolder, otherwise Unity will be not able to load it at runtime.

    That may sound complicated, I understand. But you can do all this stuff without modifying either Soft Mask and Procedural UI Image. And there are good chances that the next version of Soft Mask will have a menu item to apply integration automatically, similar to how it made for TextMesh Pro.

    Hopefully, that helps you and others who interested in using Soft Mask and Procedural UI Image together. Feel free to ask me if you have any further questions.
     

    Attached Files:

    Last edited: Mar 16, 2019
    cybersoft and daville like this.
  10. daville

    daville

    Joined:
    Aug 5, 2012
    Posts:
    267
    Thank you :D I'll check it out.
     
  11. ExcellencyHong

    ExcellencyHong

    Joined:
    Aug 9, 2016
    Posts:
    17
    i made custom shader. and i need to change some material properties in runtime. how can i change a Material property of a Custom Shader?
     
  12. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Hello,
    There is a set of methods in the Material class in form of SetXXX: SetVector, SetTexture, etc. So, in essence, you just need to do something like this:
    Code (CSharp):
    1. graphic.materialForRendering.SetVector("MyProperty", myValue);
    Where
    graphic
    is a reference to a Graphic and
    myValue
    is the value that you want to set. BUT. There is a nuance. Material that's returned by the materialForRendering property (and by material too) may be shared between many Graphic objects. For example, if you created a material in the Project tab from your shader and assigned it to two Image elements, they both with share the same material instance. If you don't want to change the property for both images simultaneously, you have to create a dynamic copy, like so:
    Code (CSharp):
    1. public void Awake() {
    2.     graphic.material = new Material(graphic.material);
    3. }
    4.  
     
  13. ExcellencyHong

    ExcellencyHong

    Joined:
    Aug 9, 2016
    Posts:
    17
    thanks for your answer!

    i have definitely worked same with you already. but it is not worked for me. also, i called the Dirty method.
    when i attach the soft mask component to the parent of any graphic object, the material is disabled and then the material properties go not changable in runtime.

    so, i modified little bit the SoftMask class. i added a code that needed to me in "Apply" method in the MaterialParameters struct. and call this method manually.
     
  14. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Oh, sorry for my premature answer. Now I tried to perform the same thing for a Graphic nested into a Soft Mask and stumbled with the same issues. I'm going to investigate it further and will contact you as soon as I figure out what to do with it.
     
  15. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    @ExcellencyHong,
    I finally figured out what's going on and prepared an example of how to use dynamic material properties. The key points are:
    • The material property should be used instead of materialForRendering. The latter is a material with all the modifiers applied but it actually doesn't suit us. Material modifiers may return a temporal copy of the original material (it's exactly the case when Soft Mask is used) so we apply our changes to a temporal copy which will be not used at all (because the very next call of materialForRendering may regenerate materials).
    • After changing material parameters you should call Graphic.SetMaterialDirty. It will reapply material modifiers, so they will get a chance to pick up material changes.
    I've attached an example of using dynamic material property with Soft Mask. To see it in action, create an empty Unity project, import Soft Mask package and then the attached package (via Assets / Import Package / Custom Package).
     

    Attached Files:

  16. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    312
    Hi @zxkne, I have a UX requirement to implement nested masks, however, as informed on the component it is not supported. Since we have a fairly complex UI, not being able to nest with soft edges kinda defeats the purpose of using this asset.
    Is there any way around it or plans to support it soft mask nesting?
     
  17. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Hi @FernandoHC,
    Sorry to disappoint but there are no such plans yet. I see the most straightforward way of implementing this in using Render Textures. That is, we render a UI element (Graphic) into a Render Texture and then use that texture as a mask for its children. I've performed some research on this topic but I don't have any concrete plans yet so I can't tell you when this will be implemented if it will be at all.
     
    FernandoHC likes this.
  18. Checko

    Checko

    Joined:
    Oct 23, 2013
    Posts:
    16
    Hello. This is currently not masking text mesh pro elements. Is there something im missing in the setup?
    The example provided in the package also is not masking TMPro. Im using the packages v. 1.3.0 of TMPro with Unity v. 2018.3

    Best

    UPDATE - I ran "Update Text Mesh Pro integration" and it is resolved.
     
    Last edited: Apr 5, 2019
    zxkne likes this.
  19. any_user

    any_user

    Joined:
    Oct 19, 2008
    Posts:
    346
    hi @zxkne.

    I'm using SoftMask since a few weeks with Unity 2018.3.x. It works very well so far on iOS and win/mac/linux builds with good performance, but on Android the performance is extremely bad. Rendering one masked image with a mask in "sliced" mode covering 1/10 of the screen area takes around 300ms (!) for rendering each frame.

    I tested it on a phone with Mali 400 gpu. The time spent rendering depends on how much screen space the image covers, so I assume the time is spent in the fragment shader – do you have any ideas how to improve that? Could some parts of the mask mapping be done in the vertex shader instead?

    I currently replace it with a "normal" unity mask as a workaround, which works without problems at 60fps.
     
  20. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Hi @any_user,

    I guess it highly depends on a concrete device. On a phone with Adreno 530 I have no performance issues in covering the whole screen by masked images in the sliced mode. But I understand that you're orienting on a wide audience and want your application to work well on various devices. So as a first step, I suggest small research:
    1. Have you tried simple mode instead? Does it improve performance? If yes, how much this performance differs from a non-masked image (or masked by Unity standard Mask)?
    2. If simple mode works well for you, can you use it instead? At least at these specific devices. If you don't resize the mask dynamically you probably may prepare an image of the required size. If your image should fit various screen sizes and shapes, maybe it's an option to prepare several such images?
    What's about moving computation to the vertex shader, I currently see no easy way to do it. The thing is that the geometry of masked objects stays untouched, it doesn't reflect 'sliced' or 'tiled' drawing mode. So in these modes, there are always be a situation when neighbor pixels from the same triangle go into different slices of a 9-stretch image.

    Please, let me know what you'll find out.
     
  21. pixelminer

    pixelminer

    Joined:
    Jul 24, 2011
    Posts:
    9
    Hi. Love the package. Unfortunately it won't compile in Unity 2019 due to System.Reflection.Emit not being allowed in 2019 as described here which means no TypeBuilder class.

    https://docs.unity3d.com/Manual/ScriptingRestrictions.html

    Are there plans to support 2019? I have to migrate to 2019 and would hate to lose Soft Mask because of it. Thanks.
     
  22. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Hi @pixelminer,

    Thank you for the kind words! I definitely plan to support 2019, I just haven't faced this issue yet.

    I'm trying to reproduce the compilation issue you're describing but have no success yet. Could you help me by answering the following questions?
    • Are you using Soft Mask 1.3.1? There was a little modification related to the usage of TypeBuilder. It should be guarded with #ifs. Could you check if it's true? File MaterialReplacer.cs:
    Code (CSharp):
    1. static bool IsMaterialReplacerType(Type t) {
    2. #if NET_STANDARD_2_0
    3.     var isTypeBuilder = false;
    4. #else
    5.     var isTypeBuilder = t is TypeBuilder;
    6. #endif
    7.     ...
    • Can you share your scripting settings from Project Settings / Player / Other Settings / Configuration?
    upload_2019-5-10_11-36-15.png
    • Which platform are you targeting (Windows, iOS, WebGL, etc.)?
    Although I haven't reproduced the issue, I have an idea of what may help. Could you modify the aforementioned #ifs this way? At the beginning of MaterialReplacer.cs:
    Code (CSharp):
    1. #if !(NET_STANDARD_2_0 || ENABLE_IL2CPP)
    And in IsMaterialReplacerType method:
    Code (CSharp):
    1. #if NET_STANDARD_2_0 || ENABLE_IL2CPP
     
  23. pixelminer

    pixelminer

    Joined:
    Jul 24, 2011
    Posts:
    9
    Hi. I just updated to 1.3.1 and the Unity 2019.1 issue is no more. Thanks!
     
  24. karam89

    karam89

    Joined:
    Aug 23, 2015
    Posts:
    6
    Hello @zxkne

    I'm buying your asset, which seems to be great

    I'm planning to use it with a jigsaw puzzle game targeted for mobiles

    So I've 2 questions:
    1- Does SoftMask support setting the mask quality? and can we change the quality (if supported) in runtime without high costs?
    2- Our jigsaw puzzle grids might have 560 pieces (the worst case) is SoftMask eligible for this amount of UI pieces (of course in this case we might set the quality to low if SoftMask support setting the quality feature)

    Best regards
     
  25. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Hello @karam89

    I wouldn't recommend Soft Mask for your task. It's optimized for cases when there are a few masks and many masked elements. Each mask has its own material so different masks can't be batched together. Here is an example of Frame Debugger window for a scene with 3 separate masks:

    JigsawFrameProfilerExample.PNG

    As you can see, each image is drawn in a separate Draw Call. So, in your worst case, you'll get 560 draw calls, which may be inappropriate.

    Soft Mask uses separate materials for each mask because it has a relatively complicated parameter set for each mask which is necessary to support complicated mapping (sliced, tiled) and sampling (channel weights). So it would be a huge overhead to pass them via vertex attributes.

    A better solution for your task is to use the second UV for vertices and sample 2 textures in the shader, each by its own UV. A classical multi-texturing, essentially.

    Thanks for asking.
     
  26. PigBang

    PigBang

    Joined:
    Sep 19, 2016
    Posts:
    5
    Hello. We have bug with soft mask, when use Sliced Image Type on Huawei p8:
     
  27. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Hello,

    I think it may be related to the way shader compiler works on this platform. I cannot reproduce the issue on this device. Could I ask you to help me localize the issue?

    First, I suggest checking what UVs are actually used for mask sampling. To see it, please, replace the following lines (SoftMaskTemplate.cginc, 81):
    Code (CSharp):
    1.         color.a *= SOFTMASK_GET_MASK(IN);
    with this:
    Code (CSharp):
    1. #ifdef __SOFTMASK_ENABLE
    2.         color = half4(SoftMask_GetMaskUV(IN.maskPosition.xy), 0, 0.5f);
    3. #endif
    Then run the program on the device and show a screenshot of how it looks like. It should be a green-red picture like this one:
    upload_2019-6-3_21-45-42.png

    Also, as always, if you don't want to investigate the issue and want to stop using Soft Mask, just send me the invoice number and I'll provide you a refund.

    Thank you!
     
  28. PigBang

    PigBang

    Joined:
    Sep 19, 2016
    Posts:
    5
  29. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    @PigBang,
    That's exactly what I wanted to see. Thank you! I need some time to further research the issue. I'll let you know as soon as I get something.
     
  30. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    @PigBang,
    Sorry to say, but I still haven't succeeded in figuring out what's going wrong. Could I ask you to prepare a small project that reproduces the issue? I understand, that the issue will appear only on Huawei P8 Lite but just having the exactly the same scene setup will help me to collect some useful information.
     
  31. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Hello everyone,

    Soft Mask has just been updated to version 1.4. This release is mainly about a long-awaited feature—Inverted Masks. There are two checkboxes added to Soft Mask Inspector that allow you to invert inside area of the mask, outside or both. Using this, you can achieve some interesting effects:

    01-inverted-masks-excerpt.png

    A demo scene that shows this feature in action is added. You may take a look at it online.

    Thank you to everyone who took his time to write a review or report a bug! I very appreciate it, folks. Sorry that I've not implemented all the features you asked nor fixed all the issues you were reporting. I just don't have that much time. But I'm going to continue supporting the package and adding new features!

    Release notes

    Starting from 1.4, Soft Mask requires Unity 5.6 or higher.

    Improvements
    • Added the Invert Mask and Invert Outsides options which allow to separately invert the inner and outer areas of the mask.
    • Added a new example featuring mask inversion.
    • Added tooltips for the Inspector UI.
    Bug fixes
    • Fixed a bug with incorrect display of a mask when a scaled sprite atlas was used.
    • Fixed an incorrect calculation of tile repeat count in the tiled mode that might occur for some sprites.
    • Fixed a bug with inconsistent Inspector state after reverting the Channel Weights property to prefab defaults.
     
    FernandoHC likes this.
  32. ZhavShaw

    ZhavShaw

    Joined:
    Aug 12, 2013
    Posts:
    129
    Is it supported on LWRP?
     
  33. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Yes, it does work on LWRP.
     
    ZhavShaw likes this.
  34. WookieWookie

    WookieWookie

    Joined:
    Mar 10, 2014
    Posts:
    8
    Since this is an artist tool used in layout, it would be really nice if you could provide a set of shaders based on the default UI shader that work with SoftMask. At least an additive one.
     
  35. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Hello,

    Sounds reasonable, I'll add it to the backlog. Maybe you know some package with a set of artistic UI shaders? I could integrate with it instead of providing shaders that do not directly correlate with the task solved by Soft Mask.

    Thank you for the feedback!
     
    WookieWookie likes this.
  36. WookieWookie

    WookieWookie

    Joined:
    Mar 10, 2014
    Posts:
    8
    There are lots of packages. But honestly, at the studios where I've worked, they don't want us importing a ton of 3rd-party stuff. It's a mess to keep track of on long-term projects, especially when they become live social games that live for years.

    SoftMask is a tough solution to find, so it is dev-approved. But I'd rather not import another party's shader set. They're unlikely to be as supportive or competent as you, just based on odds. : )

    Lots of UI artists might ask for the complete list of Photoshop blend modes. :rolleyes: That is not at all necessary, in my experience. The use cases for something like Difference mode hardly exist, even in Photoshop, lol. Here's the core list:
    • Normal: This is very useful for creating color flashes that don't blend against their background. Flash to white, as the most common example. When you want a fully opaque flash, Additive can't always provide it, depending on color content in the background.
    • Additive (aka Linear Dodge in Photoshop, or Add in other Adobe apps): For the glowing stuff, obviously.
    • Grayscale (ideally Saturation via HSV): This should be included with all game engines as a core UI shader. Graying-out buttons that are disabled (rather than tinting them in Multiply mode) is pretty standard UX.
    That's the core set. These next ones would be nice-to-haves, but rarely used:
    • Soft Light: This is a predictable effect that could have its uses for overlay effects.
    • Screen: This can be useful if there is a need for a whites-only effect. Like a snow tile and you want to scroll the UVs, but you want to be able to use a lightweight black/white image that is flattened (no transparency).
    • Multiply: Very rarely would I use this, because all Unity's color tinting is natively in Multiply mode. But in a case where there is no color field in the inspector, a shader would be needed.
    • Overlay: While used all the time in PS, this is not super useful when your background color might change. It's unpredictable, and I find that 99% of the effects people create with Overlay are actually do-able in Normal mode, if you know how to pick proper colors for a shadow, for example. (HSB, people!)
    • Color Dodge: I can't even think of how I'd use this, but I use it in PS sometimes when painting. It's a unique mode.
    This set of shaders would keep me happy for 99% of what I do daily. :) Oh, and one additional feature that would be rad is a checkbox on the shader to turn Masking on/off. All of the above is actually pretty valuable, because nobody else's shaders support SoftMask. So raise your price, if you decide to do this. You'll have to support the shaders too, obviously.
     
    Last edited: Aug 14, 2019
    zxkne likes this.
  37. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    @WookieWookie,

    Wow, that's awesome! I see a lot of experience behind all this stuff, it's very useful information. Thank you very much for this detailed overview! It makes this feature request more concrete and well-defined which in turn increases the chance that I'll put it into work someday :)
     
  38. localprojects

    localprojects

    Joined:
    Apr 26, 2019
    Posts:
    3
    Hi,

    I need a soft mask for a VR app. When using the softmask in a worldspace canvas, does it need the camera to do the texture update?

    I think this is the problem when I try to use a similar solution to yours. Do you think this solution could work?
     
  39. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    @localprojects
    Hi,

    As far as I understand when you use a world space Canvas, its content is rendered into a Render Texture and then this Render Texture is applied to a world space quad when rendering the main scene. A camera shouldn't take part in UI rendering when using a world space Canvas. Maybe the similar solution that you've tried worked in screen space? It may explain why it required a camera.

    But be aware that I'm not 100% sure and I may be wrong. Unfortunately, I don't have a VR set. Is there something VR-specific in your task? If not, you may describe what effect you want to achieve (or, better, provide an example scene) and I'll try to reproduce it with Soft Mask.
     
  40. redccoma1

    redccoma1

    Joined:
    Jun 23, 2015
    Posts:
    3
    I am using it well after buying a softmask.
    But recently I have to deal with the reflected light in a masked UI. Also I have a hard time dealing with shaders.

    Can you guide me in this case?

    It is possible to modify shaders that are not lighted by referring to the shader code provided in the sample. However, I can't solve the problem of having to handle lighting.

    Please help.. ;(
     
  41. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    Hello, @redccoma1

    Because Soft Mask works only with UI, I need some clarification regarding lighting. Usually, lighting isn't used in UI because UI is flat and it has no details that may be emphasized by lighting. I guess you either mean normal mapping (i.e. making UI texture look bumpy) or want to use Soft Mask in 3D? Could you provide more information on what are you trying to achieve?

    Thank you for choosing Soft Mask! :)
     
  42. redccoma1

    redccoma1

    Joined:
    Jun 23, 2015
    Posts:
    3
    thank you for reply @zxkne

    Yes. In general, the UI does not handle light reflections.
    However, I need to implement a UI that rotates the texture assigned to the rawimage and uses directional lighting to reflect the light by the tilt.
    (Of course the camera properties at this time use perspective)

    I want to use a custom shader (with softmask) on my rawimage to enable light reflections and masking.

    But as I mentioned in the previous topic, I don't know shader code. Also I find it difficult to invest time to implement this.
    (But I'm planning to study shaders)

    if u can, Can you tell me the shader with softmask in the standard surface shader I can create in Unity, or the shader code with softmask and light reflection in the UI-Default shader?
    (in Unity 5.6.5)

    This would be very cumbersome for you, but I need desperate help.

    regards
     
  43. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    @redccoma1,

    If you want to use Soft Mask in 3D I would recommend going UI-Default way. That is, create a standard-like UI shader with Soft Mask support and then add lighting to it. To make it work you need to somehow pass information about the light source to the shader. It can be done using material parameters and a custom script that assigns them. Doing so you not receive the shading quality of Standard Surface shader (there're much more complex calculations involved) but you can get basic N dot L lighting. Of course, you can reimplement/reuse surface shader logic too but that's a way more difficult task which I can't help you with.

    I've tried it and here is the result:

    softmask-fake-lighting.gif

    I'm not sure that it's what you wanted, but anyway. The example project is attached to this post. To see it in action, create an empty project, import Soft Mask and then the attached package.

    The package contains a shader which is just a copy of UI-Default with some modifications. Soft Mask-related changes are marked with // Soft Mask comment and lighting-related changes marked with // Lighting comment so you can easily distinguish them. Also, note that the light contains a script that just passes the light direction to UI shader via global shader variables. It works only with single directional light. If you need more... well, you have to implement it :)

    Hopefully, that helps you. If you have any questions on the example, feel free to ask.
     

    Attached Files:

  44. redccoma1

    redccoma1

    Joined:
    Jun 23, 2015
    Posts:
    3
    thank you for @zxkne

    What I need is a shaded output. Results should be processed higher quality than the results shown by way of example. But I understand it's a more difficult task, and I expect your feedback to be helpful.



    I have to shade it at a higher quality as a result of the above (this is the result of using the default surface shader without the mask function). However, I will use this as a reference and try to modify the shader code to enable high quality
    shading. However, I would be grateful if you could help.
     

    Attached Files:

  45. zxkne

    zxkne

    Joined:
    Jan 27, 2016
    Posts:
    133
    @redccoma1,

    I got it. But it's still UI? There will be some controls? Just in case, if you need masking in 3D and not need UI, the task may be solved way simpler. And you do not need Soft Mask for it. Just create a standard surface shader and add masking to it.

    But if you actually need UI and surface shaders, sorry, I can't help you more. Good luck! :)