原地址:http://www.it2down.com/it-mobile/426479.htm
当前位置: IT异常查询网 »
unity3D打造skybox淡入淡出 - 移动开发
www.it2down.com 发布于:2013-6-18 21:54:54
unity3D制作skybox淡入淡出
首先建立个shader
材质间的动画转换
skybox的纹理褪色,渐渐的转变。
设置纹理等
首先建立个shader
Shader "Custom/Skybox" { Properties { _Tint ("Tint Color", Color) = (.5, .5, .5, .5) _FrontTex ("Front (+Z)", 2D) = "white" {} _BackTex ("Back (-Z)", 2D) = "white" {} _LeftTex ("Left (+X)", 2D) = "white" {} _RightTex ("Right (-X)", 2D) = "white" {} _UpTex ("Up (+Y)", 2D) = "white" {} _DownTex ("Down (-Y)", 2D) = "white" {} _FrontTex2("2 Front (+Z)", 2D) = "white" {} _BackTex2("2 Back (-Z)", 2D) = "white" {} _LeftTex2("2 Left (+X)", 2D) = "white" {} _RightTex2("2 Right (-X)", 2D) = "white" {} _UpTex2("2 Up (+Y)", 2D) = "white" {} _DownTex2("2 Down (-Y)", 2D) = "white" {} _Color ("Fade (use alpha)", Color) = (1,1,1,1) } SubShader { Tags { "Queue" = "Background" } Cull Off ZWrite On ZTest Always Fog { Mode Off } Lighting Off Color [_Tint] Pass { SetTexture [_FrontTex] { combine texture } SetTexture[_FrontTex2] { constantColor [_Color] combine texture lerp (constant) previous } } Pass { SetTexture [_BackTex] { combine texture } SetTexture[_BackTex2] { constantColor [_Color] combine texture lerp (constant) previous } } Pass { SetTexture [_LeftTex] { combine texture } SetTexture[_LeftTex2] { constantColor [_Color] combine texture lerp (constant) previous } } Pass { SetTexture [_RightTex] { combine texture } SetTexture[_RightTex2] { constantColor [_Color] combine texture lerp (constant) previous } } Pass { SetTexture [_UpTex] { combine texture } SetTexture[_UpTex2] { constantColor [_Color] combine texture lerp (constant) previous } } Pass { SetTexture [_DownTex] { combine texture } SetTexture[_DownTex2] { constantColor [_Color] combine texture lerp (constant) previous } } } Fallback "RenderFX/Skybox", 1 }
材质间的动画转换
private var thisMaterial : Material; private var fadeSpeed : float = 0.4; function Start (){ thisMaterial = RenderSettings.skybox; thisMaterial.color.a = 0.0; } function Update () { thisMaterial.color.a += (fadeSpeed * Time.deltaTime); thisMaterial.color.a = Mathf.Clamp(thisMaterial.color.a, 0.0, 1.0); }
skybox的纹理褪色,渐渐的转变。
public var blackTexture : Texture2D; function Start (){ thisMaterial = RenderSettings.skybox; thisMaterial.color.a = 0.0; thisMaterial.SetTexture("_FrontTex", blackTexture); thisMaterial.SetTexture("_BackTex", blackTexture); thisMaterial.SetTexture("_LeftTex", blackTexture); thisMaterial.SetTexture("_RightTex", blackTexture); thisMaterial.SetTexture("_UpTex", blackTexture); thisMaterial.SetTexture("_DownTex", blackTexture); } function Update () { thisMaterial.color.a += (fadeSpeed * Time.deltaTime); thisMaterial.color.a = Mathf.Clamp(thisMaterial.color.a, 0.0, 1.0); }
设置纹理等
thisMaterial.SetTexture("_FrontTex2", textureVariable);