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 /
avatar image
0
Question by a-t-hellboy · Sep 22, 2015 at 07:13 AM · shaderspriteclipcrop

clip area shader

First of all, I don't have any idea about shader programming but I need it for my game so I found a clip area shader on the internet then I was trying to modify it and add some features to it ! I added shader to my sprite and checked it on my PC and some android devices but after that I've checked it on HTC One (My friend mobile) but weird problem was happening !

alt text

As you see the left side is not clipping visually.

The first shader I found just had width and length for clipping sprite then I added width from left and width from right and color tint to the shader.

There is a code :

 Shader "Sprites/ClipAreaWithAlpha"
 {
     Properties
     {
         _Color ("Color Tint", Color) = (1,1,1,1)
         _MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {}
         _Length ("Length", Range(0.0, 1.0)) = 1.0
         _WidthR("Width from right", Range(0.0, 1.0)) = 1.0
         _WidthL ("Width from left", Range(0.0, 1.0)) = 0.0
      }
 
     SubShader
     {
         LOD 200
 
         Tags
         {
             "Queue" = "Transparent"
             "IgnoreProjector" = "True"
             "RenderType" = "Transparent"
         }
 
         Pass
         {
             Cull Off
             Lighting Off
             ZWrite Off
             Offset -1, -1
             Fog { Mode Off }
             ColorMask RGB
             Blend SrcAlpha OneMinusSrcAlpha
 
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
 
             #include "UnityCG.cginc"
 
             sampler2D _MainTex;
             float4 _MainTex_ST;
             float _Length;
             float _WidthR;
             float _WidthL;
             half4 _Color;
 
             struct appdata_t
             {
                 float4 vertex : POSITION;
                 float2 texcoord : TEXCOORD0;
             };
 
             struct v2f
             {
                 float4 vertex : POSITION;
                 float2 texcoord : TEXCOORD0;
                 half4 color : COLOR;
             };
 
             v2f vert (appdata_t v)
             {
                 v2f o;
                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                 o.texcoord = v.texcoord;
                 o.color = _Color;
                 return o;
             }
 
             half4 frag (v2f IN) : COLOR
             {
                 if ((IN.texcoord.x<_WidthL) || (IN.texcoord.x>_WidthR) || (IN.texcoord.y<0) || (IN.texcoord.y>_Length))
                 {
                     half4 colorTransparent = half4(0,0,0,0) ;
                     return colorTransparent;
                 }
                 else
                 {
                     half4 tex = tex2D(_MainTex, IN.texcoord);
                     tex.a = IN.color.a;
                     return tex;
                 }
             }
             ENDCG
         }
     }
 }

As I said before this shader is ok on another android devices that I checked but on HTC One it doesn't work nicely and correctly. I don't know where the problem is! I'm thankful for solution.

And this shader has this warning : MaterialPropertyBlock is used to modify these values

photo-2015-09-19-23-20-23.jpg (56.8 kB)
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 a-t-hellboy · Sep 23, 2015 at 11:24 AM 0
Share

I haven't found a solution yet.

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

2 People are following this question.

avatar image avatar image

Related Questions

Pixel snap for material made with Unlit Shader Graph? 1 Answer

Outline set of tiled sprites 0 Answers

Making shader's first pass light sensitive (2D) 0 Answers

Two Textures Dissolve Shader (clip & lerp) 1 Answer

2D Sprite Always Visible - Shader / Material not working (ZTest, ZWrite, Culling) 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