- Home /
Question by
benfattino · Jan 09, 2013 at 03:05 PM ·
shadertextureblend
2 texture blend shader
I'm using this shader with 2 texture that blend together:
Shader "Blend 2 Textures, Simply Lit" {
Properties {
_Color ("Color Tint (A = Opacity)", Color) = (1,1,1,1)
_Blend ("Blend", Range (0,1)) = 0.0
_MainTex1 ("Texture1", 2D) = ""
_MainTex2 ("Texture2", 2D) = ""
}
Category {
Material {
Ambient[_Color]
Diffuse[_Color]
}
// iPhone 3GS and later
SubShader {
Tags {Queue = Transparent}
ZWrite On
Cull Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
Lighting On
SetTexture[_MainTex1]
SetTexture[_MainTex2] {
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[_MainTex1]
SetTexture[_MainTex2] {
ConstantColor (0,0,0, [_Blend])
Combine texture Lerp(constant) previous
}
}
Pass {
Lighting On
Blend DstColor SrcColor
}
}
}
}
How can change _MainTex2 with a script. Unity can change only MainTexture... It is possible to change also Blend value with script? Thanks.
Comment
Best Answer
Answer by markpdolby · Jan 09, 2013 at 03:25 PM
You can use material.SetFloat("_Blend", value) to set the blend value in script: http://docs.unity3d.com/Documentation/ScriptReference/Material.SetFloat.html and you can do the same for changing a subtexture by using material.SetTexture("_MainTex2", texure): http://docs.unity3d.com/Documentation/ScriptReference/Material.SetTexture.html
Answer by robertbu · Jan 09, 2013 at 10:00 PM
You an use Material.SetTexture() and Material.SetFloat()
renderer.material.SetTexture("_MainTex2", tex);
renderer.material.SetFloat("Blend", 0.25f);