1.使用shader实现地球旋转的效果
Shader "CustomPractice/Earth"{
Properties{
//地球纹理
_EarthTex("EarthTex",2D)= "white"{}
//云的纹理
_CloudTex("CloudTex",2D) = "white"{}
}
Subshader{
Tags{"RendrType" = "Transparent"}
pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _EarthTex;
sampler2D _CloudTex;
struct v2f {
float4 vertex:POSITION;
float4 texcoord:TEXCOORD0;
};
void vert(inout v2f v){
v.vertex = mul(UNITY_MATRIX_MVP,v.vertex);
}
fixed4 frag(v2f v):COLOR{
//渲染球
fixed u = v.texcoord.x +_Time*0.1;
float2 uv = float2(u,v.texcoord.y);
fixed4 earthColor = tex2D(_EarthTex,uv);
//渲染层
fixed uc=v.texcoord.x+ _Time*0.3;
float2 uvc = float2(uc,v.texcoord.y);
fixed4 cloudColor = tex2D(_CloudTex,uvc);
cloudColor = cloudColor.r * fixed4(1,1,1,1);
//取出地球颜色和云颜色的插值
return lerp(earthColor,cloudColor,0.5);
}
ENDCG
}
}
}
使用shader效果
最新推荐文章于 2023-10-18 15:28:20 发布