After reading one of the post in this forum, suddenly just want to make something similar to test my idea. It’s work ![]()
But, the question is how many textures allowed in shader model 3.0? Is it safe to use more than 4 textures always??
Shader "Multi_Texture_ColorKey"
{
Properties
{
key ("key " , 2D) = "" {}
tx0 ("yellow" , 2D) = "" {}
tx1 ("red " , 2D) = "" {}
tx2 ("green" , 2D) = "" {}
tx3 ("blue ", 2D) = "" {}
tx4 ("magenta", 2D) = "" {}
tx5 ("cyan" , 2D) = "" {}
tx6 ("white" , 2D) = "" {}
tx7 ("black" , 2D) = "" {}
}
SubShader
{
Pass
{
CGPROGRAM //--------------
#pragma target 3.0
#pragma vertex vertex_shader
#pragma fragment fragment_shader
struct src
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD;
};
void vertex_shader( src src1,
out float4 position : POSITION,
out float2 texcoord : TEXCOORD)
{
position = mul(glstate.matrix.mvp, src1.vertex);
texcoord = src1.texcoord;
}
void fragment_shader( float2 t:TEXCOORD,
uniform sampler2D key,
uniform sampler2D tx0,
uniform sampler2D tx1,
uniform sampler2D tx2,
uniform sampler2D tx3,
uniform sampler2D tx4,
uniform sampler2D tx5,
uniform sampler2D tx6,
uniform sampler2D tx7,
out float4 c : COLOR )
{
float4 color = tex2D(key,t);
float r = (color.r >= 0.5)? 1:0;
float g = (color.g >= 0.5)? 1:0;
float b = (color.b >= 0.5)? 1:0;
c = float4(0,0,0,0);
c += tex2D(tx0,t)*( r g !b); // yellow
c += tex2D(tx1,t)*( r !g !b); // red
c += tex2D(tx2,t)*(!r g !b); // green
c += tex2D(tx3,t)*(!r !g b); // blue
c += tex2D(tx4,t)*( r !g b); // magenta
c += tex2D(tx5,t)*(!r g b); // cyan
c += tex2D(tx6,t)*( r g b); // white
c += tex2D(tx7,t)*(!r !g !b); // black
}
ENDCG //--------------
} // Pass
} // SubShader
} // Shader
(Sorry that, no lights and bump mapping at the moment :p)