Blend 2 Textures

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m
Line 31: Line 31:
 
{
 
{
 
SetTexture [_MainTex]
 
SetTexture [_MainTex]
{
 
combine texture
 
}
 
 
        
 
        
 
SetTexture [_Texture2]  
 
SetTexture [_Texture2]  
Line 71: Line 68:
 
{
 
{
 
SetTexture [_MainTex]
 
SetTexture [_MainTex]
{
 
combine texture
 
}
 
 
        
 
        
 
SetTexture [_Texture2]  
 
SetTexture [_Texture2]  
Line 81: Line 75:
 
}
 
}
 
 
SetTexture [_nothing]
+
SetTexture [nothing]
 
{
 
{
 
combine previous * primary
 
combine previous * primary
Line 91: Line 85:
 
SubShader  
 
SubShader  
 
{
 
{
Lighting On
 
 
Material
 
{
 
Ambient (2,2,2)
 
Diffuse (1,1,1)
 
}
 
 
 
Pass  
 
Pass  
 
{
 
{
 
SetTexture [_MainTex]
 
SetTexture [_MainTex]
{
 
combine texture
 
}
 
 
 
 
SetTexture [_Texture2]
 
SetTexture [_Texture2]
Line 116: Line 99:
 
{
 
{
 
Blend DstColor Zero
 
Blend DstColor Zero
+
SetTexture [_nothing]
+
Lighting On
 +
Material
 
{
 
{
combine primary
+
Ambient (2,2,2)
}
+
Diffuse (1,1,1)
 +
}
 
}
 
}
 
}
 
}
Line 153: Line 138:
 
{
 
{
 
SetTexture [_MainTex]
 
SetTexture [_MainTex]
{
 
combine texture
 
}
 
 
        
 
        
 
SetTexture [_Texture2]  
 
SetTexture [_Texture2]  
Line 163: Line 145:
 
}
 
}
 
 
SetTexture [_nothing]
+
SetTexture [nothing]
 
{
 
{
 
combine previous * primary DOUBLE
 
combine previous * primary DOUBLE
Line 173: Line 155:
 
SubShader  
 
SubShader  
 
{
 
{
Lighting On
 
 
Material
 
{
 
Ambient (2,2,2)
 
Diffuse (1,1,1)
 
}
 
 
 
 
Pass  
 
Pass  
 
{
 
{
 
SetTexture [_MainTex]
 
SetTexture [_MainTex]
{
 
combine texture
 
}
 
 
 
 
SetTexture [_Texture2]
 
SetTexture [_Texture2]
Line 198: Line 170:
 
{
 
{
 
Blend DstColor SrcColor
 
Blend DstColor SrcColor
+
SetTexture [_nothing]
+
Lighting On
 +
Material
 
{
 
{
combine primary
+
Ambient (2,2,2)
 +
Diffuse (1,1,1)
 
}
 
}
 
}
 
}

Revision as of 01:06, 29 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, the lit shaders can be rendered in one pass. You can cut the SubShader from Blend 2 Textures and paste it in place of the second SubShader, for either of the lit versions. Doing so will ensure that one pass is used on all devices, but the newer models will utilize real-time lighting.

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]

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]

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 { Pass { SetTexture [_MainTex]

SetTexture [_Texture2] { ConstantColor (0,0,0, [_Blend]) combine texture lerp(constant) previous } }

Pass { Blend DstColor Zero

Lighting On Material { Ambient (2,2,2) Diffuse (1,1,1) } } }


}</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]

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 {

Pass { SetTexture [_MainTex]

SetTexture [_Texture2] { ConstantColor (0,0,0, [_Blend]) combine texture lerp(constant) previous } }

Pass { Blend DstColor SrcColor

Lighting On Material { Ambient (2,2,2) Diffuse (1,1,1) } } }


}</shaderlab>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox