From 478c04efb352e84e8ccbf633ba5b352c28a12012 Mon Sep 17 00:00:00 2001 From: egdaniel Date: Mon, 9 Nov 2015 07:40:49 -0800 Subject: [PATCH] Update sample to use new perlin noise shader, and make cloud like BUG=skia: Review URL: https://codereview.chromium.org/1410863006 --- .../SkPerlinNoiseShader2.cpp | 10 ++++---- gyp/SampleApp.gyp | 5 ++++ samplecode/PerlinPatch.cpp | 24 +++++++++++-------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp index b0d1812951..bbfb8cf583 100644 --- a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp +++ b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp @@ -1076,7 +1076,7 @@ private: class GrImprovedPerlinNoiseEffect : public GrFragmentProcessor { public: - static GrFragmentProcessor* Create(SkScalar octaves, SkScalar z, + static GrFragmentProcessor* Create(int octaves, SkScalar z, SkPerlinNoiseShader2::PaintingData* paintingData, GrTexture* permutationsTexture, GrTexture* gradientTexture, const SkMatrix& matrix) { @@ -1292,11 +1292,11 @@ void GrGLImprovedPerlinNoise::emitCode(EmitArgs& args) { fsBuilder->codeAppendf("vec2 coords = %s * %s;", vCoords.c_str(), baseFrequencyUni); fsBuilder->codeAppendf("float r = %s(vec3(coords, %s), %s);", noiseOctavesFuncName.c_str(), zUni, octavesUni); - fsBuilder->codeAppendf("float g = %s(vec3(coords, %s + 1000.0), %s);", + fsBuilder->codeAppendf("float g = %s(vec3(coords, %s + 0000.0), %s);", noiseOctavesFuncName.c_str(), zUni, octavesUni); - fsBuilder->codeAppendf("float b = %s(vec3(coords, %s + 2000.0), %s);", + fsBuilder->codeAppendf("float b = %s(vec3(coords, %s + 0000.0), %s);", noiseOctavesFuncName.c_str(), zUni, octavesUni); - fsBuilder->codeAppendf("float a = %s(vec3(coords, %s + 3000.0), %s);", + fsBuilder->codeAppendf("float a = %s(vec3(coords, %s + 0000.0), %s);", noiseOctavesFuncName.c_str(), zUni, octavesUni); fsBuilder->codeAppendf("%s = vec4(r, g, b, a);", args.fOutputColor); @@ -1322,7 +1322,7 @@ void GrGLImprovedPerlinNoise::onSetData(const GrGLSLProgramDataManager& pdman, const SkVector& baseFrequency = noise.baseFrequency(); pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); - pdman.set1f(fOctavesUni, noise.octaves()); + pdman.set1f(fOctavesUni, SkIntToScalar(noise.octaves())); pdman.set1f(fZUni, noise.z()); } diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp index f87c1b89a7..1fdb15b760 100644 --- a/gyp/SampleApp.gyp +++ b/gyp/SampleApp.gyp @@ -20,6 +20,7 @@ '../src/pipe/utils', # For TiledPipeController '../src/utils/debugger', '../tools', + '../experimental', ], 'includes': [ 'gmslides.gypi', @@ -131,6 +132,10 @@ #'../experimental/Networking/SkSockets.cpp', #'../experimental/Networking/SkSockets.h', + # PerlinNoise2 + '../experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp', + '../experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h', + # TiledPipeController '../src/pipe/utils/SamplePipeControllers.h', '../src/pipe/utils/SamplePipeControllers.cpp', diff --git a/samplecode/PerlinPatch.cpp b/samplecode/PerlinPatch.cpp index 9f86f1f217..945b6921fe 100644 --- a/samplecode/PerlinPatch.cpp +++ b/samplecode/PerlinPatch.cpp @@ -10,7 +10,7 @@ #include "SkCanvas.h" #include "SkGradientShader.h" #include "SkPatchUtils.h" -#include "SkPerlinNoiseShader.h" +#include "SkPerlinNoiseShader2/SkPerlinNoiseShader2.h" #include "SkComposeShader.h" static void draw_control_points(SkCanvas* canvas, const SkPoint cubics[12]) { @@ -94,25 +94,21 @@ public: fPts[11].set(150, 150); const SkColor colors[SkPatchUtils::kNumCorners] = { - SK_ColorBLUE, SK_ColorYELLOW + 0xFF5555FF, 0xFF8888FF, 0xFFCCCCFF }; - - fShader0 = SkGradientShader::CreateRadial(SkPoint::Make(128.0f, 128.0f), - 180.0f, + const SkPoint points[2] = { SkPoint::Make(0.0f, 0.0f), + SkPoint::Make(100.0f, 100.0f) }; + fShader0 = SkGradientShader::CreateLinear(points, colors, NULL, - 2, + 3, SkShader::kMirror_TileMode, 0, NULL); - fShader1 = SkPerlinNoiseShader::CreateTurbulence(fXFreq, fYFreq, 2, fSeed, NULL); - fShaderCompose = new SkComposeShader(fShader0, fShader1); } virtual ~PerlinPatchView() { SkSafeUnref(fShader0); - SkSafeUnref(fShader1); - SkSafeUnref(fShaderCompose); } protected: // overrides from SkEventSink @@ -125,6 +121,7 @@ protected: } bool onAnimate(const SkAnimTimer& timer) override { + fSeed += 0.005f; return true; } @@ -147,10 +144,17 @@ protected: SkAutoTUnref xfer(SkXfermode::Create(SkXfermode::kSrc_Mode)); + SkScalar scaleFreq = 2.0; + fShader1 = SkPerlinNoiseShader2::CreateImprovedNoise(fXFreq/scaleFreq, fYFreq/scaleFreq, 4, + fSeed); + fShaderCompose = new SkComposeShader(fShader0, fShader1); + paint.setShader(fShaderCompose); canvas->drawPatch(fPts, nullptr, texCoords, xfer, paint); draw_control_points(canvas, fPts); + SkSafeUnref(fShader1); + SkSafeUnref(fShaderCompose); } class PtClick : public Click { -- 2.34.1