#define ORANGE color(1,0.5,0.1) #define WHITEMOULD color(1,1,1) #define GREENMOULD color(0.3,0.4,0.3) surface orange(float Ka=1,Kd=1,Ks=1; float roughness=0.1; color specularcolor = color(1,1,1); float age=0.5) { point Nf,PP,DP; point V=normalize(-I); float d,ks,kd,a,m; color cm; /* color of mould */ float om; /* opacity of mould */ color cs; PP=transform("shader",P); /* Make dimples on surface */ d=abs(noise(30*PP)); d=pow(d,6); /* make surface mostly flat */ /* d=sin(0.5*3.14*d); round them off */ DP=P-0.1*d*N; /* Put the end in slightly */ DP=DP-0.2*pow(1-smoothstep(0,0.2,t),3)*N; DP=DP-0.2*pow(smoothstep(0.8,1,t),3)*N; /* Do some aging - make it mouldy */ /* Make some duller sections */ a=0.8*noise(1*PP)+0.6*noise(2.7*PP)+0.4*noise(5.05*PP); a=1-(1-a)*age; ks=pow(a,3)*Ks; kd=pow(a,2)*Kd; /* add some mould ! */ m=4*noise(3*PP)*noise(6.7*PP)*noise(12.05*PP); m+=0.35*(age+age*0.5*noise(3*PP)); m=m*smoothstep(0.3,0.6,age); m=pow(clamp(m,0,1),3-age*2); cm=mix(WHITEMOULD,GREENMOULD,smoothstep(0.5,0.8,m)); om=smoothstep(0.4,0.7,m); /* combine underlying surface colour and mould colour */ cs=mix(ORANGE,cm,om); ks=ks*(1-om); kd=mix(0.2,kd,smoothstep(0.01,0.02,t)); Nf=calculatenormal(DP); Nf=faceforward(normalize(Nf),I); Oi=Os; Ci=Os*(cs*(Ka*ambient()+kd*diffuse(Nf))+ specularcolor*ks*specular(Nf,V,roughness)); }