Advertisement
Guest User

ResourceOrbUI.shader

a guest
Oct 27th, 2022
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Unlit/OrbUI"
  2. {
  3.     Properties
  4.     {
  5.         [Header(Shape)]  
  6.         [PerRendererData]_MainTex("Shape Mask", 2D) = "white" {}
  7.         _Alphacutoff("Alpha Cutoff", Range(0,1)) = 0.15
  8.         _AlphaSmooth("Alpha Smoothness", Range(0,1)) = 0
  9.         _DarkEdge("Dark Edge", Range(0,1)) = 0.1
  10.  
  11.         [Header(Noise)]
  12.         _Noise ("Noise (RGB)", 2D) = "white" {}
  13.         _Scale("Scale", Range(0,10)) = 0.5
  14.         _MoveSpeed("Movespeed X,Y", Vector) = (1, -1, 0, 0)
  15.  
  16.         [Header(Colors)]
  17.         [HDR]_Tint ("GradientMap Tint", Color) = (1,1,1,1)
  18.         _GradientMap ("GradientMap (RGB)", 2D) = "white" {}
  19.         _Stretch("Stretch", Range(-3,3)) = 2
  20.         _Offset("Offset", Range(-3,3)) = 0
  21.        
  22.  
  23.         [Header(Sparkles)]
  24.         [HDR]_SparkleColor ("Sparkles Color", Color) = (1,1,1,1)  
  25.         _Sparkles("Sparkles (RGB)", 2D) = "black" {}
  26.         _ScaleSparkle("Scale Sparkles", Range(0,10)) = 0.2
  27.         _SparkMoveSpeed("Sparkle Movespeed X,Y", Vector) = (1, 1, 0, 0)
  28.         _SparkleOver("Sparkles Over Line", Range(0,1)) = 0.2
  29.  
  30.        
  31.         [Header(Distortion)]
  32.         _Distort("Sparkle Edge Distort", Range(-1,1)) = 0.2
  33.         _SphereDist("Shape Distort", Range(-10,10)) = 5
  34.         _LineSphereDist("Line Distort", Range(-1,1)) = -0.2
  35.         _MaskStrength ("Shape Mask Strength", Range(0,1)) = 1
  36.        
  37.         [Header(Line)]
  38.         _FillAmount ("Fill Amount", Range(0,1)) = 0.5
  39.         _Speed("Speed", Range(0,100)) = 75    
  40.         _Freq("Freq", Range(0,10)) = 0.5
  41.         _Amplitude("Amplitude", Range(0,0.1)) = 0.05
  42.          [Header(Line Width)]
  43.         [HDR]_Color ("Line Color", Color) = (1,1,1,1)
  44.         _LineWidth("Line Width", Range(0,1)) = 0.05
  45.         _LineTop("Line Top Smoothness", Range(0,1)) = 0.05
  46.         _LineBottom("Line Bottom Smoothness", Range(0,1)) = 0.05
  47.  
  48.  
  49.         // UI Masking Stuff
  50.  
  51.         [HideInInspector]_StencilComp ("Stencil Comparison", Float) = 8
  52.         [HideInInspector]_Stencil ("Stencil ID", Float) = 0
  53.         [HideInInspector]_StencilOp ("Stencil Operation", Float) = 0
  54.         [HideInInspector]_StencilWriteMask ("Stencil Write Mask", Float) = 255
  55.         [HideInInspector]_StencilReadMask ("Stencil Read Mask", Float) = 255
  56.  
  57.         [HideInInspector]_ColorMask ("Color Mask", Float) = 15
  58.  
  59.     }
  60.     SubShader
  61.     {
  62.         Tags
  63.         {
  64.             "Queue"="Transparent"
  65.             "IgnoreProjector"="True"
  66.             "RenderType"="Transparent"
  67.             "PreviewType"="Plane"
  68.             "CanUseSpriteAtlas"="True"
  69.         }
  70.  
  71.         // UI Masking Stuff
  72.         Stencil
  73.         {
  74.             Ref [_Stencil]
  75.             Comp [_StencilComp]
  76.             Pass [_StencilOp]
  77.             ReadMask [_StencilReadMask]
  78.             WriteMask [_StencilWriteMask]
  79.         }
  80.  
  81.         Cull Off
  82.         Lighting Off
  83.         ZWrite Off
  84.         ZTest [unity_GUIZTestMode]
  85.         Blend SrcAlpha OneMinusSrcAlpha
  86.         ColorMask [_ColorMask]
  87.  
  88.         Pass
  89.         {
  90.             CGPROGRAM
  91.             #pragma vertex vert
  92.             #pragma fragment frag
  93.             // make fog work
  94.  
  95.             #include "UnityCG.cginc"
  96.             #include "UnityUI.cginc"
  97.  
  98.             struct appdata
  99.             {
  100.                 float4 vertex : POSITION;
  101.                 float2 uv : TEXCOORD0;
  102.             };
  103.  
  104.             struct v2f
  105.             {
  106.                 float2 uv_MainTex : TEXCOORD0;
  107.                 float4 vertex : SV_POSITION;
  108.             };
  109.  
  110.            
  111.             float4 _Noise_ST;
  112.  
  113.             sampler2D _Noise,_GradientMap;
  114.             float _MaskStrength;
  115.  
  116.             // modified version of the Spherize UV node, takes in a SDF shapeMask
  117.             float2 Unity_Spherize_float(float2 UV, float2 Center, float Strength, float2 Offset, float shapeMask)
  118.             {
  119.                 float2 delta = saturate(UV*  (shapeMask * _MaskStrength) + 0.1)  - Center;
  120.                 float delta2 = dot(delta.xy, delta.xy);
  121.                 float delta4 = delta2 * delta2;
  122.                 float2 delta_offset = delta4 * Strength ;
  123.  
  124.                 float2 Out = UV + delta * delta_offset + Offset;
  125.                 return Out;
  126.             }
  127.  
  128.             float _Alphacutoff;
  129.             float _FillAmount;
  130.             fixed4 _Color;
  131.             float _Speed;
  132.             float2 _MoveSpeed,_SparkMoveSpeed;
  133.             float _Stretch, _Offset;
  134.             float _Distort;
  135.             float _Freq;
  136.             float _Amplitude;
  137.             float _LineTop, _LineBottom, _LineWidth;
  138.             float _SphereDist;
  139.             float _Scale;
  140.             sampler2D _MainTex,_Sparkles;
  141.             float _LineSphereDist;
  142.             float _SparkleOver;
  143.             float _ScaleSparkle;
  144.        
  145.             float4 _SparkleColor;
  146.             float _AlphaSmooth;
  147.             float4 _Tint;
  148.             float _DarkEdge;
  149.          
  150.  
  151.             v2f vert (appdata v)
  152.             {
  153.                 v2f o;
  154.                 o.vertex = UnityObjectToClipPos(v.vertex);
  155.                 o.uv_MainTex = TRANSFORM_TEX(v.uv, _Noise);
  156.                 return o;
  157.             }
  158.  
  159.             fixed4 frag (v2f i) : SV_Target
  160.             {              
  161.                 // shape Mask
  162.                 float shapeMask = tex2D(_MainTex,i.uv_MainTex);
  163.                
  164.                 // adjust uvs using the shape mask and movespeed
  165.                 float2 moveSpeed = (_Time.x * _MoveSpeed);
  166.                 float2 movingUV =  Unity_Spherize_float(i.uv_MainTex, float2(0.5,0.5),_SphereDist, moveSpeed , shapeMask );
  167.                 float2 movingUV2 =  Unity_Spherize_float(i.uv_MainTex, float2(0.5,0.5),_SphereDist, moveSpeed, shapeMask);
  168.                
  169.                 // first noise layer
  170.                 fixed noise1 = tex2D (_Noise, movingUV * _Scale);
  171.                 // second noise layer
  172.                 fixed noise2 = tex2D (_Noise,movingUV2 * (_Scale * 0.5));
  173.                 // combined
  174.                 float noiseComb = (noise1 + noise2) * 0.5;
  175.  
  176.                 // add colors via gradient map
  177.                 float2 colorMapUV = float2((noiseComb * _Stretch) + _Offset, 1);
  178.                 fixed4 gradientMap = tex2D (_GradientMap, colorMapUV);
  179.  
  180.                 // create line with wobble
  181.                 float2 nonMovingUV = Unity_Spherize_float(i.uv_MainTex, float2(0.5,0.5),_LineSphereDist, float2(0,0), shapeMask );
  182.                 float wobble = sin(((nonMovingUV) * _Freq) + (_Speed * _Time.x)) * _Amplitude ;
  183.                 float wobbleLine = saturate((nonMovingUV.y) - wobble);
  184.              
  185.                 float cutoffPoint = smoothstep(_FillAmount - _LineTop, _FillAmount , 1- wobbleLine);
  186.  
  187.                 // line width
  188.                 float lineWidth = saturate(1- smoothstep(_FillAmount + _LineWidth, _FillAmount + _LineWidth + _LineBottom , 1- wobbleLine)) * (cutoffPoint);
  189.                
  190.                 // extra sparkles texture
  191.                 float2 sparkMoveSpeed = _Time.x * _SparkMoveSpeed;
  192.                  float2 sparkUV = Unity_Spherize_float(i.uv_MainTex, float2(0.5,0.5),_Distort, moveSpeed, shapeMask);
  193.                   float2 sparkUV2 = Unity_Spherize_float(i.uv_MainTex, float2(0.5,0.5),_Distort, sparkMoveSpeed, shapeMask );
  194.                 float4 sparkles = tex2D(_Sparkles, sparkUV * _ScaleSparkle) ;
  195.                  float4 sparkles2 = tex2D(_Sparkles, sparkUV2 * _ScaleSparkle* 0.5) ;
  196.                  sparkles = (sparkles * sparkles2) * 6;
  197.                 sparkles *= smoothstep(_FillAmount - _SparkleOver, _FillAmount , 1- wobbleLine);
  198.              
  199.  
  200.                 // combine
  201.                 float3 final = (gradientMap.rgb * _Tint * cutoffPoint) + (lineWidth * _Color);
  202.  
  203.                 // add in sparkles
  204.                 final += sparkles * _SparkleColor * saturate((shapeMask) - 0.1);
  205.  
  206.                 // darken edges
  207.                 final -= (1-saturate(shapeMask * 2 ))* _DarkEdge;
  208.  
  209.                 // cut out mask shape
  210.                 float alpha = smoothstep(_Alphacutoff, _Alphacutoff + _AlphaSmooth, shapeMask * 2);
  211.  
  212.                 // clip the alpha for any ui masking
  213.                 clip (alpha - 0.001);
  214.  
  215.                 return float4(final,alpha);
  216.             }
  217.             ENDCG
  218.         }
  219.     }
  220. }
  221.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement