Blend 2 Textures

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(ShaderLab - Blend 2 Textures.shader)
m
Line 1: Line 1:
 +
[[Category:iPhone]]
 
Author: Jessy
 
Author: Jessy
  
Line 5: Line 6:
 
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.
 
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.
+
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==

Revision as of 05:51, 15 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] { 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