Blend 2 Textures
(→Description) |
(→ShaderLab - Blend 2 Textures.shader) |
||
Line 25: | Line 25: | ||
} | } | ||
− | |||
SubShader | SubShader | ||
{ | { | ||
Line 45: | Line 44: | ||
}</shaderlab> | }</shaderlab> | ||
− | |||
==ShaderLab - Blend 2 Textures, Simply Lit.shader== | ==ShaderLab - Blend 2 Textures, Simply Lit.shader== |
Revision as of 21:18, 12 November 2009
Author: Jessy
Contents |
Description
This shader blends between two textures based on a 0-1 value that you control. There is an extra-fast version that does not use lighting, and two versions which do. (One of these does not allow for overblown highlights, and the other allows 2x brightness like most of Unity's built-in shaders.) The lighting is the same basic ambient + diffuse calculation that I used in my Simply Lit shaders.
I recommend the lit versions only for devices with a GPU newer than that which was used in the original iPhones and iPod touches (such as the iPhone 3GS), because with the newer GPU, this shader can be rendered in one pass.
Usage
Drag a different texture onto each of the material's variable slots, and use the Blend control to mix them to taste.
Click here for a zip file that includes these three shaders.
ShaderLab - Blend 2 Textures.shader
<shaderlab>Shader "Blend 2 Textures" {
Properties
{
_Blend ("Blend", Range (0, 1) ) = 0.5
_MainTex ("Texture 1", 2D) = ""
_Texture2 ("Texture 2", 2D) = ""
}
SubShader { Pass { SetTexture [_MainTex] { combine texture }
SetTexture [_Texture2] { ConstantColor (0,0,0, [_Blend]) combine texture lerp(constant) previous } } }
}</shaderlab>
ShaderLab - Blend 2 Textures, Simply Lit.shader
<shaderlab>Shader "Blend 2 Textures, Simply Lit" {
Properties
{
_Blend ("Blend", Range (0, 1) ) = 0.5
_MainTex ("Texture 1", 2D) = ""
_Texture2 ("Texture 2", 2D) = ""
}
// iPhone 3GS and later SubShader { Lighting On
Material { Ambient (2,2,2) Diffuse (1,1,1) }
Pass { SetTexture [_MainTex] { combine texture }
SetTexture [_Texture2] { ConstantColor (0,0,0, [_Blend]) combine texture lerp(constant) previous }
SetTexture [_nothing] { combine previous * primary } } }
// pre-3GS devices, including the September 2009 8GB iPod touch SubShader { Lighting On
Material { Ambient (2,2,2) Diffuse (1,1,1) }
Pass { SetTexture [_MainTex] { combine texture }
SetTexture [_Texture2] { ConstantColor (0,0,0, [_Blend]) combine texture lerp(constant) previous } }
Pass { Blend DstColor Zero
SetTexture [_nothing] { combine primary } } }
}</shaderlab>
ShaderLab - Blend 2 Textures, Simply Lit DOUBLE.shader
<shaderlab>Shader "Blend 2 Textures, Simply Lit DOUBLE" {
Properties
{
_Blend ("Blend", Range (0, 1) ) = 0.5
_MainTex ("Texture 1", 2D) = ""
_Texture2 ("Texture 2", 2D) = ""
}
// iPhone 3GS and later SubShader { Lighting On
Material { Ambient (2,2,2) Diffuse (1,1,1) }
Pass { SetTexture [_MainTex] { combine texture }
SetTexture [_Texture2] { ConstantColor (0,0,0, [_Blend]) combine texture lerp(constant) previous }
SetTexture [_nothing] { combine previous * primary DOUBLE } } }
// pre-3GS devices, including the September 2009 8GB iPod touch SubShader { Lighting On
Material { Ambient (2,2,2) Diffuse (1,1,1) }
Pass { SetTexture [_MainTex] { combine texture }
SetTexture [_Texture2] { ConstantColor (0,0,0, [_Blend]) combine texture lerp(constant) previous } }
Pass { Blend DstColor SrcColor
SetTexture [_nothing] { combine primary } } }
}</shaderlab>