Advertisement
Guest User

CloudsMoving.shader

a guest
Mar 6th, 2018
4,336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. Shader "FX/Clouds" {
  2. Properties{
  3. _Color("Tint", Color) = (1,1,1,1)
  4. _Noise("Noise (RGB)", 2D) = "gray" {}
  5. _TColor("Cloud Top Color", Color) = (1,0.6,1,1)
  6. _CloudColor("Cloud Base Color", Color) = (0.6,1,1,1)
  7. _RimColor("Rim Color", Color) = (0.6,1,1,1)
  8. _RimPower("Rim Power", Range(0,40)) = 20
  9. _Scale("World Scale", Range(0,0.1)) = 0.004
  10. _AnimSpeedX("Animation Speed X", Range(-2,2)) = 1
  11. _AnimSpeedY("Animation Speed Y", Range(-2,2)) = 1
  12. _AnimSpeedZ("Animation Speed Z", Range(-2,2)) = 1
  13. _Height("Noise Height", Range(0,2)) = 0.8
  14. _Strength("Noise Emission Strength", Range(0,2)) = 0.3
  15. }
  16.  
  17. SubShader{
  18. Tags{ "RenderType" = "Opaque" }
  19. LOD 200
  20. Cull Off
  21. CGPROGRAM
  22.  
  23. #pragma surface surf Lambert vertex:disp addshadow
  24.  
  25. sampler2D _Noise;
  26. float4 _Color, _CloudColor, _TColor, _RimColor;
  27. float _Scale, _Strength, _RimPower, _Height;
  28. float _AnimSpeedX, _AnimSpeedY, _AnimSpeedZ;
  29.  
  30. struct Input {
  31. float3 viewDir;
  32. float4 noiseComb;
  33. float4 col;
  34. };
  35.  
  36. struct appdata {
  37. float4 vertex : POSITION;
  38. float3 normal : NORMAL;
  39. };
  40.  
  41. void disp(inout appdata_full v, out Input o)
  42. {
  43. UNITY_INITIALIZE_OUTPUT(Input, o);
  44.  
  45. float3 worldSpaceNormal = normalize(mul((float3x3)unity_ObjectToWorld, v.normal.xyz));// worldspace normal for blending
  46. float3 worldNormalS = saturate(pow(worldSpaceNormal * 1.4, 4)); // corrected blend value
  47. float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;// world position for projecting
  48.  
  49. float movementSpeedX = _Time.x * _AnimSpeedX; //movement over X
  50. float movementSpeedY = _Time.x * _AnimSpeedY; //movement over Y
  51. float movementSpeedZ = _Time.x * _AnimSpeedZ; //movement over Z
  52.  
  53. float4 xy = float4((worldPos.x * _Scale) - movementSpeedX, (worldPos.y * _Scale)- movementSpeedY, 0, 0); // xy texture projection over worldpos * scale and movement
  54. float4 xz = float4((worldPos.x * _Scale) - movementSpeedX, (worldPos.z * _Scale) - movementSpeedZ, 0, 0); // same with xz
  55. float4 yz = float4((worldPos.y * _Scale) - movementSpeedY, (worldPos.z * _Scale) - movementSpeedZ, 0, 0); // same with yz
  56.  
  57. float4 noiseXY = tex2Dlod(_Noise, xy);// textures projected
  58. float4 noiseXZ = tex2Dlod(_Noise, xz );
  59. float4 noiseYZ = tex2Dlod(_Noise, yz);
  60.  
  61. o.noiseComb = noiseXY; // combining the texture sides
  62. o.noiseComb = lerp(o.noiseComb, noiseXZ, worldNormalS.y);
  63. o.noiseComb = lerp(o.noiseComb, noiseYZ, worldNormalS.x);
  64.  
  65. v.vertex.xyz += (v.normal *(o.noiseComb * _Height)); // displacement
  66.  
  67. o.col = lerp(_CloudColor, _TColor, v.vertex.y);// gradient over vertex
  68. }
  69.  
  70. void surf(Input IN, inout SurfaceOutput o) {
  71. half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal * (IN.noiseComb* _Strength))); // rimlight using normal and noise
  72. o.Emission = _RimColor.rgb *pow(rim, _RimPower); // add glow rimlight to the clouds
  73. o.Albedo = IN.col *_Color;// gradient * color tint
  74. }
  75. ENDCG
  76.  
  77. }
  78.  
  79. Fallback "Diffuse"
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement