1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkPerlinNoiseShader_DEFINED 9 #define SkPerlinNoiseShader_DEFINED 10 11 #include "include/core/SkShader.h" 12 13 /** \class SkPerlinNoiseShader 14 15 SkPerlinNoiseShader creates an image using the Perlin turbulence function. 16 17 It can produce tileable noise if asked to stitch tiles and provided a tile size. 18 In order to fill a large area with repeating noise, set the stitchTiles flag to 19 true, and render exactly a single tile of noise. Without this flag, the result 20 will contain visible seams between tiles. 21 22 The algorithm used is described here : 23 http://www.w3.org/TR/SVG/filters.html#feTurbulenceElement 24 */ 25 class SK_API SkPerlinNoiseShader { 26 public: 27 /** 28 * This will construct Perlin noise of the given type (Fractal Noise or Turbulence). 29 * 30 * Both base frequencies (X and Y) have a usual range of (0..1) and must be non-negative. 31 * 32 * The number of octaves provided should be fairly small, with a limit of 255 enforced. 33 * Each octave doubles the frequency, so 10 octaves would produce noise from 34 * baseFrequency * 1, * 2, * 4, ..., * 512, which quickly yields insignificantly small 35 * periods and resembles regular unstructured noise rather than Perlin noise. 36 * 37 * If tileSize isn't NULL or an empty size, the tileSize parameter will be used to modify 38 * the frequencies so that the noise will be tileable for the given tile size. If tileSize 39 * is NULL or an empty size, the frequencies will be used as is without modification. 40 */ 41 static sk_sp<SkShader> MakeFractalNoise(SkScalar baseFrequencyX, SkScalar baseFrequencyY, 42 int numOctaves, SkScalar seed, 43 const SkISize* tileSize = nullptr); 44 static sk_sp<SkShader> MakeTurbulence(SkScalar baseFrequencyX, SkScalar baseFrequencyY, 45 int numOctaves, SkScalar seed, 46 const SkISize* tileSize = nullptr); 47 48 static void RegisterFlattenables(); 49 50 private: 51 SkPerlinNoiseShader() = delete; 52 }; 53 54 #endif 55