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
0
Question by vanshika1012 · Jan 06, 2017 at 05:42 PM · shader programmingshaderlabcgshader writing

Mask Shader Problem in Unity

I am trying to use Mask Shader. Strangely this shader working fine on Unity3d Editor and Android, but not working on iOS. It gives me weird result and after iOS build it stops working on Editor as well. Below is the code of my Shader. I guess, there must be some logical reason. I am not "PRO" at shader writing. Hope someone help.

Below shader, basically unMask the image on touch. This Mask Shader is applied on top layer and when I touch it, it shows me below image. Just like scratch effect.

 Shader "Masked" {
 Properties {
     _MainTex ("Main", 2D) = "white" {}
     _MaskTex ("Mask", 2D) = "white" {}
 }

 SubShader {
     Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
     ZWrite Off
     ZTest Off
     Blend SrcAlpha OneMinusSrcAlpha
     Pass {
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
         #pragma fragmentoption ARB_precision_hint_fastest
            #include "UnityCG.cginc"

         uniform sampler2D _MainTex;
         uniform sampler2D _MaskTex;
         uniform float4 _MainTex_ST;
         uniform float4 _MaskTex_ST;

         struct app2vert
         {
             float4 position: POSITION;
             float2 texcoord: TEXCOORD0;
         };

         struct vert2frag
         {
             float4 position: POSITION;
             float2 texcoord: TEXCOORD0;
         };

         vert2frag vert(app2vert input)
         {
             vert2frag output;
             output.position = mul(UNITY_MATRIX_MVP, input.position);
             output.texcoord = TRANSFORM_TEX(input.texcoord, _MainTex);
             return output;
         }

         fixed4 frag(vert2frag input) : COLOR
         {
             fixed4 main_color = tex2D(_MainTex, input.texcoord);
             fixed4 mask_color = tex2D(_MaskTex, input.texcoord);
             return fixed4(main_color.r, main_color.g, main_color.b, main_color.a * (1.0f - mask_color.a));
         }
         ENDCG
     }
 }
 }
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

0 Replies

· Add your reply
  • Sort: 

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

87 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

Related Questions

_WorldSpacePosLight0 suddenly changes when change camera position or direction 0 Answers

Translucent Transparent Diffuse Sprite Shader Edit 1 Answer

_Time in Image Effects 0 Answers

Is it possible to set the 'ForceNoShadowCasting' SubShader Tag via shader properties or a custom material editor? 1 Answer

Shader error : unexpected $end, expecting TOK_SETTEXTURE or '}' at line 18 1 Answer


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