diff --git a/vcg/complex/algorithms/update/color.h b/vcg/complex/algorithms/update/color.h index 30d8beb1..c4121f6a 100644 --- a/vcg/complex/algorithms/update/color.h +++ b/vcg/complex/algorithms/update/color.h @@ -368,7 +368,6 @@ Note: The faux bit is used to color polygonal faces uniformly } /*! \brief Perlin Noise. -\return the number of changed vertexes (the selected ones) Simple Perlin noise. To make things weirder each color band can have its own offset and frequency. Period is expressed in absolute terms. @@ -396,6 +395,34 @@ static void PerVertexPerlinNoise(MeshType& m, CoordType period, CoordType offset } + +/*! \brief Perlin Color mixing. + +Simple Perlin color mixing. Color 1 and 2 are mixed according the perlin noise function, with period and offset. +*/ +static void PerVertexPerlinColoring(MeshType& m, Scalarm period, CoordType offset = CoordType(0, 0, 0), Color4b color1 = Color4b(0, 0, 0, 255), Color4b color2 = Color4b(255, 255, 255, 255), bool onSelected = false) +{ + RequirePerVertexColor(m); + + CoordType p; + + for (VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) + if (!(*vi).IsD()) + if ((!onSelected) || ((*vi).IsS())) + { + // perlin noise is defined in 022 + p = (vi->P() / period) + offset; + double factor = (math::Perlin::Noise(p[0], p[1], p[2]) + 1.0) / 2.0; + + int rr = (color1[0] * factor) + (color2[0] * (1.0 - factor)); + int gg = (color1[1] * factor) + (color2[1] * (1.0 - factor)); + int bb = (color1[2] * factor) + (color2[2] * (1.0 - factor)); + int aa = (color1[3] * factor) + (color2[3] * (1.0 - factor)); + + (*vi).C() = Color4b(rr, gg, bb, aa); + } +} + /*! \brief Simple Noise adding function. It simply add signed noise to the color of the mesh. The noise has uniform distribution and the amplitude is +/-2^(noisebits-1). */