aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar senorblanco <senorblanco@chromium.org>2014-06-12 11:24:19 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-06-12 11:24:20 -0700
commitce6a354e121915c2925e545e7df2929492d69d50 (patch)
tree0d402dcd9fb7e585254f3dcd43051b7d532e3c93 /gm
parente61c411c1258a323a010558c08de3d9f8d170dca (diff)
Fix tiled perlin noise.
It turns out that the perlin implementation we inherited from WebKit does not actually generate tileable noise (see Chromium bug http://crbug.com/383495). The main problem is that when generating coordinates for gradient interpolation, it was attempting to wrap both x and (x + 1) simultaneously at the tile boundary (that is, either both or neither are wrapped). This obviously won't work, since along the tile seams, (x + 1) should be wrapped, but x should not. The same is true in y. This patch fixes both the CPU and GPU paths, renames some variables to more closely match the spec, and modifies the perlin noise GM to actually test tiling. (Note that the clipping the GM was doing was removed, since it's superfluous: it used to be necessary for image filters, but isn't anymore, and this isn't an image filter GM anyway.) R=sugoi@google.com, sugoi TBR=senorblanco Author: senorblanco@chromium.org Review URL: https://codereview.chromium.org/332523006
Diffstat (limited to 'gm')
-rw-r--r--gm/perlinnoise.cpp33
1 files changed, 21 insertions, 12 deletions
diff --git a/gm/perlinnoise.cpp b/gm/perlinnoise.cpp
index ee58f6f5aa..b69b7d0476 100644
--- a/gm/perlinnoise.cpp
+++ b/gm/perlinnoise.cpp
@@ -24,13 +24,11 @@ protected:
return SkISize::Make(200, 500);
}
- void drawClippedRect(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
+ void drawRect(SkCanvas* canvas, int x, int y, const SkPaint& paint, const SkISize& size) {
canvas->save();
- canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
- SkIntToScalar(fSize.width()), SkIntToScalar(fSize.height())));
- SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
- SkIntToScalar(fSize.width()),
- SkIntToScalar(fSize.height()));
+ canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
+ SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()),
+ SkIntToScalar(size.height()));
canvas->drawRect(r, paint);
canvas->restore();
}
@@ -38,14 +36,25 @@ protected:
void test(SkCanvas* canvas, int x, int y, SkPerlinNoiseShader::Type type,
float baseFrequencyX, float baseFrequencyY, int numOctaves, float seed,
bool stitchTiles) {
+ SkISize tileSize = SkISize::Make(fSize.width() / 2, fSize.height() / 2);
SkShader* shader = (type == SkPerlinNoiseShader::kFractalNoise_Type) ?
SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves,
- seed, stitchTiles ? &fSize : NULL) :
+ seed, stitchTiles ? &tileSize : NULL) :
SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, numOctaves,
- seed, stitchTiles ? &fSize : NULL);
+ seed, stitchTiles ? &tileSize : NULL);
SkPaint paint;
paint.setShader(shader)->unref();
- drawClippedRect(canvas, x, y, paint);
+ if (stitchTiles) {
+ drawRect(canvas, x, y, paint, tileSize);
+ x += tileSize.width();
+ drawRect(canvas, x, y, paint, tileSize);
+ y += tileSize.width();
+ drawRect(canvas, x, y, paint, tileSize);
+ x -= tileSize.width();
+ drawRect(canvas, x, y, paint, tileSize);
+ } else {
+ drawRect(canvas, x, y, paint, fSize);
+ }
}
virtual void onDraw(SkCanvas* canvas) {
@@ -58,10 +67,10 @@ protected:
test(canvas, 0, 100, SkPerlinNoiseShader::kFractalNoise_Type,
0.1f, 0.1f, 2, 0, false);
test(canvas, 100, 100, SkPerlinNoiseShader::kFractalNoise_Type,
- 0.2f, 0.4f, 5, 0, true);
+ 0.05f, 0.1f, 1, 0, true);
test(canvas, 0, 200, SkPerlinNoiseShader::kTurbulence_Type,
- 0.1f, 0.1f, 2, 0, true);
+ 0.1f, 0.1f, 1, 0, true);
test(canvas, 100, 200, SkPerlinNoiseShader::kTurbulence_Type,
0.2f, 0.4f, 5, 0, false);
@@ -75,7 +84,7 @@ protected:
test(canvas, 0, 400, SkPerlinNoiseShader::kFractalNoise_Type,
0.1f, 0.1f, 2, 0, false);
test(canvas, 100, 400, SkPerlinNoiseShader::kFractalNoise_Type,
- 0.2f, 0.4f, 5, 0, true);
+ 0.1f, 0.05f, 1, 0, true);
}
private: