Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2.  
  3. Shader "Custom/AdditiveScreenTexture"{
  4. Properties {
  5. _TintColor ("Tint Color", Color) = (1,1,1,1)
  6. _EmissionGain ("Emission Gain", Range(0, 1)) = 0.052
  7. _Cloudy ("Cloudy", Range (0, 4)) = .15
  8. _Params ("Size (MinMax) Wind (MinMax)", Vector) = (32, 64, 1, 1)
  9. _ParamsB ("Angle (RAD) Variat", Vector) = (-1.87, -1.27, 5, 0)
  10. _Wind ("Wind speed", Range (0, 2)) = .2
  11. _Rotation ("Rotation", Range (0, 1)) = 0
  12. _Samples ("Samples", Range (1, 10)) = 2
  13. _MainTex ("Texture", 2D) = "white" {}
  14.  
  15. }
  16.  
  17. Category {
  18. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
  19. Blend SrcAlpha One
  20. ZWrite Off
  21.  
  22. SubShader {
  23. Pass {
  24.  
  25. CGPROGRAM
  26. // Upgrade NOTE: excluded shader from DX11; has structs without semantics (struct v2f members worldPos)
  27. #pragma exclude_renderers d3d11
  28. #pragma vertex vert
  29. #pragma fragment frag
  30.  
  31. fixed4 _TintColor;
  32. float _EmissionGain;
  33. half _Cloudy;
  34. half _Rotation;
  35. half _Wind;
  36. half4 _Params;
  37. half4 _ParamsB;
  38. int _Samples;
  39. sampler2D _MainTex;
  40. float4 _MainTex_ST;
  41.  
  42. struct appdata_t {
  43. float4 vertex : POSITION;
  44. fixed4 color : COLOR;
  45. };
  46.  
  47. struct v2f {
  48. float4 vertex : SV_POSITION;
  49. fixed4 color : COLOR;
  50. float2 worldPosition: TEXCOORD0;
  51. };
  52.  
  53.  
  54. v2f vert (appdata_t v)
  55. {
  56. v2f o;
  57. o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  58. o.color = v.color ;
  59. o.worldPosition = mul(unity_ObjectToWorld, v.vertex);
  60. return o;
  61. }
  62.  
  63. float pingpong(float value, float freq){
  64. return sin( (value*3.1415926536) * freq);
  65. }
  66.  
  67. float semiRandom(float2 uv){
  68. return frac(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453);
  69. }
  70.  
  71. fixed noise(v2f i, float size, float2 speed){
  72. float2 uv = speed * _Time.x + i.worldPosition.xy * size;
  73. return tex2D(_MainTex, uv).x;
  74. }
  75.  
  76.  
  77. // rotated 45 degrees
  78. fixed noise45(v2f i, float size, float2 speed){
  79. float2 uv = speed * _Time.x + i.worldPosition.xy * size;
  80.  
  81. float y = uv.y * 0.7071067812;
  82. float x = uv.x * 0.7071067812;
  83. uv = half2(x+y,-x+y);
  84.  
  85. return tex2D(_MainTex, uv).x;
  86. }
  87.  
  88. fixed noise452(v2f i, float size, float2 speed) {
  89. float2 xy = speed * _Time.x + i.worldPosition.xy * size;
  90.  
  91. // xy = xy * 0.7071067812;
  92. // xy = float2(xy.x+xy.y,-xy.x+xy.y);
  93. xy = tex2D(_MainTex, xy).xy ;
  94.  
  95. return abs(xy.x + sin(( (xy.x * 1.3f + xy.y * 2.135f) - (xy.x * 1.172f + xy.y * .35f)) * _ParamsB.z * _Time.x) * 0.6f);
  96. }
  97.  
  98. float2 rotate(float2 original, float angle ){
  99. float sinX = sin ( angle );
  100. float cosX = cos ( angle );
  101. float sinY = sin ( angle );
  102. float2x2 rotationMatrix = float2x2( cosX, -sinX, sinY, cosX);
  103. return mul(original, rotationMatrix );
  104. }
  105.  
  106. fixed4 frag (v2f i) : SV_Target
  107. {
  108. float clouds = .5 + noise452(i, 1/_Params.x, rotate(float2(_Wind,0), _ParamsB.x)*_Params.z)*2;
  109.  
  110. for(int s=1;s<_Samples;s++){
  111. float s01 = s/(float)(_Samples-1);
  112. float2 direction = rotate(float2(_Wind,0), lerp(_ParamsB.x, _ParamsB.y, s01) );
  113. clouds = clouds - ( noise452(i, 1/lerp(_Params.x, _Params.y, s01), direction * (lerp(_Params.z, _Params.w, s01)))) * lerp(.3, 1, s01);
  114. }
  115.  
  116. float4 shaftColor = i.color*i.color;
  117.  
  118. return lerp(shaftColor, shaftColor*clouds, _Cloudy) * _TintColor * (exp(_EmissionGain * 5));
  119. }
  120.  
  121. ENDCG
  122. }
  123. }
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement