Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
1
Question by neural · Oct 09, 2016 at 01:18 PM · uishader programmingmasking

Custom shader does not update if masked,

I have an issue that has been partially addressed elsewhere (like http://answers.unity3d.com/questions/980924/ui-mask-with-shader.html and http://answers.unity3d.com/questions/1004826/custom-ui-material-with-mask.html), but in my case i am trying to also update the shader, and this solution : http://answers.unity3d.com/questions/1130203/ui-mask-override-my-shaders-custom-property.html did nothing in my case.

This is my shader :

 Shader "MyLinearGradient"
 {
     Properties{
         _TopColor("Top color", Color) = (1,1,1,1)
         _BottomColor("Bottom color", Color) = (1,1,1,1)
         _Offset("Offset",Float) = 0
 
         // 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
         {
             "Queue" = "Transparent"
             "IgnoreProjector" = "True"
             "RenderType" = "Transparent"
             "PreviewType" = "Plane"
             "CanUseSpriteAtlas" = "True"
         }
         LOD 100
 
         Stencil
         {
             Ref[_Stencil]
             Comp[_StencilComp]
             Pass[_StencilOp]
             ReadMask[_StencilReadMask]
             WriteMask[_StencilWriteMask]
         }
         ColorMask[_ColorMask]
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
 
             #include "UnityCG.cginc"
 
             fixed4 _TopColor;
             fixed4 _BottomColor;
             float1 _Offset;
 
             struct v2f {
                 float4 position : SV_POSITION;
                 fixed4 color : COLOR;
             };
 
             v2f vert(appdata_full v)
             {
                 v2f o;
                 o.position = mul(UNITY_MATRIX_MVP, v.vertex);
                 float1 IntOffset = v.texcoord.y + v.texcoord.x + _Offset;
                 o.color.r = cos(IntOffset)*(_TopColor.r - _BottomColor.r) + _BottomColor.r;
                 o.color.g = cos(IntOffset)*(_TopColor.g - _BottomColor.g) + _BottomColor.g;
                 o.color.b = cos(IntOffset)*(_TopColor.b - _BottomColor.b) + _BottomColor.b;
                 o.color.a = cos(IntOffset)*(_TopColor.a - _BottomColor.a) + _BottomColor.a;
                 return o;
             }
 
             fixed4 frag(v2f i) : SV_Target
             {
                 float4 color = i.color;
                 color.a = 1;
                 return color;
             }
             ENDCG
         }
     }
 }
 

which i try to slide with the _offset parameter. The material works fine except if it is under a ui mask. i also attach a test project in order to see it live.

Thank you in advance

,

cognichess.zip (254.6 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NextLevelLab · Dec 15, 2016 at 12:10 AM

I have just experienced the same issue like in this case: https://forum.unity3d.com/threads/masked-ui-elements-shader-not-updating.371542/ One hint from that post could be that "[...] the material that you are referencing for the animation is not the one that is being used to draw (using the original vs the copied)" ... But I still have no clue nor any workaround ...

I am actually trying to cover a kind of healthbar with a Material, who's offset gets controlled via script to generate a flowing effect.. The problem is, that my "healthbar" is not perfectly rectangular, so I tried to apply an UI Mask on the flowing Material.

I hope that someone will soon have a solution for this.

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

105 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

UI Mask not working 1 Answer

UI Elements Instantly Breaks Sprite Masks (Unity 2D) 1 Answer

Invisible transition mask 0 Answers

After updating to Unity 2017.2 UI masks are not working.,Unity 2017.2 UI mask issue 0 Answers

How to use shader to control the rendering of each text character(letter)? Or, how to correctly pass custom data into vert/frag? 0 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