Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Set texture alpha when mouse touch(Mobile)

Discussion in 'Shaders' started by Tongie, Mar 8, 2015.

  1. Tongie

    Tongie

    Joined:
    Sep 19, 2012
    Posts:
    90
    I wanted to do sth like a scratch card effect. When i touch on the pixel, the pixel alpha is set to 0. I managed to achieve it using setpixel but the fps drop about 20 when i touch on the surface. How do i do this using shader?

    Code (CSharp):
    1. Shader "Custom/TongAlpha"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Base (RGB)", 2D) = "white" {}
    6.     }
    7.     SubShader
    8.     {
    9.         Tags { "RenderType" = "Opaque" }
    10.         LOD 200
    11.    
    12.         CGPROGRAM
    13.         #pragma surface surf Lambert
    14.    
    15.         sampler2D _MainTex;
    16.         bool _IsTouch;
    17.    
    18.         struct Input
    19.         {
    20.             float2 uv_MainTex;
    21.         };
    22.    
    23.         void surf (Input IN, inout SurfaceOutput o)
    24.         {
    25.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    26.             o.Albedo = c.rgb;
    27.             if (_IsTouch)
    28.             {
    29.                 o.Alpha = 0;
    30.             }
    31.             else
    32.             {
    33.                 o.Alpha = c.a;
    34.             }
    35.         }
    36.         ENDCG
    37.     }
    38.     FallBack "Mobile/Diffuse"
    39. }
     
    Last edited: Mar 8, 2015
  2. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    @Tongie have you managed to make it work?