Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp

Issue 1410863006: Update sample to use new perlin noise shader, and make cloud like (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more nits Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gyp/SampleApp.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDither.h" 8 #include "SkDither.h"
9 #include "SkPerlinNoiseShader2.h" 9 #include "SkPerlinNoiseShader2.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni; 1069 GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni;
1070 1070
1071 private: 1071 private:
1072 typedef GrGLFragmentProcessor INHERITED; 1072 typedef GrGLFragmentProcessor INHERITED;
1073 }; 1073 };
1074 1074
1075 ///////////////////////////////////////////////////////////////////// 1075 /////////////////////////////////////////////////////////////////////
1076 1076
1077 class GrImprovedPerlinNoiseEffect : public GrFragmentProcessor { 1077 class GrImprovedPerlinNoiseEffect : public GrFragmentProcessor {
1078 public: 1078 public:
1079 static GrFragmentProcessor* Create(SkScalar octaves, SkScalar z, 1079 static GrFragmentProcessor* Create(int octaves, SkScalar z,
1080 SkPerlinNoiseShader2::PaintingData* paint ingData, 1080 SkPerlinNoiseShader2::PaintingData* paint ingData,
1081 GrTexture* permutationsTexture, GrTexture * gradientTexture, 1081 GrTexture* permutationsTexture, GrTexture * gradientTexture,
1082 const SkMatrix& matrix) { 1082 const SkMatrix& matrix) {
1083 return new GrImprovedPerlinNoiseEffect(octaves, z, paintingData, permuta tionsTexture, 1083 return new GrImprovedPerlinNoiseEffect(octaves, z, paintingData, permuta tionsTexture,
1084 gradientTexture, matrix); 1084 gradientTexture, matrix);
1085 } 1085 }
1086 1086
1087 virtual ~GrImprovedPerlinNoiseEffect() { delete fPaintingData; } 1087 virtual ~GrImprovedPerlinNoiseEffect() { delete fPaintingData; }
1088 1088
1089 const char* name() const override { return "ImprovedPerlinNoise"; } 1089 const char* name() const override { return "ImprovedPerlinNoise"; }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 noiseOctavesCode.append("p *= 2.0;"); 1285 noiseOctavesCode.append("p *= 2.0;");
1286 noiseOctavesCode.append("ratio *= 2.0;"); 1286 noiseOctavesCode.append("ratio *= 2.0;");
1287 noiseOctavesCode.append("}"); 1287 noiseOctavesCode.append("}");
1288 noiseOctavesCode.append("return (result + 1.0) / 2.0;"); 1288 noiseOctavesCode.append("return (result + 1.0) / 2.0;");
1289 fsBuilder->emitFunction(kFloat_GrSLType, "noiseOctaves", SK_ARRAY_COUNT(nois eOctavesArgs), 1289 fsBuilder->emitFunction(kFloat_GrSLType, "noiseOctaves", SK_ARRAY_COUNT(nois eOctavesArgs),
1290 noiseOctavesArgs, noiseOctavesCode.c_str(), &noiseOc tavesFuncName); 1290 noiseOctavesArgs, noiseOctavesCode.c_str(), &noiseOc tavesFuncName);
1291 1291
1292 fsBuilder->codeAppendf("vec2 coords = %s * %s;", vCoords.c_str(), baseFreque ncyUni); 1292 fsBuilder->codeAppendf("vec2 coords = %s * %s;", vCoords.c_str(), baseFreque ncyUni);
1293 fsBuilder->codeAppendf("float r = %s(vec3(coords, %s), %s);", noiseOctavesFu ncName.c_str(), 1293 fsBuilder->codeAppendf("float r = %s(vec3(coords, %s), %s);", noiseOctavesFu ncName.c_str(),
1294 zUni, octavesUni); 1294 zUni, octavesUni);
1295 fsBuilder->codeAppendf("float g = %s(vec3(coords, %s + 1000.0), %s);", 1295 fsBuilder->codeAppendf("float g = %s(vec3(coords, %s + 0000.0), %s);",
1296 noiseOctavesFuncName.c_str(), zUni, octavesUni); 1296 noiseOctavesFuncName.c_str(), zUni, octavesUni);
1297 fsBuilder->codeAppendf("float b = %s(vec3(coords, %s + 2000.0), %s);", 1297 fsBuilder->codeAppendf("float b = %s(vec3(coords, %s + 0000.0), %s);",
1298 noiseOctavesFuncName.c_str(), zUni, octavesUni); 1298 noiseOctavesFuncName.c_str(), zUni, octavesUni);
1299 fsBuilder->codeAppendf("float a = %s(vec3(coords, %s + 3000.0), %s);", 1299 fsBuilder->codeAppendf("float a = %s(vec3(coords, %s + 0000.0), %s);",
1300 noiseOctavesFuncName.c_str(), zUni, octavesUni); 1300 noiseOctavesFuncName.c_str(), zUni, octavesUni);
1301 fsBuilder->codeAppendf("%s = vec4(r, g, b, a);", args.fOutputColor); 1301 fsBuilder->codeAppendf("%s = vec4(r, g, b, a);", args.fOutputColor);
1302 1302
1303 // Clamp values 1303 // Clamp values
1304 fsBuilder->codeAppendf("%s = clamp(%s, 0.0, 1.0);", args.fOutputColor, args. fOutputColor); 1304 fsBuilder->codeAppendf("%s = clamp(%s, 0.0, 1.0);", args.fOutputColor, args. fOutputColor);
1305 1305
1306 // Pre-multiply the result 1306 // Pre-multiply the result
1307 fsBuilder->codeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n", 1307 fsBuilder->codeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n",
1308 args.fOutputColor, args.fOutputColor, 1308 args.fOutputColor, args.fOutputColor,
1309 args.fOutputColor, args.fOutputColor); 1309 args.fOutputColor, args.fOutputColor);
1310 } 1310 }
1311 1311
1312 void GrGLImprovedPerlinNoise::GenKey(const GrProcessor& processor, const GrGLSLC aps&, 1312 void GrGLImprovedPerlinNoise::GenKey(const GrProcessor& processor, const GrGLSLC aps&,
1313 GrProcessorKeyBuilder* b) { 1313 GrProcessorKeyBuilder* b) {
1314 } 1314 }
1315 1315
1316 void GrGLImprovedPerlinNoise::onSetData(const GrGLSLProgramDataManager& pdman, 1316 void GrGLImprovedPerlinNoise::onSetData(const GrGLSLProgramDataManager& pdman,
1317 const GrProcessor& processor) { 1317 const GrProcessor& processor) {
1318 INHERITED::onSetData(pdman, processor); 1318 INHERITED::onSetData(pdman, processor);
1319 1319
1320 const GrImprovedPerlinNoiseEffect& noise = processor.cast<GrImprovedPerlinNo iseEffect>(); 1320 const GrImprovedPerlinNoiseEffect& noise = processor.cast<GrImprovedPerlinNo iseEffect>();
1321 1321
1322 const SkVector& baseFrequency = noise.baseFrequency(); 1322 const SkVector& baseFrequency = noise.baseFrequency();
1323 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); 1323 pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY);
1324 1324
1325 pdman.set1f(fOctavesUni, noise.octaves()); 1325 pdman.set1f(fOctavesUni, SkIntToScalar(noise.octaves()));
1326 1326
1327 pdman.set1f(fZUni, noise.z()); 1327 pdman.set1f(fZUni, noise.z());
1328 } 1328 }
1329 1329
1330 ///////////////////////////////////////////////////////////////////// 1330 /////////////////////////////////////////////////////////////////////
1331 const GrFragmentProcessor* SkPerlinNoiseShader2::asFragmentProcessor( 1331 const GrFragmentProcessor* SkPerlinNoiseShader2::asFragmentProcessor(
1332 GrContext* context, 1332 GrContext* context,
1333 const SkMatrix& viewM, 1333 const SkMatrix& viewM,
1334 const SkMatrix* externalLoca lMatrix, 1334 const SkMatrix* externalLoca lMatrix,
1335 SkFilterQuality) const { 1335 SkFilterQuality) const {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 str->append(" seed: "); 1426 str->append(" seed: ");
1427 str->appendScalar(fSeed); 1427 str->appendScalar(fSeed);
1428 str->append(" stitch tiles: "); 1428 str->append(" stitch tiles: ");
1429 str->append(fStitchTiles ? "true " : "false "); 1429 str->append(fStitchTiles ? "true " : "false ");
1430 1430
1431 this->INHERITED::toString(str); 1431 this->INHERITED::toString(str);
1432 1432
1433 str->append(")"); 1433 str->append(")");
1434 } 1434 }
1435 #endif 1435 #endif
OLDNEW
« no previous file with comments | « no previous file | gyp/SampleApp.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698