Guest User

AnimatedLightCookie.shader

a guest
Jun 12th, 2020
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/AnimatedLightCookie"
  2. {
  3.     Properties
  4.     {
  5.         _Tex("Primary Noise", 2D) = "white" {}
  6.         _Tex2("Secondary Noise", 2D) = "white" {}
  7.         _Range("Primary Cutoff", Range(0,1)) = 0.1
  8.         _Range2("Secondary Cutoff", Range(0,1)) = 0.5
  9.         _DistortStrength("Distort Strength", Range(0,1)) = 0.1
  10.         _Smoothness("Cutoff Smoothness", Range(0,1)) = 0.1
  11.         _SecondLayerStrength("Secondary Layer Strength", Range(0,1)) = 0.5
  12.         _Speed("Speed", Range(0,1)) = 0.2
  13.         _Strength("Strength", Range(0,1)) = 0.2
  14.         [Toggle(MOVE)] _MOVE("Back and forth?", Float) = 0
  15.         [Toggle(INVERT)] _INVERT("Invert", Float) = 0
  16.     }
  17.  
  18.         SubShader
  19.         {
  20.             Lighting Off
  21.             Blend One Zero
  22.  
  23.             Pass
  24.         {
  25.             CGPROGRAM
  26.     #include "UnityCustomRenderTexture.cginc"
  27.  
  28.     #pragma vertex CustomRenderTextureVertexShader
  29.     #pragma fragment frag
  30.     #pragma target 3.0
  31.     #pragma shader_feature MOVE
  32.     #pragma shader_feature INVERT
  33.  
  34.         sampler2D _Tex, _Tex2;
  35.         float _Range, _Smoothness, _Speed, _Range2, _Strength, _DistortStrength, _SecondLayerStrength;
  36.  
  37.         float4 frag(v2f_customrendertexture IN) : COLOR
  38.         {
  39.             // scrolling movement controlled by _Speed variable
  40.             float time = 0;
  41.             // move back and forth with a sine wave
  42. #if MOVE
  43.             time = sin(_Time.x * 20)* _Speed;
  44. #else
  45.             time = _Time.x * _Speed;
  46. #endif
  47.  
  48.             // primary noise texture, only need 1 channel
  49.             float primNoise = tex2D(_Tex, (IN.globalTexcoord.xy * 2) + (time * 0.2)).r;
  50.        
  51.             // secondary noise texture, for more fluid motion, add in the first noise as distortion
  52.             float secNoise = tex2D(_Tex2, (IN.globalTexcoord.xy * 4) + time + (primNoise * _DistortStrength));
  53.  
  54.             // detail texture to make edges a bit sharper
  55.             float4 detailTex = tex2D(_Tex2, (IN.globalTexcoord.xy * 10)) + primNoise + secNoise;
  56.            
  57.             // first layer combined noise
  58.             float clouds = (primNoise * secNoise)  * 0.5;
  59.  
  60.             // bigger second layer noise, moving slower
  61.             float4 layer2 = tex2D(_Tex2, (IN.globalTexcoord.xy) + (time * 0.1) + (primNoise * _DistortStrength));
  62.  
  63.             // smooth step through the noise
  64.             clouds = smoothstep(_Range, _Range + _Smoothness, clouds * detailTex);
  65.  
  66.             // second layer clouds, at half strength
  67.             float secondClouds = smoothstep(_Range2, _Range2 + _Smoothness, layer2.r * detailTex) * _SecondLayerStrength;
  68.             // combine both
  69.             clouds = (clouds + secondClouds);
  70.             // clamp values
  71.             clouds = saturate(clouds);
  72.             // optional invert
  73. #if INVERT
  74.             clouds = 1 - clouds;
  75. #endif
  76.             // shadow strength
  77.             clouds *= _Strength;
  78.             return float4(1,1,1,clouds);
  79.  
  80.             }
  81.             ENDCG
  82.         }
  83.         }
  84. }
Add Comment
Please, Sign In to add comment