Update sample to use new perlin noise shader, and make cloud like
BUG=skia: Review URL: https://codereview.chromium.org/1410863006
This commit is contained in:
parent
953549235d
commit
478c04efb3
@ -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());
|
||||
}
|
||||
|
@ -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',
|
||||
|
@ -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<SkXfermode> 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user