Making an outward-fading circle sprite

Hey! So I’m trying to make a 2d sprite for an atmosphere of a planet, and I want the atmosphere to slowly fade out from the center of the circle until it’s totally transparent. How would I go about doing this? I’ve tried drawing my own sprites, but they never turn out realistic - is there a mathematical way to do this in unity?

You would normally create the sprite in its “full” state and then provide a separate gradient map, a black and white image which represents the way the fade progresses. You then need an alpha mask shader, which renders e.g. black as transparent and white as fully white but moves a threshold value from 0 to 1 to animate the fade. Search for “alpha mask shader” or “animated transparency shader” to find an implementation. :wink: The mathematical way is to find a good threshold function (a simple cutoff will probably not look good if you’d rather have a smooth fade, but there are ways to smooth the values). Try the search term “soft alpha mask”.

As I said, you can find many tutorials about mask shaders, but just to get you started, here is one I’ve used (not time for a real tutorial myself, but maybe you can experiment with it):

Shader "Sprites Gradient Fade"
{
	Properties
	{
		[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
		_Color ("Color", Color) = (1,1,1,1)
		_Range("Cutoff", Float) = 4
		[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
		[HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
		[HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
		[PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {}
		[PerRendererData] _EnableExternalAlpha ("Enable External Alpha", 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 SpriteVert
			#pragma fragment Frag
			#pragma target 2.0
			#pragma multi_compile_instancing
			#pragma multi_compile _ PIXELSNAP_ON
			#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
			#include "UnitySprites.cginc"

			float _Range;

			fixed4 Frag(v2f IN) : SV_Target
			{
				fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color;

				fixed4 OUT = c;
				OUT.rgb = _Color;
				OUT.rgb *= c.a;
				OUT.a = 1 - c.a;
				c.a = saturate(c.r * _Range);

				return OUT;
			}
		ENDCG
		}
	}
}

Simply create a custom material for your sprite, then select this shader and add a black and white image to use as a gradient mask. If all goes well, you can animate the fade by changing the cutoff parameter.