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.

132 lines
3.8 KiB

  1. // SpaceUnity: Shader from Unity wiki
  2. Shader "SpaceUnity/PlanetStandard"
  3. {
  4. //Earth Shader created by Julien Lynge @ Fragile Earth Studios
  5. //Upgrade of a shader originally put together in Strumpy Shader Editor by Clamps
  6. //Feel free to use and share this shader, but please include this attribution
  7. Properties
  8. {
  9. _MainTex("_MainTex", 2D) = "black" {}
  10. _Normals("_Normals", 2D) = "black" {}
  11. _Lights("_Lights", 2D) = "black" {}
  12. _LightScale("_LightScale", Float) = 1
  13. _AtmosNear("_AtmosNear", Color) = (0.1686275,0.7372549,1,1)
  14. _AtmosFar("_AtmosFar", Color) = (0.4557808,0.5187039,0.9850746,1)
  15. _AtmosFalloff("_AtmosFalloff", Float) = 3
  16. }
  17. SubShader
  18. {
  19. Tags
  20. {
  21. "Queue"="Geometry"
  22. "IgnoreProjector"="False"
  23. "RenderType"="Opaque"
  24. }
  25. Cull Back
  26. ZWrite On
  27. ZTest LEqual
  28. ColorMask RGBA
  29. Fog{
  30. }
  31. CGPROGRAM
  32. #pragma surface surf BlinnPhongEditor
  33. #pragma target 2.0
  34. sampler2D _MainTex;
  35. sampler2D _Normals;
  36. sampler2D _Lights;
  37. float _LightScale;
  38. float4 _AtmosNear;
  39. float4 _AtmosFar;
  40. float _AtmosFalloff;
  41. struct EditorSurfaceOutput {
  42. half3 Albedo;
  43. half3 Normal;
  44. half3 Emission;
  45. half3 Gloss;
  46. half Specular;
  47. half Alpha;
  48. half4 Custom;
  49. };
  50. inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
  51. {
  52. half3 spec = light.a * s.Gloss;
  53. half4 c;
  54. c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
  55. c.g -= .01 * s.Alpha;
  56. c.r -= .03 * s.Alpha;
  57. c.rg += min(s.Custom, s.Alpha);
  58. c.b += 0.75 * min(s.Custom, s.Alpha);
  59. c.b = saturate(c.b + s.Alpha * .02);
  60. c.a = 1.0;
  61. return c;
  62. }
  63. inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
  64. {
  65. half3 h = normalize (lightDir + viewDir);
  66. half diff = max (0, dot ( lightDir, s.Normal ));
  67. float nh = max (0, dot (s.Normal, h));
  68. float spec = pow (nh, s.Specular*128.0);
  69. half4 res;
  70. res.rgb = _LightColor0.rgb * diff;
  71. res.w = spec * Luminance (_LightColor0.rgb);
  72. res *= atten * 2.0;
  73. //s.Alpha is now 1 where the earth is dark. The value of night lights has been saved to Alpha
  74. half invdiff = 1 - saturate(16 * diff);
  75. s.Alpha = invdiff;
  76. return LightingBlinnPhongEditor_PrePass( s, res );
  77. }
  78. struct Input {
  79. float3 viewDir;
  80. float2 uv_MainTex;
  81. float2 uv_Normals;
  82. float2 uv_Lights;
  83. };
  84. void surf (Input IN, inout EditorSurfaceOutput o) {
  85. o.Gloss = 0.0;
  86. o.Specular = 0.0;
  87. o.Custom = 0.0;
  88. o.Alpha = 1.0;
  89. float4 Fresnel0_1_NoInput = float4(0,0,1,1);
  90. float4 Fresnel0=(1.0 - dot( normalize( float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ).xyz), normalize( Fresnel0_1_NoInput.xyz ) )).xxxx;
  91. float4 Pow0=pow(Fresnel0,_AtmosFalloff.xxxx);
  92. float4 Saturate0=saturate(Pow0);
  93. float4 Lerp0=lerp(_AtmosNear,_AtmosFar,Saturate0);
  94. float4 Multiply1=Lerp0 * Saturate0;
  95. float4 Sampled2D2=tex2D(_MainTex,IN.uv_MainTex.xy);
  96. float4 Add0=Multiply1 + Sampled2D2;
  97. float4 Sampled2D0=tex2D(_Normals,IN.uv_Normals.xy);
  98. float4 UnpackNormal0=float4(UnpackNormal(Sampled2D0).xyz, 1.0);
  99. o.Albedo = Add0;
  100. o.Normal = UnpackNormal0;
  101. //o.Emission = Multiply0;
  102. o.Emission = 0.0;
  103. //float4 Multiply0=Sampled2D1 * _LightScale.xxxx;
  104. o.Custom = tex2D(_Lights,IN.uv_Lights.xy).r * _LightScale;
  105. o.Normal = normalize(o.Normal);
  106. }
  107. ENDCG
  108. }
  109. Fallback "Diffuse"
  110. }