Got something to say? I'd love to hear from you, but I'm afraid that if I publish my email address on a web page these days, people will write me lots of mail about how I can "increase my manhood" or purchase inexpensive V1@gra. So instead let's try this. Just put your message in, give your return address, and if you're not trying to sell me questionable goods, I'll do my best answer you. Trust me; it's so simple, even a former Nigerian general with lots of regretably inaccessible cash could do it.
surface Rust(float smooth = 25;float severity = .5;float multipass = 10;float age = 60; ) {
//float smooth = 20; // Higher numbers for less blocky rust. ~ 12 - 45
//float severity = .8; //for mixing, 0-1.
//float multipass = 10; //1-inf
//float age = 60; //You start to see rust around 25. Objects disappear around 90. Max 112
float displace = 0; // Whether or not to displace this pixel.
//This will give us the patchy effect.
float phase = noise(s*(smooth),t*(smooth));
//We don't want age-phase to go below 1.
if (age - phase < 1) phase = age - 1;
normal Nf;
Nf = faceforward( normalize(N), I );
//From Dave's example
vector NS = vtransform( "shader" , N );
point PS = transform( "shader" , P );
float i; //Really...
//Like blinn, only more convenient. :)
color thispixel = Oi * ( (Cs * (diffuse(Nf) - .3)) +
(specular(normalize(N),normalize(-I),8) *15)
* 6 /*.025*/);
//Now rust it.
//Blend a random color out of the "ramp" texture.
for (i=0;i<multipass;i = i + 1) {
//No particular numeric significance here, but I'm trying to adjust the
//amount of rust vs. metal based on age, and this does a good job.
if (phase > ((1/112) * age))break;
//Different lighting for the rusted metal...
if (displace = 0) { //Always do this only once per pixel
thispixel = Oi * ((thispixel*(diffuse(Nf)*12)) +
(specular(normalize(N),normalize(-I),2)*4)*9);
}
//Rust. -- This will blend a random rust color up to element <age> in
//our ramp, <multipass> times.
thispixel = mix(thispixel,
/*Lookup from our color ramp*/
color texture("rust.tex",
(1/112)*round(random() * age),.5),
severity);
displace = 1;
}
if(displace == 1) {
//Displace a little, based on age, but only if the spot is rusted.
PS += (phase * (.0005 * age)) * normalize(NS);
}
Oi = Os;
Ci = Oi * thispixel;
P = transform( "shader", "current", PS );
N = calculatenormal(P);
}