Shader:SkyboxBlend
2017-05-20 本文已影响178人
Levi_Wan
天空盒渐变
在我们的开发中,往往会遇见需要渐变的过程给用户更好的体验。在Unity中,我们的渐变大多都是通过插值Lerp来完成的。当我们的需求如果不是float,int,vector3等插值时而是Skybox的插值呢?
这时候我们就需要使用到shader,将我们需要渐变的两张Texture纹理进行Blend操作实现渐变。
通过Shader中的pass通道进行Blend的混合实现纹理之间的混合。
-
这时我们可以通过控制_Blend可以实现天空盒的渐变。
Blend.gif
Shader "Custom/SkyBoxBlended" {
Properties {
_Tint ("Tint Color", Color) = (.5, .5, .5, .5)
_Blend ("Blend", Range(0.0,1.0)) = 0.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" {}
}
SubShader {
Tags { "Queue" = "Background" }
Cull Off
Fog { Mode Off }
Lighting Off
Color [_Tint]
Pass {
SetTexture [_FrontTex] { combine texture }
SetTexture [_FrontTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
}
Pass {
SetTexture [_BackTex] { combine texture }
SetTexture [_BackTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
}
Pass {
SetTexture [_LeftTex] { combine texture }
SetTexture [_LeftTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
}
Pass {
SetTexture [_RightTex] { combine texture }
SetTexture [_RightTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
}
Pass {
SetTexture [_UpTex] { combine texture }
SetTexture [_UpTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
}
Pass {
SetTexture [_DownTex] { combine texture }
SetTexture [_DownTex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous }
}
}
Fallback "Skybox/6 Sided", 1
}