original articles should be reproduced please specify: Reproduced from the Wind Yu Chong Unity3d Tutorial College
Shader Fourth Lecture: Making a beautiful Earth
Vertex and Fragment Shader example two, make an auto-rotating 3D earth.
Download the Beautiful Earth Project
The principle is 2 poster, a map of the Earth, a map of the clouds
(1) by uv.x that is the texture coordinates of the horizontal axis and time multiplied, resulting in the ball in the movement of the effect (2) through the earth and cloud color values superimposed to form a cascade effect.
Note: The ' Wrap Mode ' property of the decal must be set to repeat
About Wrap Mode
When wrap mode is clamp: it means that the value of the texture XY axis is limited to the range of [0,1], with the axis u as an example, the left and right sides are not connected.
When wrap mode is repeat: The idea is that you can imagine that a map of the earth is a tile, and when wrap mode is repeat, the entire texture is covered with n rows of x-n columns of tiles, which can be interpreted as infinitely large. Take u as an example, as shown below. The advantage is that in clamp mode, the two sides of the map, where u is 0 and U is 1, are not connected. Now the left and right sides of the picture are connected. Portrait V is the same. This technology is mainly used when the texture is a brick texture (tiled Texture), that is, the left and right and the upper and lower lines are connected, a small piece of texture map can render a large area. such as a large meadow and so on.
Attached: Shader code
shader "Custom/2lsy_earth" {properties { _maintex ("Texture", 2D) = "White" {} _cloud ("_cloud", 2d) = ' White ' {}} subshader { tags{"Queue" = "Transparent" "rendertype" = "Transparent"} pass {Cgprogram # Pragma vertex vert #pragma fragment frag #include "unitycg.cginc" FLOAT4 _color; Sampler2d _maintex; Sampler2d _cloud; struct v2f { float4 pos:SV_POSITION; float2 uv: texcoord0; } ; FLOAT4 _maintex_st; v2f Vert (Appdata_base v) { //as before v2f o; o.pos = Mul (UNITY_MATRIX_MVP, V.vertex);     O.UV = Transform_tex (V.texcoord, _maintex); return o; } Half4 Frag (v2f i): color { //map UV of the earth, X i.e. transverse in motion float u_x = i. uv.x + -0.1*_time; Float2 uv_earth=float2 (u_x, I.UV.Y); half4 Texcolor_earth = tex2d (_maintex, Uv_earth); //Clouds Map UV x is also moving, but moving faster some  FLOAT2 Uv_cloud; u_x = i.uv.x + -0.2*_time; UV_CLOUD=FLOAT2 (u_x, I.UV.Y); Half4 tex_clouddepth = tex2d (_cloud, Uv_cloud);
Pure white x Depth value = cloud color of the point half4 Texcolor_cloud = FLOAT4 (1,1,1,0) * (tex_clouddepth.x);
Earth Cloud Color Mixed return lerp (texcolor_earth,texcolor_cloud,0.5f); } ENDCG}}} take care of the work, and look at the effect, isn't it great.