Blend 2 Textures

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(New page: Author: Jessy ==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 w...)
 
(Description)
Line 3: Line 3:
 
==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.)  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.
+
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==
 
==Usage==

Revision as of 21:17, 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) = "" }

// iPhone 3GS and later 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>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox