Unity Shaders: Simple Dissolve
I am a huge fan of Beyond Eyes game. I love the way the world appears and disappears following the movement of the little girl.
So I've started to analyze how to get the same effect and to my understanding, the effect can be subdivided in two steps:
The dissolve shader effect is pretty easy to get, here's the source code:
So I've started to analyze how to get the same effect and to my understanding, the effect can be subdivided in two steps:
- a dissolve shader that makes things appear and disappear in a cool way
- a spherical mask that makes objects appear and disappear based on their distance from the player
The dissolve shader effect is pretty easy to get, here's the source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | Shader "Mistwork/Dissolve" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _Glossiness ("Smoothness", Range(0,1)) = 0.5 _Metallic ("Metallic", Range(0,1)) = 0.0 _DissolveTex("Dissolve Texture", 2D) = "white" {} _DissolveAmount("Dissolve Amount", Range(0, 1)) = 0 _BurnSize("Burn Size", Range(0, 1)) = 0.03 _BurnColor("Burn Color", Color) = (1, 1, 1, 1) } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf Standard fullforwardshadows #pragma target 3.0 sampler2D _MainTex; sampler2D _DissolveTex; struct Input { float2 uv_MainTex; float2 uv_DissolveTex; }; float _Glossiness; float _Metallic; float4 _Color; float _DissolveAmount; float _BurnSize; float4 _BurnColor; UNITY_INSTANCING_BUFFER_START(Props) UNITY_INSTANCING_BUFFER_END(Props) void surf (Input IN, inout SurfaceOutputStandard o) { //Sample the _DissolveTex values. We use this value to discard pixels. _DissolveAmount adjust the amount of dissolve effect float dissolve_value = tex2D(_DissolveTex, IN.uv_DissolveTex).r - _DissolveAmount; //Discard the pixel if dissolve_value is < 0 clip(dissolve_value); //Show the burn area only if _BurnSize is > than dissolve value float burnAmount = step(dissolve_value, _BurnSize); fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb; o.Metallic = _Metallic; o.Smoothness = _Glossiness; o.Alpha = c.a; o.Emission = _BurnColor * burnAmount; } ENDCG } FallBack "Diffuse" } |
Nothing too complicated here, I just sample the values from a noise texture and discard pixels based on these values.
By subtracting _DissolveAmount value from the noise texture sampled values, I can adjust the amount of the dissolve effect.
I've also added a burn effect around the dissolved pixels.
In the next posts, I'll show you how to replace _DissolveAmount with a new value based on the distance from the object we want to dissolve, to the player object.