- Home /
shader cg blending two textures
Hi all;
I'm learning cg shaders at the moment and I've managed to blend two textures together by following some intro tutorials. What I want to do is blend one texture into another - in my case, snow into rock. So far I have a slider that allows me to manually adjust the blending of the snow into rock textures (in the object inspector). Is there a way of eliminating the use of the slider and manually set how much of texture 1 blends into texture 2? (using code within the shader only). Any advise will be appreciated.
Code:
Shader "Custom/something" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Texture2 ("Blend Texture 1", 2D) = "white" {}
//http://answers.unity3d.com/questions/232106/shader-blending-multiple-textures-in-cg-code.html
_Blend1 ("Blend between _MainTex and Texture2", Range (0, 1) ) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 400
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
//#pragma surface surf BlinnPhong
sampler2D _MainTex;
sampler2D _Texture2;
float _Blend1;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
//half4 c = tex2D (_MainTex, IN.uv_MainTex);
fixed4 mainCol = tex2D(_MainTex, IN.uv_MainTex);
fixed4 texTwoCol = tex2D(_Texture2, IN.uv_MainTex);
fixed4 output = lerp(mainCol, texTwoCol, _Blend1);
o.Albedo = output.rgb;
o.Alpha = output.a;
}
ENDCG
}
FallBack "Diffuse"
}
Answer by Owen-Reynolds · Feb 20, 2014 at 10:09 PM
Material.setFloat will change material slider values. It doesn't care about the range -- that's only for the Inspector slider.
http://docs.unity3d.com/Documentation/ScriptReference/Material.SetFloat.html