original articles should be reproduced please specify: Reproduced from the Wind Yu Chong Unity3d Tutorial College
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: The value of the texture XY axis is that the Uvs are limited to the range of [0,1], with the horizontal axis u for example, left and right sides 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 for example, e.g.. 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 {C Gprogram #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 that is horizontal 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); The map of the clouds 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 see the effect, isn't it great?
Unity3d Tutorial Shader: The fourth is about making a beautiful Earth