由 ChildPark » 4日 9月 2005年, 23:51
還可將黑色區域作透明處理。
surface ri_mulitlayer(
float Ka = 1,
Kd = 0.5;
color col = color(1,1,1);
color col1 = color(1,0,0);
color col2 = color(0,1,0);
color col3 = color(0,0,1);
color bg = color(0,0,0);
)
{
float fuzz = 0.005;
normal Nf = faceforward(normalize(N), I);
/* Layer 1 color */
float ss1 = smoothstep(0-fuzz, 0+fuzz, s) - smoothstep(0.2, 0.2+fuzz, s);
float tt1 = smoothstep(0-fuzz, 0+fuzz, t) - smoothstep(0.2, 0.2+fuzz, t);
float comp1 = ss1*tt1;
color layer1 = mix(bg, col, comp1);
/* Layer 2 color */
float ss2 = smoothstep(0.2-fuzz, 0.2+fuzz, s) - smoothstep(0.4, 0.4+fuzz, s);
float tt2 = smoothstep(0.2-fuzz, 0.2+fuzz, t) - smoothstep(0.4, 0.4+fuzz, t);
float comp2 = ss2+tt2;
color layer2 = mix(layer1, col1, comp2);
/* Layer 3 color */
float ss3 = smoothstep(0.4-fuzz, 0.4+fuzz, s) - smoothstep(0.6, 0.6+fuzz, s);
float tt3 = smoothstep(0.4-fuzz, 0.4+fuzz, t) - smoothstep(0.6, 0.6+fuzz, t);
float comp3 = ss3+tt3;
color layer3 = mix(layer2, col2, comp3);
/* Layer 4 color */
float ss4 = smoothstep(0.6-fuzz, 0.6+fuzz, s) - smoothstep(0.8, 0.8+fuzz, s);
float tt4 = smoothstep(0.6-fuzz, 0.6+fuzz, t) - smoothstep(0.8, 0.8+fuzz, t);
float comp4 = ss4+tt4;
color layer4 = mix(layer3, col3, comp4);
float comp5 = comp1+comp2+comp3+comp4;
if(comp5 < 0.5){
comp5 = 0;
}else{
comp5 = 1;
}
Oi = comp5;
Ci = Oi * layer4 * (Ka * ambient() + Kd * diffuse(Nf));
}