Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by MaximeBeaudoin · Jun 07, 2015 at 03:07 PM · shadermaterialmask

UI mask with shader

Hi,

I want to use a UI mask with a shader instead of a texture. However, not only it doesn't work, but I get this warning:

Material UnmoveableMask (UnityEngine.Material) doesn't have color mask UnityEngine.Canvas:SendWillRenderCanvases()

I tried playing with stencil stuff directly in my shader, but didn't get any satisfying result.

So, is the UI Mask component supposed to work with custom shaders?

Thanks,

Maxime

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cyril A · Nov 07, 2015 at 03:34 AM 0
Share

Also interrested in using a Shader on 3d object, and manage it so the UI $$anonymous$$ask affect it .... I'm trying this kind of solution but it doesn't work for now..

4 Replies

· Add your reply
  • Sort: 
avatar image
26

Answer by JeanLuc · Aug 20, 2015 at 01:21 PM

yes, just need to copy the part the Stencil and ColorMask from the build in shader "UI-Default.shader"

 Shader "Custom/Opaque"
  {  
     Properties
     {
         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
         _Color ("Tint", Color) = (1,1,1,1)
         
         // required for UI.Mask
         _StencilComp ("Stencil Comparison", Float) = 8
         _Stencil ("Stencil ID", Float) = 0
         _StencilOp ("Stencil Operation", Float) = 0
         _StencilWriteMask ("Stencil Write Mask", Float) = 255
         _StencilReadMask ("Stencil Read Mask", Float) = 255
         _ColorMask ("Color Mask", Float) = 15
     }
     SubShader
     {
         Tags 
         { 
             // ...
         }
         
         // required for UI.Mask
         Stencil
         {
             Ref [_Stencil]
             Comp [_StencilComp]
             Pass [_StencilOp] 
             ReadMask [_StencilReadMask]
             WriteMask [_StencilWriteMask]
         }
          ColorMask [_ColorMask]
         
         Pass
         {
             // ...
         }
     }
  }
  
Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image saarwii · Sep 30, 2015 at 09:10 AM 0
Share

I am also trying to render a shader (3d mesh) and mask using the UI mask...I have a very limitid knowledge of how shaders work so please bear with me.... Should i put the above code in the standard shader to get this to work? or should i create a new shader with the above code and apply it?

avatar image twobob · Oct 29, 2015 at 08:31 PM 1
Share

Heroic. I can confirm that this still works nicely on 5.2.2.fx.

avatar image Trafulgoth · Nov 02, 2015 at 11:20 PM 1
Share

For posterity: Note that "_StencilComp" is very important and it's backing values are not documented anywhere that I could find. The float (int, really) that you assign to it tells the shader what comparison operation to use when checking the stencil buffer. In my case, I needed to write an "Equals" operation in there. I'm using my$$anonymous$$at.SetFloat("_StencilComp", 3); from C# to do it. Not sure if 3 is actually the equal operation or just one that worked because of mathematical coincidence.

avatar image blueknee · Aug 17, 2016 at 08:13 AM 1
Share

oh my goodness. this works perfectly! thanks!!

avatar image TurboCrackers · Oct 31, 2016 at 05:44 PM 0
Share

So is that the text for the entire shader, then I make a material and assign this new shader to it? Also, do I modify any of the new material's properties? I used this code and did what I described, but the panel went invisible, along with its children.

Show more comments
avatar image
3

Answer by Michiel-Frankfort · Oct 28, 2016 at 11:03 PM

Hi,

Just a little visual update for 5.4.1 to get a Shaderforge-shader working with stencil UI Mask component. I hope it helps... alt text


michiel-frankfort-shaderforge-ui-masking.jpg (404.3 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Mr-Pocket-Scientist · Jun 01, 2016 at 01:40 PM

Look at this: http://answers.unity3d.com/questions/1130203/ui-mask-override-my-shaders-custom-property.html Store the new Material in a variable and update that anytime with your usual scripts. The GetModifiedMaterial() gets called only when the canvas layout should be updated.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by yutuch · May 25, 2019 at 07:04 PM

Hey! I dig this topic up because I encountered the same issue today and none of the top google answers helped me.

I checked every parameters, and Instantiated the new material at runtime and yet, it didn't work properly.

In my case, the problem was the Image's scale. If it was (1,1,1), the shader worked, if it's (-1,1,1) it didn't.

Hope this will help some wanderers

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why can't I alter a Texture offset on a material, if its used in a Mask or Scroll rect? 2 Answers

Material doesn't have a color property '_Color' 4 Answers

How would one get a CRT screen effect on an in game object?,How would one achieve a CRT screen effect on an in-game object? 0 Answers

UI/Default stencil buffer for only parent? 0 Answers

Custom UI material with Mask ? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges