Seven is the number.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

240 lines
10 KiB

4 years ago
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  3. Shader "Custom/Planet_Clouds_Atmosphere"
  4. {
  5. Properties{
  6. _MainTex("Clouds Base (RGB)", 2D) = "white" {}
  7. _AlphaScale("Clouds alpha Scale", Range(0.0, 2.0)) = 1.0
  8. [NoScaleOffset]_BumpMap("Clouds normal Map", 2D) = "bump" {}
  9. _BumpScale("Clouds bump Scale", Range(0.0, 1.0)) = 1.0
  10. _DisplacementClouds ("Clouds displacement", Range(0, .05)) = 0.005
  11. _Highatmospherecolor ("High atmosphere color", Color) = (0.5,0.5,0.5,0)
  12. _Lowatmospherecolor ("Low atmosphere color", Color) = (0.5,0.5,0.5,1)
  13. _Inneratmosphere ("Inner atmosphere", Color) = (0.5,0.5,0.5,1)
  14. _Outeratmospherelimit ("Outer atmosphere limit", Range(0, 1)) = 0.548887
  15. _Outeratmopsheredensity ("Outer atmopshere density", Range(0, 1)) = 1
  16. _Inneratmopsheredensity ("Inner atmopshere density", Range(0, 1)) = 0.08092485
  17. _Innerouterlimit ("Inner outer limit", Range(0, 1)) = 0.6647399
  18. _Inneroutersmoothness ("Inner outer smoothness", Range(0, 1)) = 0.2572428
  19. _DisplacementAtmosphere ("Displacement atmosphere", Range(0, .1)) = 0.1
  20. }
  21. CGINCLUDE
  22. #define _GLOSSYENV 1
  23. #define UNITY_SETUP_BRDF_INPUT SpecularSetup
  24. ENDCG
  25. SubShader
  26. {
  27. Tags
  28. {
  29. "RenderType" = "Transparent"
  30. "Queue" = "Transparent"
  31. }
  32. LOD 300
  33. Blend SrcAlpha OneMinusSrcAlpha
  34. ZWrite Off
  35. CGPROGRAM
  36. #pragma target 3.0
  37. #include "UnityPBSLighting.cginc"
  38. //#pragma surface surf Standard
  39. #pragma surface surf Standard fullforwardshadows alpha vertex:vert
  40. //#pragma surface surf Lambert
  41. //#define UNITY_PASS_FORWARDBASE
  42. sampler2D _MainTex;
  43. sampler2D _BumpMap;
  44. uniform float _BumpScale;
  45. uniform float _AlphaScale;
  46. uniform float _DisplacementClouds;
  47. struct Input
  48. {
  49. float2 uv_MainTex;
  50. };
  51. void vert (inout appdata_full v)
  52. {
  53. v.vertex.xyz += v.normal * _DisplacementClouds;
  54. }
  55. void surf(Input IN, inout SurfaceOutputStandard o)
  56. {
  57. float4 albedotex = tex2D(_MainTex, IN.uv_MainTex);
  58. float4 normaltex = tex2D(_BumpMap, IN.uv_MainTex);
  59. o.Albedo = albedotex.rgb;
  60. o.Alpha = saturate(albedotex.a * _AlphaScale);
  61. o.Normal = normalize(UnpackScaleNormal(normaltex, _BumpScale));
  62. o.Metallic = 0.0f;
  63. o.Smoothness = 0.0f;
  64. }
  65. ENDCG
  66. Pass {
  67. Name "FORWARD"
  68. Tags {
  69. "LightMode"="ForwardBase"
  70. }
  71. Blend SrcAlpha OneMinusSrcAlpha
  72. ZWrite Off
  73. //Offset 10, -1
  74. CGPROGRAM
  75. #pragma vertex vert
  76. #pragma fragment frag
  77. #define UNITY_PASS_FORWARDBASE
  78. #include "UnityCG.cginc"
  79. #pragma multi_compile_fwdbase
  80. //#pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
  81. #pragma target 3.0
  82. uniform float4 _LightColor0;
  83. uniform float4 _Highatmospherecolor;
  84. uniform float4 _Lowatmospherecolor;
  85. uniform float _Outeratmopsheredensity;
  86. uniform float _Inneratmopsheredensity;
  87. uniform float _Innerouterlimit;
  88. uniform float _Inneroutersmoothness;
  89. uniform float _Outeratmospherelimit;
  90. uniform float4 _Inneratmosphere;
  91. uniform float _DisplacementAtmosphere;
  92. struct VertexInput {
  93. float4 vertex : POSITION;
  94. float3 normal : NORMAL;
  95. };
  96. struct VertexOutput {
  97. float4 pos : SV_POSITION;
  98. float4 posWorld : TEXCOORD0;
  99. float3 normalDir : TEXCOORD1;
  100. };
  101. VertexOutput vert (VertexInput v)
  102. {
  103. float4 vpos = v.vertex + float4(normalize(v.normal)*_DisplacementAtmosphere, 0.0f);
  104. VertexOutput o = (VertexOutput)0;
  105. o.normalDir = UnityObjectToWorldNormal(v.normal);
  106. o.posWorld = mul(unity_ObjectToWorld, vpos);
  107. float3 lightColor = _LightColor0.rgb;
  108. o.pos = UnityObjectToClipPos(vpos);
  109. return o;
  110. }
  111. float4 frag(VertexOutput i) : COLOR
  112. {
  113. i.normalDir = normalize(i.normalDir);
  114. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  115. float3 normalDirection = i.normalDir;
  116. float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
  117. float3 lightColor = _LightColor0.rgb;
  118. float3 halfDirection = normalize(viewDirection+lightDirection);
  119. float attenuation = 1;
  120. float3 attenColor = _LightColor0.xyz;
  121. float NdotL = max(0, dot( normalDirection, lightDirection ));
  122. /////// Diffuse:
  123. NdotL = dot( normalDirection, lightDirection );
  124. float3 w = float3(.25f,.25f,.25f)*0.5; // Light wrapping
  125. float3 NdotLWrap = NdotL * ( 1.0 - w );
  126. float3 forwardLight = max(float3(0.0,0.0,0.0), NdotLWrap + w );
  127. NdotL = max(0.0,dot( normalDirection, lightDirection ));
  128. float3 directDiffuse = forwardLight * attenColor;
  129. float ramp1 = smoothstep( 0.0 , _Outeratmospherelimit , pow(1.0-max(0,dot(i.normalDir, viewDirection)),7.0) );
  130. float ramp2 = smoothstep( max((_Innerouterlimit-_Inneroutersmoothness),0.0) , min((_Innerouterlimit+_Inneroutersmoothness),1.0) , 1.0-max(0,dot(i.normalDir, viewDirection)));
  131. float3 diffuseColor = lerp(_Inneratmosphere.rgb,lerp(_Lowatmospherecolor.rgb,_Highatmospherecolor.rgb,ramp1),ramp2);
  132. float3 diffuse = directDiffuse * diffuseColor;
  133. /// Final Color:
  134. float3 finalColor = diffuse;
  135. return fixed4(finalColor,(lerp(_Inneratmopsheredensity,((1.0 - ramp1)*_Outeratmopsheredensity),ramp2)*saturate((dot(lightDirection,i.normalDir)*2.0))));
  136. }
  137. ENDCG
  138. }
  139. Pass {
  140. Name "FORWARD_DELTA"
  141. Tags {
  142. "LightMode"="ForwardAdd"
  143. }
  144. Blend One One
  145. ZWrite Off
  146. Offset -1, -1
  147. CGPROGRAM
  148. #pragma vertex vert
  149. #pragma fragment frag
  150. #define UNITY_PASS_FORWARDADD
  151. #include "UnityCG.cginc"
  152. #include "AutoLight.cginc"
  153. #pragma multi_compile_fwdadd
  154. #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
  155. #pragma target 3.0
  156. uniform float4 _LightColor0;
  157. uniform float4 _Highatmospherecolor;
  158. uniform float4 _Lowatmospherecolor;
  159. uniform float _Outeratmopsheredensity;
  160. uniform float _Inneratmopsheredensity;
  161. float Smoothstep1( float Minvalue , float Maxvalue , float Value ){
  162. return smoothstep(Minvalue, Maxvalue, Value);
  163. }
  164. float Smoothstep2( float Minvalue , float Maxvalue , float Value ){
  165. return smoothstep(Minvalue, Maxvalue, Value);
  166. }
  167. uniform float _Innerouterlimit;
  168. uniform float _Inneroutersmoothness;
  169. uniform float _Outeratmospherelimit;
  170. uniform float4 _Inneratmosphere;
  171. struct VertexInput {
  172. float4 vertex : POSITION;
  173. float3 normal : NORMAL;
  174. };
  175. struct VertexOutput {
  176. float4 pos : SV_POSITION;
  177. float4 posWorld : TEXCOORD0;
  178. float3 normalDir : TEXCOORD1;
  179. LIGHTING_COORDS(2,3)
  180. };
  181. VertexOutput vert (VertexInput v) {
  182. VertexOutput o = (VertexOutput)0;
  183. o.normalDir = UnityObjectToWorldNormal(v.normal);
  184. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  185. float3 lightColor = _LightColor0.rgb;
  186. o.pos = UnityObjectToClipPos(v.vertex);
  187. TRANSFER_VERTEX_TO_FRAGMENT(o)
  188. return o;
  189. }
  190. float4 frag(VertexOutput i) : COLOR {
  191. i.normalDir = normalize(i.normalDir);
  192. /////// Vectors:
  193. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  194. float3 normalDirection = i.normalDir;
  195. float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
  196. float3 lightColor = _LightColor0.rgb;
  197. float3 halfDirection = normalize(viewDirection+lightDirection);
  198. ////// Lighting:
  199. float attenuation = LIGHT_ATTENUATION(i);
  200. float3 attenColor = attenuation * _LightColor0.xyz;
  201. float NdotL = max(0, dot( normalDirection, lightDirection ));
  202. /////// Diffuse:
  203. NdotL = dot( normalDirection, lightDirection );
  204. float3 w = float3(.25f,.25f,.25f)*0.5; // Light wrapping
  205. float3 NdotLWrap = NdotL * ( 1.0 - w );
  206. float3 forwardLight = max(float3(0.0,0.0,0.0), NdotLWrap + w );
  207. NdotL = max(0.0,dot( normalDirection, lightDirection ));
  208. float3 directDiffuse = forwardLight * attenColor;
  209. float ramp1 = smoothstep( 0.0 , _Outeratmospherelimit , pow(1.0-max(0,dot(i.normalDir, viewDirection)),7.0) );
  210. float ramp2 = Smoothstep2( max((_Innerouterlimit-_Inneroutersmoothness),0.0) , min((_Innerouterlimit+_Inneroutersmoothness),1.0) , 1.0-max(0,dot(i.normalDir, viewDirection)) );
  211. float3 diffuseColor = lerp(_Inneratmosphere.rgb,lerp(_Lowatmospherecolor.rgb,_Highatmospherecolor.rgb,ramp1),ramp2);
  212. float3 diffuse = directDiffuse * diffuseColor;
  213. /// Final Color:
  214. float3 finalColor = diffuse;
  215. return fixed4(finalColor * (lerp(_Inneratmopsheredensity,((1.0 - ramp1)*_Outeratmopsheredensity),ramp2)*saturate((dot(lightDirection,i.normalDir)*2.0))),0);
  216. }
  217. ENDCG
  218. }
  219. }
  220. FallBack "Diffuse"
  221. }