Hello!Does anyone know where can i find a shader that can blend 2 textures based on an alpha map?So that where is white,Texture 1 is visible 100% and where it is black,Texture 2 is visible 100% and where it is gray,they are mixed.I am using unity 3.x…I found something that was using a lightmap,but it didn’t worked
Please help me!
Anyone? :[
EDIT: Oh nevermind, i didnt read your post carefully.
I will use the Lerp function
If you have got a surfaceshader :
fixed4 texture1 = tex2D(_Texture1, IN.uv_Texture1);
fixed4 texture2 = tex2D(_Texture2, IN.uv_Texture2);
fixed alpha = tex2D(_Alpha, IN.uv_Alpha).r;
o.Albedo = lerp(texture2, texture1, alpha);
Thus, when alpha = 1 → 100% texture1
when alpha = 0 → 100% texture2
Otherwise, the lerp function blend your textures
OH,i see!
Sorry,but i am a total noob when it comes to shaders…If this would be my shader :
Shader "Example/Rim" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_BumpMap ("Bumpmap", 2D) = "bump" {}
_RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
_RimPower ("Rim Power", Range(0.5,8.0)) = 3.0
}
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float3 viewDir;
};
sampler2D _MainTex;
sampler2D _BumpMap;
float4 _RimColor;
float _RimPower;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
o.Normal = UnpackNormal (tex2D (_BumpMap, IN.uv_BumpMap));
half rim = 1.0 - saturate(dot (normalize(IN.viewDir), o.Normal));
o.Emission = _RimColor.rgb * pow (rim, _RimPower);
}
ENDCG
}
Fallback "Diffuse"
}
Where do i place it?If i place your snipped in the surf function it gives a bunch of errors Thanks!
I am using Unity 3
Oh i just found what i needed!
http://www.unifycommunity.com/wiki/index.php?title=LayerShader
Thank you for your help
This uses the same principle