Hello! I wanted to create the effect you can achieve with Unity UI's Image Type "Filled", but with a 2D Sprite. I found this video: and that helped me a great deal, but the creator there did not handle transparency. So I found Unity's Standard Sprite Shader (or at least what i believe is: https://github.com/nubick/unity-uti...Assets/Scripts/Shaders/Sprites-Default.shader), and tried to apply the cutoff technique there. I managed to get it half-working, but not fully. It works if the color of my Sprite is black, but not for other colors: I want the full transparency as with the black hex, but with any color. The base image is just a white hex. I don't understand where that half-transparent thing comes from! Here is the Shader i Created: Code (CSharp): // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' Shader "Sprites/DefaultCutoff" { Properties { [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} _Color ("Tint", Color) = (1,1,1,1) _TransitionTex("Transition Texture", 2D) = "white" {} _Cutoff("Cutoff", Range(0, 1)) = 0 [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 } SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True" } Cull Off Lighting Off ZWrite Off Blend One OneMinusSrcAlpha Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma multi_compile _ PIXELSNAP_ON #include "UnityCG.cginc" struct appdata_t { float4 vertex : POSITION; float4 color : COLOR; float2 texcoord : TEXCOORD0; }; struct v2f { float4 vertex : SV_POSITION; fixed4 color : COLOR; float2 texcoord : TEXCOORD0; }; fixed4 _Color; float _Cutoff; sampler2D _TransitionTex; v2f vert(appdata_t IN) { v2f OUT; OUT.vertex = UnityObjectToClipPos(IN.vertex); OUT.texcoord = IN.texcoord; OUT.color = IN.color * _Color; #ifdef PIXELSNAP_ON OUT.vertex = UnityPixelSnap (OUT.vertex); #endif return OUT; } sampler2D _MainTex; sampler2D _AlphaTex; float _AlphaSplitEnabled; fixed4 SampleSpriteTexture (float2 uv) { fixed4 color = tex2D (_MainTex, uv); #if UNITY_TEXTURE_ALPHASPLIT_ALLOWED if (_AlphaSplitEnabled) color.a = tex2D (_AlphaTex, uv).r; #endif //UNITY_TEXTURE_ALPHASPLIT_ALLOWED return color; } fixed4 frag(v2f IN) : SV_Target { fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color; c.rgb *= c.a; fixed4 transit = tex2D(_TransitionTex, IN.texcoord); if (transit.b > _Cutoff) c.a = 0; return c; } ENDCG } } } I'm also very new to Shaders so I might be doing some very basic mistake here... Thanks for your help! Best, Johannes
Right now your object will never be transparent because of this: Blend One OneMinusSrcAlpha If you want transparency, use this instead: Blend SrcAlpha OneMinusSrcAlpha In your fragment function, you are darkening your pixels based on how transparent they should be. c.rgb *= c.a; This is not a bad idea, but I don't like to do this until I'm done adjusting alpha. I think the above code should come after this code: if (transit.b > _Cutoff) c.a = 0; Good luck!