#include "material.h" #include "locillum.h" #include "noises.h" #include "filterwidth.h" //! The Bark_Colour Shader /** * This file contains the Bark_Colour surface shader. * @author Hannes Ricklefs - NCCA 2005 */ //! A Function /** * Small helper function if color values are expressed in 0 - 255. * \param i - number to be devided by 255 * \return - the equivalent value i space 0 - 1 */ float photo_prman(float i) { return i/255; } //! The surface Shader /** * This surface shader applies the colour to a surface in order to create * a Photorealistic tree bark image. * Inputs: * \param Kd - the diffuse component * \param Ka - the ambient component * \param crack_moss_height - the hight up to which the moss in the crack should grow * \param top_moss_height - the hight from which the moss should grow on top of the surface * \param grain - the amount of grain to mix the overall color of the surface * \param roughness - the roughness parameter of the surface * \param baseColor - the color for the bottom of the cracks * \param middleColor - the color between the cracks and the top of the surface * \param topColor - the color for the top of the surface * \param topMoss - the color of the Moss to grow on top of the surface * \param crackMoss - the color of the Moss to grow in the cracks * \param space - the space in which to apply the shader. */ surface Bark_Colour(float Kd = 0.7, Ka = 1, crack_moss_height = 3.0, top_moss_height = 6.0, grain = 0.5, roughness = 0.5; varying color baseColor = color (photo_prman(194), photo_prman(206), photo_prman(104)), middleColor = color (photo_prman(119), photo_prman(92), photo_prman(25)), topColor = color (photo_prman(206), photo_prman(175), photo_prman(95)), topMoss = color (photo_prman(174), photo_prman(200), photo_prman(73)), crackMoss = color (0.3,0.3,0.2); string space="shader"; ) { //standard shader initialisation normal n = normalize(N); normal Nf = faceforward(n, I); point PP = transform(space, P); float height = 0; color finalColor = 0; //get the displacment if(displacement("hump",height) == 1) { //generate a variation of colours- color darkColor = baseColor - 0.025; color lowBaseColor = baseColor + 0.025; color lowerMiddleColor = middleColor - 0.0125; color higherMiddleColor = middleColor + 0.0125; color lowTopColor = topColor - 0.025; color higherTopColor = topColor + 0.025; //interpolate the color finalColor = spline ( height, darkColor, baseColor, lowBaseColor, lowerMiddleColor, middleColor, higherMiddleColor, topColor, lowTopColor, higherTopColor); //apply a more organic look to the surface float mixvalue = fBm(2*PP,filterwidthp(PP),6,2,grain); //check if we grow moss in the cracks if(height < crack_moss_height) { //push the value more towards the Moss value finalColor = mix(finalColor,crackMoss,mixvalue+0.5); } //check if we grow moss on the surface if(height > top_moss_height) { //push the value more towards the Moss value finalColor = mix(finalColor,topMoss,mixvalue+0.5); } } //assigne the final color based on the clay material Ci = finalColor * (Ka*ambient() + Kd*LocIllumOrenNayar(Nf,-normalize(I),roughness)); Oi = Os; }