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.

188 lines
8.7 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/Planets_Atmosphere"
  4. {
  5. Properties {
  6. _Highatmospherecolor ("High atmosphere color", Color) = (0.5,0.5,0.5,0)
  7. _Lowatmospherecolor ("Low atmosphere color", Color) = (0.5,0.5,0.5,1)
  8. _Inneratmosphere ("Inner atmosphere", Color) = (0.5,0.5,0.5,1)
  9. _Outeratmospherelimit ("Outer atmosphere limit", Range(0, 1)) = 0.548887
  10. _Outeratmopsheredensity ("Outer atmopshere density", Range(0, 1)) = 1
  11. _Inneratmopsheredensity ("Inner atmopshere density", Range(0, 1)) = 0.08092485
  12. _Innerouterlimit ("Inner outer limit", Range(0, 1)) = 0.6647399
  13. _Inneroutersmoothness ("Inner outer smoothness", Range(0, 1)) = 0.2572428
  14. _DisplacementAtmosphere ("Displacement atmosphere", Range(0, .1)) = 0.1
  15. }
  16. SubShader {
  17. Tags {
  18. "IgnoreProjector"="True"
  19. "Queue"="Transparent"
  20. "RenderType"="Transparent"
  21. }
  22. LOD 200
  23. Pass {
  24. Name "FORWARD"
  25. Tags {
  26. "LightMode"="ForwardBase"
  27. }
  28. Blend SrcAlpha OneMinusSrcAlpha
  29. ZWrite Off
  30. //Offset 10, -1
  31. CGPROGRAM
  32. #pragma vertex vert
  33. #pragma fragment frag
  34. #define UNITY_PASS_FORWARDBASE
  35. #include "UnityCG.cginc"
  36. #pragma multi_compile_fwdbase
  37. //#pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
  38. #pragma target 3.0
  39. uniform float4 _LightColor0;
  40. uniform float4 _Highatmospherecolor;
  41. uniform float4 _Lowatmospherecolor;
  42. uniform float _Outeratmopsheredensity;
  43. uniform float _Inneratmopsheredensity;
  44. uniform float _Innerouterlimit;
  45. uniform float _Inneroutersmoothness;
  46. uniform float _Outeratmospherelimit;
  47. uniform float4 _Inneratmosphere;
  48. uniform float _DisplacementAtmosphere;
  49. struct VertexInput {
  50. float4 vertex : POSITION;
  51. float3 normal : NORMAL;
  52. };
  53. struct VertexOutput {
  54. float4 pos : SV_POSITION;
  55. float4 posWorld : TEXCOORD0;
  56. float3 normalDir : TEXCOORD1;
  57. };
  58. VertexOutput vert (VertexInput v)
  59. {
  60. float4 vpos = v.vertex + float4(normalize(v.normal)*_DisplacementAtmosphere, 0.0f);
  61. VertexOutput o = (VertexOutput)0;
  62. o.normalDir = UnityObjectToWorldNormal(v.normal);
  63. o.posWorld = mul(unity_ObjectToWorld, vpos);
  64. float3 lightColor = _LightColor0.rgb;
  65. o.pos = UnityObjectToClipPos(vpos);
  66. return o;
  67. }
  68. float4 frag(VertexOutput i) : COLOR
  69. {
  70. i.normalDir = normalize(i.normalDir);
  71. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  72. float3 normalDirection = i.normalDir;
  73. float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
  74. float3 lightColor = _LightColor0.rgb;
  75. float3 halfDirection = normalize(viewDirection+lightDirection);
  76. float attenuation = 1;
  77. float3 attenColor = _LightColor0.xyz;
  78. float NdotL = max(0, dot( normalDirection, lightDirection ));
  79. /////// Diffuse:
  80. NdotL = dot( normalDirection, lightDirection );
  81. float3 w = float3(.25f,.25f,.25f)*0.5; // Light wrapping
  82. float3 NdotLWrap = NdotL * ( 1.0 - w );
  83. float3 forwardLight = max(float3(0.0,0.0,0.0), NdotLWrap + w );
  84. NdotL = max(0.0,dot( normalDirection, lightDirection ));
  85. float3 directDiffuse = forwardLight * attenColor;
  86. float ramp1 = smoothstep( 0.0 , _Outeratmospherelimit , pow(1.0-max(0,dot(i.normalDir, viewDirection)),7.0) );
  87. float ramp2 = smoothstep( max((_Innerouterlimit-_Inneroutersmoothness),0.0) , min((_Innerouterlimit+_Inneroutersmoothness),1.0) , 1.0-max(0,dot(i.normalDir, viewDirection)));
  88. float3 diffuseColor = lerp(_Inneratmosphere.rgb,lerp(_Lowatmospherecolor.rgb,_Highatmospherecolor.rgb,ramp1),ramp2);
  89. float3 diffuse = directDiffuse * diffuseColor;
  90. /// Final Color:
  91. float3 finalColor = diffuse;
  92. return fixed4(finalColor,(lerp(_Inneratmopsheredensity,((1.0 - ramp1)*_Outeratmopsheredensity),ramp2)*saturate((dot(lightDirection,i.normalDir)*2.0))));
  93. }
  94. ENDCG
  95. }
  96. Pass {
  97. Name "FORWARD_DELTA"
  98. Tags {
  99. "LightMode"="ForwardAdd"
  100. }
  101. Blend One One
  102. ZWrite Off
  103. Offset -1, -1
  104. CGPROGRAM
  105. #pragma vertex vert
  106. #pragma fragment frag
  107. #define UNITY_PASS_FORWARDADD
  108. #include "UnityCG.cginc"
  109. #include "AutoLight.cginc"
  110. #pragma multi_compile_fwdadd
  111. #pragma exclude_renderers gles3 metal d3d11_9x xbox360 xboxone ps3 ps4 psp2
  112. #pragma target 3.0
  113. uniform float4 _LightColor0;
  114. uniform float4 _Highatmospherecolor;
  115. uniform float4 _Lowatmospherecolor;
  116. uniform float _Outeratmopsheredensity;
  117. uniform float _Inneratmopsheredensity;
  118. float Smoothstep1( float Minvalue , float Maxvalue , float Value ){
  119. return smoothstep(Minvalue, Maxvalue, Value);
  120. }
  121. float Smoothstep2( float Minvalue , float Maxvalue , float Value ){
  122. return smoothstep(Minvalue, Maxvalue, Value);
  123. }
  124. uniform float _Innerouterlimit;
  125. uniform float _Inneroutersmoothness;
  126. uniform float _Outeratmospherelimit;
  127. uniform float4 _Inneratmosphere;
  128. struct VertexInput {
  129. float4 vertex : POSITION;
  130. float3 normal : NORMAL;
  131. };
  132. struct VertexOutput {
  133. float4 pos : SV_POSITION;
  134. float4 posWorld : TEXCOORD0;
  135. float3 normalDir : TEXCOORD1;
  136. LIGHTING_COORDS(2,3)
  137. };
  138. VertexOutput vert (VertexInput v) {
  139. VertexOutput o = (VertexOutput)0;
  140. o.normalDir = UnityObjectToWorldNormal(v.normal);
  141. o.posWorld = mul(unity_ObjectToWorld, v.vertex);
  142. float3 lightColor = _LightColor0.rgb;
  143. o.pos = UnityObjectToClipPos(v.vertex);
  144. TRANSFER_VERTEX_TO_FRAGMENT(o)
  145. return o;
  146. }
  147. float4 frag(VertexOutput i) : COLOR {
  148. i.normalDir = normalize(i.normalDir);
  149. /////// Vectors:
  150. float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
  151. float3 normalDirection = i.normalDir;
  152. float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
  153. float3 lightColor = _LightColor0.rgb;
  154. float3 halfDirection = normalize(viewDirection+lightDirection);
  155. ////// Lighting:
  156. float attenuation = LIGHT_ATTENUATION(i);
  157. float3 attenColor = attenuation * _LightColor0.xyz;
  158. float NdotL = max(0, dot( normalDirection, lightDirection ));
  159. /////// Diffuse:
  160. NdotL = dot( normalDirection, lightDirection );
  161. float3 w = float3(.25f,.25f,.25f)*0.5; // Light wrapping
  162. float3 NdotLWrap = NdotL * ( 1.0 - w );
  163. float3 forwardLight = max(float3(0.0,0.0,0.0), NdotLWrap + w );
  164. NdotL = max(0.0,dot( normalDirection, lightDirection ));
  165. float3 directDiffuse = forwardLight * attenColor;
  166. float ramp1 = smoothstep( 0.0 , _Outeratmospherelimit , pow(1.0-max(0,dot(i.normalDir, viewDirection)),7.0) );
  167. float ramp2 = Smoothstep2( max((_Innerouterlimit-_Inneroutersmoothness),0.0) , min((_Innerouterlimit+_Inneroutersmoothness),1.0) , 1.0-max(0,dot(i.normalDir, viewDirection)) );
  168. float3 diffuseColor = lerp(_Inneratmosphere.rgb,lerp(_Lowatmospherecolor.rgb,_Highatmospherecolor.rgb,ramp1),ramp2);
  169. float3 diffuse = directDiffuse * diffuseColor;
  170. /// Final Color:
  171. float3 finalColor = diffuse;
  172. return fixed4(finalColor * (lerp(_Inneratmopsheredensity,((1.0 - ramp1)*_Outeratmopsheredensity),ramp2)*saturate((dot(lightDirection,i.normalDir)*2.0))),0);
  173. }
  174. ENDCG
  175. }
  176. }
  177. FallBack "Diffuse"
  178. }