- Home /
shader blending 2 texture script
Hi all;
I have a shader that allows me to blend two textures together. As a shader newbie, I'm struggling to try to word this carefully without too much confusion. I want to be able to blend between one texture to another on a plane asset, at one end of the plane is a snow texture and the other is a rock texture. I want to blending the middle of the plane so that if gives the effect of the first texture at 0.5 (snow) blending with the second texture (rock) - a snowy rocky blend. Here is a a picture to explain what I want to achieve:
The plane just blends the whole of the plane from one texture to another (not what I want). Any help is appreciated.
CODE:
Shader "Custom/something" {
Properties {
// define texture, default white
_MainTex ("Base (RGB)", 2D) = "white" {}
// define 2nd texture default 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 //- Blend1 is the slider to go from snow (0) to rock (1)
//_Blend1 (for (float i = 0.0; i < 1.0; i++;) = i // - test
}
SubShader {
Tags { "RenderType"="Opaque" } // render opaque geometry
LOD 400
CGPROGRAM
// surface shader, get output by calling surf function, use diffuse (lambert) lighting model
#pragma surface surf Lambert
#pragma target 3.0
//#pragma surface surf BlinnPhong
sampler2D _MainTex;
sampler2D _Texture2;
float _Blend1;
struct Input {
// get uv coordinates of _MainTex
float2 uv_MainTex;
// get uv coordinates of _Texture2
float2 uv_Texture2;
};
void surf (Input IN, inout SurfaceOutput o) {
//half4 c = tex2D (_MainTex, IN.uv_MainTex);
// how to specify uv,
// http://unitygems.com/noobshader1/
// blend 0.5
fixed4 mainCol = tex2D(_MainTex, IN.uv_MainTex);
fixed4 texTwoCol = tex2D(_Texture2, IN.uv_MainTex);
//fixed4 texTwoCol = tex2D(_Texture2, IN.uv_Texture2);
fixed4 output = lerp(mainCol, texTwoCol, _Blend1);
o.Albedo = output.rgb;
o.Alpha = output.a;
}
ENDCG
}
FallBack "Diffuse"
capture.png
(4.4 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613134339im_/https://answers.unity.com/themes/thub/images/avi.jpg)