Blend 2 Textures

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
Line 4: Line 4:
 
==Description==
 
==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.
+
These shaders blend between two textures based on a 0-1 value that you control. The first version is extra-fast because it does not use lighting, and the second uses the same basic ambient + diffuse calculation that I used in my [[Simply Lit]] shader.
 
+
   
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==
 
==Usage==
  
 
Drag a different texture onto each of the material's variable slots, and use the Blend control to mix them to taste.
 
Drag a different texture onto each of the material's variable slots, and use the Blend control to mix them to taste.
  
 +
Take note that the lit version requires two passes on  the GPU used in the oldest iOS devices.
  
[[Media:Blend 2 Textures.zip|Click here for a zip file that includes these three shaders.]]
+
 
 +
[[Media:Blend 2 Textures.zip|Click here for a zip file that includes these shaders.]]
  
 
==ShaderLab - Blend 2 Textures.shader==
 
==ShaderLab - Blend 2 Textures.shader==
 
<shaderlab>Shader "Blend 2 Textures" {  
 
<shaderlab>Shader "Blend 2 Textures" {  
  
 
+
Properties {
Properties  
+
{
+
 
_Blend ("Blend", Range (0, 1) ) = 0.5  
 
_Blend ("Blend", Range (0, 1) ) = 0.5  
 
_MainTex ("Texture 1", 2D) = ""  
 
_MainTex ("Texture 1", 2D) = ""  
Line 26: Line 24:
 
}
 
}
  
SubShader  
+
SubShader {
{
+
Pass {
Pass  
+
SetTexture[_MainTex]
{
+
SetTexture[_Texture2] {  
SetTexture [_MainTex]
+
     
+
SetTexture [_Texture2]  
+
{  
+
 
ConstantColor (0,0,0, [_Blend])  
 
ConstantColor (0,0,0, [_Blend])  
combine texture lerp(constant) previous
+
Combine texture Lerp(constant) previous
 
}
 
}
 
}
 
}
Line 45: Line 39:
 
==ShaderLab - Blend 2 Textures, Simply Lit.shader==
 
==ShaderLab - Blend 2 Textures, Simply Lit.shader==
 
<shaderlab>Shader "Blend 2 Textures, Simply Lit" {  
 
<shaderlab>Shader "Blend 2 Textures, Simply Lit" {  
 
+
 
+
Properties {
Properties  
+
_Color ("Color", Color) = (1,1,1)
{
+
_Blend ("Blend", Range (0,1)) = 0.5  
_Blend ("Blend", Range (0, 1) ) = 0.5  
+
 
_MainTex ("Texture 1", 2D) = ""  
 
_MainTex ("Texture 1", 2D) = ""  
 
_Texture2 ("Texture 2", 2D) = ""
 
_Texture2 ("Texture 2", 2D) = ""
 
}
 
}
  
// iPhone 3GS and later
+
Category {
SubShader
+
Material {
{
+
Ambient[_Color]
Lighting On
+
Diffuse[_Color]
+
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
+
// iPhone 3GS and later
SubShader
+
SubShader {Pass {
{
+
Lighting On
Pass
+
SetTexture[_MainTex]
{
+
SetTexture[_Texture2] {  
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])  
 
ConstantColor (0,0,0, [_Blend])  
combine texture lerp(constant) previous
+
Combine texture Lerp(constant) previous
 
}
 
}
+
SetTexture[_] {Combine previous * primary Double}
SetTexture [nothing]
+
}}
{
+
combine previous * primary DOUBLE
+
}
+
}
+
}  
+
 
+
// pre-3GS devices, including the September 2009 8GB iPod touch
+
SubShader
+
{
+
 
 
Pass
+
// pre-3GS devices, including the September 2009 8GB iPod touch
{
+
SubShader {
SetTexture [_MainTex]
+
Pass {
+
SetTexture[_MainTex]
SetTexture [_Texture2]
+
SetTexture[_Texture2] {
{
+
ConstantColor (0,0,0, [_Blend])
ConstantColor (0,0,0, [_Blend])
+
Combine texture Lerp(constant) previous
combine texture lerp(constant) previous
+
}
 
}
 
}
}
+
Pass {
+
Lighting On
Pass
+
Blend DstColor SrcColor
{
+
Blend DstColor SrcColor
+
+
Lighting On
+
Material
+
{
+
Ambient (2,2,2)
+
Diffuse (1,1,1)
+
 
}
 
}
 
}
 
}
 
}
 
}
 
  
 
}</shaderlab>
 
}</shaderlab>

Revision as of 19:07, 26 October 2010

Author: Jessy

Contents

Description

These shaders blend between two textures based on a 0-1 value that you control. The first version is extra-fast because it does not use lighting, and the second uses the same basic ambient + diffuse calculation that I used in my Simply Lit shader.

Usage

Drag a different texture onto each of the material's variable slots, and use the Blend control to mix them to taste.

Take note that the lit version requires two passes on the GPU used in the oldest iOS devices.


Click here for a zip file that includes these 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 { _Color ("Color", Color) = (1,1,1) _Blend ("Blend", Range (0,1)) = 0.5 _MainTex ("Texture 1", 2D) = "" _Texture2 ("Texture 2", 2D) = "" }

Category { Material { Ambient[_Color] Diffuse[_Color] }

// iPhone 3GS and later SubShader {Pass { Lighting On SetTexture[_MainTex] SetTexture[_Texture2] { ConstantColor (0,0,0, [_Blend]) Combine texture Lerp(constant) previous } SetTexture[_] {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 { Lighting On Blend DstColor SrcColor } } }

}</shaderlab>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox