This is the shader I’m working right now.
At the very beginning, it was created to be a dissolve shader effect. I decided to pivot to a burning paper effect. The reason: I was reinventing the wheel. The asset store ( the unity’store where you can buy all your resources for video games) was full of dissolve shaders, a lot of people like me thoughts it was a great idea too.
But I’ve realized all the shaders were very generic shader. Obviously, they are dissolve shaders, but What was dissolving? The answer is everything and nothing. So I started to work on the idea of doing a dissolve shader for only one material… the one who is often dissolved in games, paper. So I’ve been working on this shader on my free time, trying to figure out how the paper behaves, how It looks… As far I’ve got this, but I have more effect to implement in the shader. I hope to show you in next posts.
Shader "Custom/BurnEffect" { Properties { _Color ("Color", Color) = (1,1,1,1) _BurnedColor("BurnedColor", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _BurnedMark("BurnedMask", 2D) = "white" {} _CrumpledTexture("CrumpledTexture", 2D) = "white"{} _Glossiness ("Smoothness", Range(0,1)) = 0.5 _Metallic ("Metallic", Range(0,1)) = 0.0 _ThresholdBurned("ThresholdBurned", Range(0,1)) = 0.0 _fadeOutAmount("FadeOutAmount", Range(0,1)) = 0.1 _InnerBurnedAmount("InnerBurnedAmount",Range(0,1)) = 0.1 } SubShader { Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } LOD 200 CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types #pragma surface surf Standard alpha:fade // Use shader model 3.0 target, to get nicer looking lighting #pragma target 3.0 sampler2D _MainTex; sampler2D _BurnedMark; sampler2D _CrumpledTexture; struct Input { float2 uv_MainTex; }; half _Glossiness; half _Metallic; half _ThresholdBurned; half _fadeOutAmount; half _InnerBurnedAmount; fixed4 _Color; fixed4 _ColorMask; fixed4 _CrumpledColor; fixed4 _BurnedColor; float rand(float3 co) { return frac(sin( dot(co.xyz ,float3(12.9898,78.233,45.5432) )) * 43758.5453); } void surf (Input IN, inout SurfaceOutputStandard o) { // Albedo comes from a texture tinted by color fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; _ColorMask = tex2D (_BurnedMark, IN.uv_MainTex); o.Albedo = c.rgb; o.Alpha = c.a; // Metallic and smoothness come from slider variables o.Metallic = _Metallic; o.Smoothness = _Glossiness; if(_ThresholdBurned != 0.0 || c.a > 0.2 ) { //If the alpha value of the mask if bigger than the _thershold the this part of the mesh is shown and will be apply some effects in ther borders if(_ColorMask.a >= _ThresholdBurned) { o.Alpha = c.a; fixed distFromBurnedBorder = abs(_ColorMask.a - _ThresholdBurned); if(distFromBurnedBorder < _InnerBurnedAmount ) { if(distFromBurnedBorder < _InnerBurnedAmount/1.1) { o.Albedo = lerp(c.rgb, _BurnedColor.rgb, 0.3+ distFromBurnedBorder/_InnerBurnedAmount); o.Alpha = c.a; //If we are near from the disolve border, we interpolate the transparency from the texture alpha to 0 to make the border smoothe if(distFromBurnedBorder < 0.01) o.Alpha = lerp(0,1,1-(0.01-distFromBurnedBorder)/0.01) ; }else{ //o.Albedo = c.rgb; //o.Albedo = tex2D (_CrumpledTexture, IN.uv_MainTex).rgb; o.Albedo = _BurnedColor.rgb; o.Alpha = c.a; } } else{ o.Albedo = tex2D (_CrumpledTexture, IN.uv_MainTex)* c.rgb * tex2D (_CrumpledTexture, IN.uv_MainTex) ; } } else { o.Alpha = 0.0; } //We enter in this code block if the alpha mask value is lower than the threshold } if(c.a < 0.1){ o.Alpha = 0.0; } } ENDCG } }
.