Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Shader "Custom/LightRays"{
  2.     Properties{
  3.         _MainTex("Texture",2D)="white"{}
  4.         _Color1("Color1",Color)=(0.1,1,1,1)
  5.         _Color2("Color2",Color)=(0,0.46,1,0)
  6.         _Speed("Speed",Range(0,5.0))=0.5
  7.         _Size("Size",Range(1.0,30.0))=15.0
  8.         _Skew("Skew",Range(-1.0,1.0))=0.5
  9.         _Shear("Shear",Range(0.0,5.0))=1.0
  10.         _Fade("Fade",Range(0.0,1.0))=1.0
  11.         _Contrast("Contrast",Range(0.0,50.0))=1.0
  12.     }
  13.     SubShader{
  14.         Tags{
  15.             "Queue"="Transparent"
  16.             "IgnoreProjector"="True"
  17.             "RenderType"="Transparent"
  18.             "PreviewType"="Plane"
  19.         }
  20.         Cull Off
  21.         Lighting Off
  22.         ZWrite Off
  23.         Fog {Mode Off}
  24.         Blend SrcAlpha OneMinusSrcAlpha
  25.         Pass{
  26.             CGPROGRAM
  27.             #pragma vertex vert_img
  28.             #pragma fragment frag
  29.  
  30.             #include "UnityCG.cginc"
  31.  
  32.             float4 permute(float4 x){
  33.                 return fmod(34.0*pow(x,2)+x,289.0);
  34.             }
  35.  
  36.             float2 fade(float2 t){
  37.                 return 6.0*pow(t,5.0)-15.0*pow(t,4.0)+10.0*pow(t,3.0);
  38.             }
  39.  
  40.             float4 taylorInvSqrt(float4 r){
  41.                 return 1.79284291400159-0.85373472095314*r;
  42.             }
  43.  
  44.             #define DIV_289 0.00346020761245674740484429065744f
  45.  
  46.             float mod289(float x){
  47.                 return x-floor(x*DIV_289)*289.0;
  48.             }
  49.  
  50.             #define REPEAT_Y 1000.0
  51.  
  52.             float PerlinNoise2D(float2 P){
  53.                 //Mirror the pattern on large Y number
  54.                 if(floor(P.y/REPEAT_Y)%2==0){
  55.                     P.y-=floor(P.y/REPEAT_Y)*REPEAT_Y;
  56.                 }else{
  57.                     P.y-=floor(P.y/REPEAT_Y)*REPEAT_Y;
  58.                     P.y=REPEAT_Y-P.y;
  59.                 }
  60.                 float4 Pi=floor(P.xyxy)+float4(0.0,0.0,1.0,1.0);
  61.                 float4 Pf=frac(P.xyxy)-float4(0.0,0.0,1.0,1.0);
  62.                 float4 ix=Pi.xzxz;
  63.                 float4 iy=Pi.yyww;
  64.                 float4 fx=Pf.xzxz;
  65.                 float4 fy=Pf.yyww;
  66.                 float4 i=permute(permute(ix)+iy);
  67.                 float4 gx=frac(i/41.0)*2.0-1.0;
  68.                 float4 gy=abs(gx)-0.5;
  69.                 float4 tx=floor(gx+0.5);
  70.                 gx=gx-tx;
  71.                 float2 g00=float2(gx.x,gy.x);
  72.                 float2 g10=float2(gx.y,gy.y);
  73.                 float2 g01=float2(gx.z,gy.z);
  74.                 float2 g11=float2(gx.w,gy.w);
  75.                 float4 norm=taylorInvSqrt(float4(dot(g00,g00),dot(g01,g01),dot(g10,g10),dot(g11,g11)));
  76.                 g00*=norm.x;
  77.                 g01*=norm.y;
  78.                 g10*=norm.z;
  79.                 g11*=norm.w;
  80.                 float n00=dot(g00,float2(fx.x,fy.x));
  81.                 float n10=dot(g10,float2(fx.y,fy.y));
  82.                 float n01=dot(g01,float2(fx.z,fy.z));
  83.                 float n11=dot(g11,float2(fx.w,fy.w));
  84.                 float2 fade_xy=fade(Pf.xy);
  85.                 float2 n_x=lerp(float2(n00, n01),float2(n10, n11),fade_xy.x);
  86.                 float n_xy=lerp(n_x.x,n_x.y,fade_xy.y);
  87.                 return 2.3*n_xy;
  88.             }
  89.  
  90.             fixed4 _Color1;
  91.             fixed4 _Color2;
  92.             float _Speed;
  93.             float _Size;
  94.             float _Skew;
  95.             float _Shear;
  96.             float _Fade;
  97.             float _Contrast;
  98.  
  99.             fixed4 frag(v2f_img i):SV_Target{
  100.                 fixed4 color=lerp(_Color1,_Color2,1-i.uv.y);
  101.                 fixed noisePos=i.uv.x;
  102.                 noisePos+=-0.5;
  103.                 noisePos*=_Size;
  104.                 noisePos+=(1-i.uv.y)*(_Size*_Skew);
  105.                 noisePos*=1/lerp(1,_Shear,1-i.uv.y);
  106.                 fixed val=PerlinNoise2D(float2(noisePos,_Time.y*_Speed))/2 + 0.5f;
  107.                 val=_Contrast*(val-0.5)+0.5;
  108.                 color.a*=lerp(val,val*i.uv.y,_Fade);
  109.                 color.a=clamp(color.a,0.0,1.0);
  110.                 return color;
  111.             }
  112.             ENDCG
  113.         }
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement