surface wgsTreeHSV(float Kd = 1; string objectName = "leafShape"; string alphaMap = ""; color barkcolor = color(0.4, 0.2, 0), leafprimarycolor = color(0.353,0.506,0.090); float lhd = 0.1, /*leaf hue delta [-0.5 0.5] */ lsd = 0.05, /*leaf sat delta [0.0] */ lvd = 0.1; /*leaf val delta [0.0] */ ) { /* --- Setup Variables --- */ color surfcolor = color(0.2,0.2,0.2); normal n = normalize(N); normal nf = faceforward(n, I); uniform string shapename; //color surfcolorHSV = ctransform( "hsv" ; surfcolor); //surfcolor = color(0.5,1,1); //if poly has name attr, refer to it as shapename if(attribute("identifier:name", shapename)) { //look for any micropolys with a name and number ;) string pattern = concat(objectName, "[0-9]*$"); //if pattern exists in shapename, //it must be a poly that we want as a leaf: if(match(pattern, shapename)) { color lpc = ctransform("hsv",leafprimarycolor); //point diffp = point(lhd,lsd,lvd); color diffc = color(lhd,lsd,lvd); //color dcmax = color(1,1,1)-lpc; //apply aplha to all polys if we have one: if (alphaMap != "") Oi = Os * float texture(alphaMap); else Oi = Os; //Look at the trailing digit //if we have a "#" at end of poly: if(match("0$", shapename)) //set color to lpc surfcolor = ctransform("hsv","rgb",( (lpc + diffc) )); else if(match("1$", shapename)) surfcolor = ctransform("hsv","rgb",( (lpc - diffc) )); else if(match("2$", shapename)) surfcolor = ctransform("hsv","rgb",( (lpc + diffc*0.5) )); else if(match("3$", shapename)) surfcolor = ctransform("hsv","rgb",( (lpc - diffc*0.5) )); else if(match("4$", shapename)) surfcolor = ctransform("hsv","rgb",( (lpc + 0) )); else surfcolor =leafprimarycolor; } else {// colorize everything else differently surfcolor = barkcolor; Oi = Os; } } //Oi = Os; color diffusecolor = Kd * diffuse(nf); Ci = Oi * Cs * surfcolor * diffusecolor; }