Advertisement
SatyamBhatt

Dissolve Shader

May 8th, 2025
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Unlit/DisintegreateShader"
  2. {
  3.  Properties
  4.     {
  5.         _MainTex ("Texture", 2D) = "white" {}
  6.         _NoiseScale ("Noise Scale", Float) = 10.0
  7.         _SubValue ("Subtract", Range(-2, 4)) = 0.0
  8.         _Thickness ("Thickness", Range(0, 1)) = 0.0
  9.  
  10.         [HDR] _Color ("Color", Color) = (1,1,1,1)
  11.         _ColorIntensity ("Color Intensity", Range(0, 10)) = 1
  12.  
  13.     }
  14.     SubShader
  15.     {
  16.         Tags {
  17.             "RenderType"="Transparent"
  18.             "Queue"="Transparent"
  19.         }
  20.  
  21.         Pass
  22.         {
  23.             Cull Off
  24.             ZWrite Off
  25.             Blend SrcAlpha OneMinusSrcAlpha
  26.  
  27.             CGPROGRAM
  28.             #pragma vertex vert
  29.             #pragma fragment frag
  30.             #include "UnityCG.cginc"
  31.  
  32.             struct appdata
  33.             {
  34.                 float4 vertex : POSITION;
  35.                 float2 uv : TEXCOORD0;
  36.             };
  37.  
  38.             struct v2f
  39.             {
  40.                 float2 uv : TEXCOORD0;
  41.                 float4 vertex : SV_POSITION;
  42.             };
  43.  
  44.             sampler2D _MainTex;
  45.             float4 _MainTex_ST;
  46.             float _NoiseScale;
  47.             float4 _Color;
  48.             float _SubValue;
  49.             float _ColorIntensity;
  50.             float _Thickness;
  51.  
  52.             // Gradient Noise functions
  53.             float2 unity_gradientNoise_dir(float2 p)
  54.             {
  55.                 // Rotation matrix to rotate the gradient
  56.                 p = p % 289;
  57.                 float x = (34 * p.x + 1) * p.x % 289 + p.y;
  58.                 x = (34 * x + 1) * x % 289;
  59.                 x = frac(x / 41) * 2 - 1;
  60.                 return normalize(float2(x - floor(x + 0.5), abs(x) - 0.5));
  61.             }
  62.  
  63.             float unity_gradientNoise(float2 p)
  64.             {
  65.                 float2 ip = floor(p);
  66.                 float2 fp = frac(p);
  67.                 float d00 = dot(unity_gradientNoise_dir(ip), fp);
  68.                 float d01 = dot(unity_gradientNoise_dir(ip + float2(0, 1)), fp - float2(0, 1));
  69.                 float d10 = dot(unity_gradientNoise_dir(ip + float2(1, 0)), fp - float2(1, 0));
  70.                 float d11 = dot(unity_gradientNoise_dir(ip + float2(1, 1)), fp - float2(1, 1));
  71.                 fp = fp * fp * fp * (fp * (fp * 6 - 15) + 10);
  72.                 return lerp(lerp(d00, d01, fp.y), lerp(d10, d11, fp.y), fp.x);
  73.             }
  74.  
  75.             float GradientNoise(float2 UV, float Scale)
  76.             {
  77.                 return unity_gradientNoise(UV * Scale) + 0.5;
  78.             }
  79.  
  80.             v2f vert (appdata v)
  81.             {
  82.                 v2f o;
  83.                 o.vertex = UnityObjectToClipPos(v.vertex);
  84.                 o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  85.                 return o;
  86.             }
  87.  
  88.             float4 frag (v2f i) : SV_Target
  89.             {
  90.                 // Sample the texture
  91.                 float4 col = tex2D(_MainTex, i.uv);
  92.  
  93.                 float2 uv = i.uv;
  94.                
  95.                 // Generate noise
  96.                 float noise = GradientNoise(i.uv, _NoiseScale);
  97.                 noise = saturate(noise);
  98.  
  99.                 uv.y = pow(uv.y, 2) * 3;
  100.                 float heightCalc = noise + uv.y;
  101.                 //return float4(heightCalc.xxx, 1);
  102.                 //return float4(heightCalc.xxx - _SubValue, 1);
  103.                 //heightCalc = step(heightCalc, 0);
  104.  
  105.                 float stepFn = step(heightCalc - _SubValue, 0); // Smaller
  106.                 float stepFnOff = step(heightCalc - (_SubValue + _Thickness), 0); // Use this as the mask // Larger
  107.                 float lines = stepFnOff - stepFn;
  108.                 float4 lineColor = lines * _Color * _ColorIntensity;
  109.  
  110.                 //return float4(colorOut.rgb, stepFnOff);
  111.                 float4 maskedOffTex = col * stepFn;
  112.                 //return maskedOffTex;
  113.                 return float4(maskedOffTex.rgb + lineColor.rgb, stepFnOff * col.a);
  114.             }
  115.                
  116.             ENDCG
  117.         }
  118.     }
  119. }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement