Guest User

Clouds.shader

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