#include "noises.h" #include "filterwidth.h" //! Macro /** * A macro to normalize a given value to a specified range. * \param mi - the minimum value of the range * \param mx - the maximum value of the range * \param value - the value to be normalized * \return the normalized value */ #define normalizeRange(mi,mx,value) (value-mi)/(mx-mi) //! The Bark2 Shader /** * This file contains the Bark_Texture displacement shader. * @author Hannes Ricklefs - NCCA 2005 */ //! The displacement shader /** * This displacement shader provides the basic functionality to create * a Photorealistic looking Treebark based on a given texture file.It is * more seen as a prove of concept! * After the texture file has been applied and the turbulence has been adjusted the user should use the * provided normalrange.pl script to identify the range of displacement this pattern generates. * The resulting min and max values should be passed into lowNormaliseRange and topNormaliseRange respectively. * * Inputs * \param dispScale - the Scale factor for the texture. * \param texname - the path and name of the texture file. * \param space - the space in which the shader should be be applied * \param turboctaves - the octaves of the Turbulence in order to add turbulence to the overall texture. * \param turblcunarity - the lacunarity of the Turbulence in order to add turbulence to the overall texture. * \param turbgain - the gain of the Turbulence in order to add turbulence to the overall texture. * \param lowNormaliseRange - the min value calculated by the displacement inorder to normalise the output hump. * .The normlrange.pl script should be used to calculate the min value. * \param topNormaliseRange - the max value calculated by the displacement inorder to normalise the output hump. * .The normlrange.pl script should be used to calculate the max value. * * Outputs: * \param hump - the displacement normalise according to lowNormaliseRange and topNormaliseRange * */ displacement Bark_Texture (float dispScale=0.04; string texname="", space="shader"; float trueDisp=1, turboctaves=4, turblac=2, turbgain=0.5, lowNormaliseRange=0.300805, topNormaliseRange=2.037044; output varying float hump = 0;) { //standard shader initialisation normal NN = normalize(N); point PP = transform(space,P); //Apply the texture file if(texname != "") { hump = (float texture(texname,s,t))+ turbulence(PP,filterwidthp(PP),turboctaves,turblac,turbgain); } //printf ("%f\n",hump); PP=P+NN*hump*dispScale; N=calculatenormal(PP); //if ture displacement is selected if(trueDisp) P=PP; //normalise the hump value hump = normalizeRange(lowNormaliseRange,topNormaliseRange,hump); }