Index: experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h |
diff --git a/include/effects/SkPerlinNoiseShader.h b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h |
similarity index 72% |
copy from include/effects/SkPerlinNoiseShader.h |
copy to experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h |
index 0cb1b47a9f4b57b12e979ebb81ec41f445e36101..3c02c5de244c546ad39b4f3b15a1882882332c76 100644 |
--- a/include/effects/SkPerlinNoiseShader.h |
+++ b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h |
@@ -5,14 +5,14 @@ |
* found in the LICENSE file. |
*/ |
-#ifndef SkPerlinNoiseShader_DEFINED |
-#define SkPerlinNoiseShader_DEFINED |
+#ifndef SkPerlinNoiseShader2_DEFINED |
+#define SkPerlinNoiseShader2_DEFINED |
#include "SkShader.h" |
-/** \class SkPerlinNoiseShader |
+/** \class SkPerlinNoiseShader2 |
- SkPerlinNoiseShader creates an image using the Perlin turbulence function. |
+ SkPerlinNoiseShader2 creates an image using the Perlin turbulence function. |
It can produce tileable noise if asked to stitch tiles and provided a tile size. |
In order to fill a large area with repeating noise, set the stitchTiles flag to |
@@ -22,24 +22,30 @@ |
The algorithm used is described here : |
http://www.w3.org/TR/SVG/filters.html#feTurbulenceElement |
*/ |
-class SK_API SkPerlinNoiseShader : public SkShader { |
+class SK_API SkPerlinNoiseShader2 : public SkShader { |
public: |
struct StitchData; |
struct PaintingData; |
/** |
- * About the noise types : the difference between the 2 is just minor tweaks to the algorithm, |
- * they're not 2 entirely different noises. The output looks different, but once the noise is |
- * generated in the [1, -1] range, the output is brought back in the [0, 1] range by doing : |
+ * About the noise types : the difference between the first 2 is just minor tweaks to the |
+ * algorithm, they're not 2 entirely different noises. The output looks different, but once the |
+ * noise is generated in the [1, -1] range, the output is brought back in the [0, 1] range by |
+ * doing : |
* kFractalNoise_Type : noise * 0.5 + 0.5 |
* kTurbulence_Type : abs(noise) |
* Very little differences between the 2 types, although you can tell the difference visually. |
+ * "Improved" is based on the Improved Perlin Noise algorithm described at |
+ * http://mrl.nyu.edu/~perlin/noise/. It is quite distinct from the other two, and the noise is |
+ * a 2D slice of a 3D noise texture. Minor changes to the Z coordinate will result in minor |
+ * changes to the noise, making it suitable for animated noise. |
*/ |
enum Type { |
kFractalNoise_Type, |
kTurbulence_Type, |
+ kImprovedNoise_Type, |
kFirstType = kFractalNoise_Type, |
- kLastType = kTurbulence_Type |
+ kLastType = kImprovedNoise_Type |
}; |
/** |
* This will construct Perlin noise of the given type (Fractal Noise or Turbulence). |
@@ -62,6 +68,12 @@ public: |
int numOctaves, SkScalar seed, |
const SkISize* tileSize = NULL); |
/** |
+ * Creates an Improved Perlin Noise shader. The z value is roughly equivalent to the seed of the |
+ * other two types, but minor variations to z will only slightly change the noise. |
+ */ |
+ static SkShader* CreateImprovedNoise(SkScalar baseFrequencyX, SkScalar baseFrequencyY, |
+ int numOctaves, SkScalar z); |
+ /** |
* Create alias for CreateTurbulunce until all Skia users changed |
* its code to use the new naming |
*/ |
@@ -76,7 +88,7 @@ public: |
class PerlinNoiseShaderContext : public SkShader::Context { |
public: |
- PerlinNoiseShaderContext(const SkPerlinNoiseShader& shader, const ContextRec&); |
+ PerlinNoiseShaderContext(const SkPerlinNoiseShader2& shader, const ContextRec&); |
virtual ~PerlinNoiseShaderContext(); |
void shadeSpan(int x, int y, SkPMColor[], int count) override; |
@@ -87,6 +99,7 @@ public: |
SkScalar calculateTurbulenceValueForPoint( |
int channel, |
StitchData& stitchData, const SkPoint& point) const; |
+ SkScalar calculateImprovedNoiseValueForPoint(int channel, const SkPoint& point) const; |
SkScalar noise2D(int channel, |
const StitchData& stitchData, const SkPoint& noiseVector) const; |
@@ -102,19 +115,19 @@ public: |
#endif |
SK_TO_STRING_OVERRIDE() |
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader) |
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader2) |
protected: |
void flatten(SkWriteBuffer&) const override; |
Context* onCreateContext(const ContextRec&, void* storage) const override; |
private: |
- SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX, |
+ SkPerlinNoiseShader2(SkPerlinNoiseShader2::Type type, SkScalar baseFrequencyX, |
SkScalar baseFrequencyY, int numOctaves, SkScalar seed, |
const SkISize* tileSize); |
- virtual ~SkPerlinNoiseShader(); |
+ virtual ~SkPerlinNoiseShader2(); |
- const SkPerlinNoiseShader::Type fType; |
+ const SkPerlinNoiseShader2::Type fType; |
const SkScalar fBaseFrequencyX; |
const SkScalar fBaseFrequencyY; |
const int fNumOctaves; |