Moisaic Noise
Site Map Feedback

Download:

Up Mosaic Perlin Simplex Voronoi

Mosaic Noise The simplest noise texture is random rectangular areas. It is easy to overlook patterns like this, but occasionally some part of one of the images created may be exactly what you need as a basis for something more complex. The Textures page shows a floor tile being made from apparently unrelated gradients. Noise has a MosaicNoise methods which take three coordinates to create repeatable distortable images. The following code produced the above image; you can see the different x and y scales and the constant z:

  for(WORD x=GetWidth(); x--; ) { // Loops are best comparing the counter with zero, so this counts down.
    double u=double(x)/Width; // Calculate the parameter (ratio in the range [0,1]) indicating how far through the loop is.
    for(DWORD y=GetHeight(); y--;) {
      double v=double(y)/GetHeight(); // Calculate the parameter (ratio in the range [0,1]) indicating how far through the loop is.
      BYTE B=BYTE(Round(255*Noise::UnsignedMosaic(u*10, v*20, 0.5))); // Turn the parameter into a Greyscale Level.
      SetPixel(x,y, RGB(B,B,B));
  } }
GetWidth(), GetHeight() and SetPixel are members of CPixelBlock which was used as a base class.
Round is declared in Global.h.

The function given to the z parameter can be varied, and the mixed octaves idea (described on the Psuedo Random Number Generator (PRNG) page) can be implemented (with the following code):

  for(WORD x=GetWidth(); x--;) {
    double u=double(x)/GetWidth();
    for(WORD y=GetHeight(); y--;) {
      double v=double(y)/GetHeight();
      int Octaves=3;
      double Result=0;
      for(DWORD Frequency=1; Octaves--; Frequency<<=1) {
        Result+=Noise::Mosaic((u*10)*Frequency, (v*10)*Frequency, (0.5*10)*Frequency);
      }
      BYTE B=BYTE(Round(255*Clamped(0.0, Unsigned(Result)/3, 1.0)));
      SetPixel(x,y, RGB(B,B,B));
    }
  }
 
Clamped and Unsigned are declared in Global.h.

These are a few variations:
Mosaic Noise Examples
The noise functions return signed intervals in the range [-1,1] which are reasonably good to add together for mixing. It does mean that a fiddle-factor is needed to scale the amplitude (brightness) which is what the 'Clamped' and '/3' are doing to the Result.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.