Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Dissolve shader for Unity


Add this texture to the second slot. Set it to alpha from grayscale and alpha is transparency. Your texture goes in the first one.

Make a new material with this shader and play with the sliders and colours. You can create cool animated effects if you change dissolution level and/or edge width gradually over time.

Example of the shader in action:


Shader "Unlit/DissolveEffectShader"
_MainTex ("Texture", 2D) = "white" {}
_NoiseTex ("Texture", 2D) = "white" {}
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
_EdgeColour1 ("Edge colour 1", Color) = (1.0, 1.0, 1.0, 1.0)
_EdgeColour2 ("Edge colour 2", Color) = (1.0, 1.0, 1.0, 1.0)
_Level ("Dissolution level", Range (0.0, 1.0)) = 0.1
_Edges ("Edge width", Range (0.0, 1.0)) = 0.1
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
LOD 100
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
Lighting Off
ZWrite Off
Fog { Mode Off }
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile DUMMY PIXELSNAP_ON
#include "UnityCG.cginc"
struct appdata
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
struct v2f
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
sampler2D _MainTex;
sampler2D _NoiseTex;
float4 _EdgeColour1;
float4 _EdgeColour2;
float _Level;
float _Edges;
float4 _MainTex_ST;
v2f vert (appdata v)
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
o.vertex = UnityPixelSnap (o.vertex);
return o;
fixed4 frag (v2f i) : SV_Target
// sample the texture
float cutout = tex2D(_NoiseTex, i.uv).r;
fixed4 col = tex2D(_MainTex, i.uv);
if (cutout < _Level)
if(cutout < col.a && cutout < _Level + _Edges)
col =lerp(_EdgeColour1, _EdgeColour2, (cutout-_Level)/_Edges );
return col;

This comment has been minimized.

Copy link
Owner Author

commented Dec 14, 2017

Free to use under the terms of the MIT License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.