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

Side by Side Diff: src/effects/SkPerlinNoiseShader.cpp

Issue 491673002: Initial refactor of shaderbuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 6 years, 4 months 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
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 "SkPerlinNoiseShader.h" 9 #include "SkPerlinNoiseShader.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkWriteBuffer.h" 12 #include "SkWriteBuffer.h"
13 #include "SkShader.h" 13 #include "SkShader.h"
14 #include "SkUnPreMultiply.h" 14 #include "SkUnPreMultiply.h"
15 #include "SkString.h" 15 #include "SkString.h"
16 16
17 #if SK_SUPPORT_GPU 17 #if SK_SUPPORT_GPU
18 #include "GrContext.h" 18 #include "GrContext.h"
19 #include "GrCoordTransform.h" 19 #include "GrCoordTransform.h"
20 #include "gl/GrGLEffect.h" 20 #include "gl/GrGLEffect.h"
21 #include "gl/GrGLShaderBuilder.h" 21 #include "gl/builders/GrGLProgramBuilder.h"
22 #include "GrTBackendEffectFactory.h" 22 #include "GrTBackendEffectFactory.h"
23 #include "SkGr.h" 23 #include "SkGr.h"
24 #endif 24 #endif
25 25
26 static const int kBlockSize = 256; 26 static const int kBlockSize = 256;
27 static const int kBlockMask = kBlockSize - 1; 27 static const int kBlockMask = kBlockSize - 1;
28 static const int kPerlinNoise = 4096; 28 static const int kPerlinNoise = 4096;
29 static const int kRandMaximum = SK_MaxS32; // 2**31 - 1 29 static const int kRandMaximum = SK_MaxS32; // 2**31 - 1
30 30
31 namespace { 31 namespace {
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 #if SK_SUPPORT_GPU 490 #if SK_SUPPORT_GPU
491 491
492 #include "GrTBackendEffectFactory.h" 492 #include "GrTBackendEffectFactory.h"
493 493
494 class GrGLPerlinNoise : public GrGLEffect { 494 class GrGLPerlinNoise : public GrGLEffect {
495 public: 495 public:
496 GrGLPerlinNoise(const GrBackendEffectFactory& factory, 496 GrGLPerlinNoise(const GrBackendEffectFactory& factory,
497 const GrDrawEffect& drawEffect); 497 const GrDrawEffect& drawEffect);
498 virtual ~GrGLPerlinNoise() {} 498 virtual ~GrGLPerlinNoise() {}
499 499
500 virtual void emitCode(GrGLShaderBuilder*, 500 virtual void emitCode(GrGLProgramBuilder*,
501 const GrDrawEffect&, 501 const GrDrawEffect&,
502 const GrEffectKey&, 502 const GrEffectKey&,
503 const char* outputColor, 503 const char* outputColor,
504 const char* inputColor, 504 const char* inputColor,
505 const TransformedCoordsArray&, 505 const TransformedCoordsArray&,
506 const TextureSamplerArray&) SK_OVERRIDE; 506 const TextureSamplerArray&) SK_OVERRIDE;
507 507
508 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_ OVERRIDE; 508 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_ OVERRIDE;
509 509
510 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB uilder* b); 510 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB uilder* b);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 return effect; 638 return effect;
639 } 639 }
640 640
641 GrGLPerlinNoise::GrGLPerlinNoise(const GrBackendEffectFactory& factory, const Gr DrawEffect& drawEffect) 641 GrGLPerlinNoise::GrGLPerlinNoise(const GrBackendEffectFactory& factory, const Gr DrawEffect& drawEffect)
642 : INHERITED (factory) 642 : INHERITED (factory)
643 , fType(drawEffect.castEffect<GrPerlinNoiseEffect>().type()) 643 , fType(drawEffect.castEffect<GrPerlinNoiseEffect>().type())
644 , fStitchTiles(drawEffect.castEffect<GrPerlinNoiseEffect>().stitchTiles()) 644 , fStitchTiles(drawEffect.castEffect<GrPerlinNoiseEffect>().stitchTiles())
645 , fNumOctaves(drawEffect.castEffect<GrPerlinNoiseEffect>().numOctaves()) { 645 , fNumOctaves(drawEffect.castEffect<GrPerlinNoiseEffect>().numOctaves()) {
646 } 646 }
647 647
648 void GrGLPerlinNoise::emitCode(GrGLShaderBuilder* builder, 648 void GrGLPerlinNoise::emitCode(GrGLProgramBuilder* builder,
649 const GrDrawEffect&, 649 const GrDrawEffect&,
650 const GrEffectKey& key, 650 const GrEffectKey& key,
651 const char* outputColor, 651 const char* outputColor,
652 const char* inputColor, 652 const char* inputColor,
653 const TransformedCoordsArray& coords, 653 const TransformedCoordsArray& coords,
654 const TextureSamplerArray& samplers) { 654 const TextureSamplerArray& samplers) {
655 sk_ignore_unused_variable(inputColor); 655 sk_ignore_unused_variable(inputColor);
656 656
657 SkString vCoords = builder->ensureFSCoords2D(coords, 0); 657 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
658 SkString vCoords = fsBuilder->ensureFSCoords2D(coords, 0);
658 659
659 fBaseFrequencyUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibil ity, 660 fBaseFrequencyUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi lity,
660 kVec2f_GrSLType, "baseFrequency"); 661 kVec2f_GrSLType, "baseFrequency");
661 const char* baseFrequencyUni = builder->getUniformCStr(fBaseFrequencyUni); 662 const char* baseFrequencyUni = builder->getUniformCStr(fBaseFrequencyUni);
662 fAlphaUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, 663 fAlphaUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
663 kFloat_GrSLType, "alpha"); 664 kFloat_GrSLType, "alpha");
664 const char* alphaUni = builder->getUniformCStr(fAlphaUni); 665 const char* alphaUni = builder->getUniformCStr(fAlphaUni);
665 666
666 const char* stitchDataUni = NULL; 667 const char* stitchDataUni = NULL;
667 if (fStitchTiles) { 668 if (fStitchTiles) {
668 fStitchDataUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi lity, 669 fStitchDataUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib ility,
669 kVec2f_GrSLType, "stitchData"); 670 kVec2f_GrSLType, "stitchData");
670 stitchDataUni = builder->getUniformCStr(fStitchDataUni); 671 stitchDataUni = builder->getUniformCStr(fStitchDataUni);
671 } 672 }
672 673
673 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8 674 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8
674 const char* chanCoordR = "0.125"; 675 const char* chanCoordR = "0.125";
675 const char* chanCoordG = "0.375"; 676 const char* chanCoordG = "0.375";
676 const char* chanCoordB = "0.625"; 677 const char* chanCoordB = "0.625";
677 const char* chanCoordA = "0.875"; 678 const char* chanCoordA = "0.875";
678 const char* chanCoord = "chanCoord"; 679 const char* chanCoord = "chanCoord";
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 // Get texture coordinates and normalize 731 // Get texture coordinates and normalize
731 noiseCode.appendf("\n\t%s = fract(floor(mod(%s, 256.0)) / vec4(256.0));\n", 732 noiseCode.appendf("\n\t%s = fract(floor(mod(%s, 256.0)) / vec4(256.0));\n",
732 floorVal, floorVal); 733 floorVal, floorVal);
733 734
734 // Get permutation for x 735 // Get permutation for x
735 { 736 {
736 SkString xCoords(""); 737 SkString xCoords("");
737 xCoords.appendf("vec2(%s.x, 0.5)", floorVal); 738 xCoords.appendf("vec2(%s.x, 0.5)", floorVal);
738 739
739 noiseCode.appendf("\n\tvec2 %s;\n\t%s.x = ", latticeIdx, latticeIdx); 740 noiseCode.appendf("\n\tvec2 %s;\n\t%s.x = ", latticeIdx, latticeIdx);
740 builder->appendTextureLookup(&noiseCode, samplers[0], xCoords.c_str(), k Vec2f_GrSLType); 741 fsBuilder->appendTextureLookup(&noiseCode, samplers[0], xCoords.c_str(), kVec2f_GrSLType);
741 noiseCode.append(".r;"); 742 noiseCode.append(".r;");
742 } 743 }
743 744
744 // Get permutation for x + 1 745 // Get permutation for x + 1
745 { 746 {
746 SkString xCoords(""); 747 SkString xCoords("");
747 xCoords.appendf("vec2(%s.z, 0.5)", floorVal); 748 xCoords.appendf("vec2(%s.z, 0.5)", floorVal);
748 749
749 noiseCode.appendf("\n\t%s.y = ", latticeIdx); 750 noiseCode.appendf("\n\t%s.y = ", latticeIdx);
750 builder->appendTextureLookup(&noiseCode, samplers[0], xCoords.c_str(), k Vec2f_GrSLType); 751 fsBuilder->appendTextureLookup(&noiseCode, samplers[0], xCoords.c_str(), kVec2f_GrSLType);
751 noiseCode.append(".r;"); 752 noiseCode.append(".r;");
752 } 753 }
753 754
754 #if defined(SK_BUILD_FOR_ANDROID) 755 #if defined(SK_BUILD_FOR_ANDROID)
755 // Android rounding for Tegra devices, like, for example: Xoom (Tegra 2), Ne xus 7 (Tegra 3). 756 // Android rounding for Tegra devices, like, for example: Xoom (Tegra 2), Ne xus 7 (Tegra 3).
756 // The issue is that colors aren't accurate enough on Tegra devices. For exa mple, if an 8 bit 757 // The issue is that colors aren't accurate enough on Tegra devices. For exa mple, if an 8 bit
757 // value of 124 (or 0.486275 here) is entered, we can get a texture value of 123.513725 758 // value of 124 (or 0.486275 here) is entered, we can get a texture value of 123.513725
758 // (or 0.484368 here). The following rounding operation prevents these preci sion issues from 759 // (or 0.484368 here). The following rounding operation prevents these preci sion issues from
759 // affecting the result of the noise by making sure that we only have multip les of 1/255. 760 // affecting the result of the noise by making sure that we only have multip les of 1/255.
760 // (Note that 1/255 is about 0.003921569, which is the value used here). 761 // (Note that 1/255 is about 0.003921569, which is the value used here).
761 noiseCode.appendf("\n\t%s = floor(%s * vec2(255.0) + vec2(0.5)) * vec2(0.003 921569);", 762 noiseCode.appendf("\n\t%s = floor(%s * vec2(255.0) + vec2(0.5)) * vec2(0.003 921569);",
762 latticeIdx, latticeIdx); 763 latticeIdx, latticeIdx);
763 #endif 764 #endif
764 765
765 // Get (x,y) coordinates with the permutated x 766 // Get (x,y) coordinates with the permutated x
766 noiseCode.appendf("\n\tvec4 %s = fract(%s.xyxy + %s.yyww);", bcoords, lattic eIdx, floorVal); 767 noiseCode.appendf("\n\tvec4 %s = fract(%s.xyxy + %s.yyww);", bcoords, lattic eIdx, floorVal);
767 768
768 noiseCode.appendf("\n\n\tvec2 %s;", uv); 769 noiseCode.appendf("\n\n\tvec2 %s;", uv);
769 // Compute u, at offset (0,0) 770 // Compute u, at offset (0,0)
770 { 771 {
771 SkString latticeCoords(""); 772 SkString latticeCoords("");
772 latticeCoords.appendf("vec2(%s.x, %s)", bcoords, chanCoord); 773 latticeCoords.appendf("vec2(%s.x, %s)", bcoords, chanCoord);
773 noiseCode.appendf("\n\tvec4 %s = ", lattice); 774 noiseCode.appendf("\n\tvec4 %s = ", lattice);
774 builder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_st r(), 775 fsBuilder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_ str(),
775 kVec2f_GrSLType); 776 kVec2f_GrSLType);
776 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); 777 noiseCode.appendf(".bgra;\n\t%s.x = ", uv);
777 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); 778 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
778 } 779 }
779 780
780 noiseCode.appendf("\n\t%s.x -= 1.0;", fractVal); 781 noiseCode.appendf("\n\t%s.x -= 1.0;", fractVal);
781 // Compute v, at offset (-1,0) 782 // Compute v, at offset (-1,0)
782 { 783 {
783 SkString latticeCoords(""); 784 SkString latticeCoords("");
784 latticeCoords.appendf("vec2(%s.y, %s)", bcoords, chanCoord); 785 latticeCoords.appendf("vec2(%s.y, %s)", bcoords, chanCoord);
785 noiseCode.append("\n\tlattice = "); 786 noiseCode.append("\n\tlattice = ");
786 builder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_st r(), 787 fsBuilder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_ str(),
787 kVec2f_GrSLType); 788 kVec2f_GrSLType);
788 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); 789 noiseCode.appendf(".bgra;\n\t%s.y = ", uv);
789 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); 790 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
790 } 791 }
791 792
792 // Compute 'a' as a linear interpolation of 'u' and 'v' 793 // Compute 'a' as a linear interpolation of 'u' and 'v'
793 noiseCode.appendf("\n\tvec2 %s;", ab); 794 noiseCode.appendf("\n\tvec2 %s;", ab);
794 noiseCode.appendf("\n\t%s.x = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th); 795 noiseCode.appendf("\n\t%s.x = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th);
795 796
796 noiseCode.appendf("\n\t%s.y -= 1.0;", fractVal); 797 noiseCode.appendf("\n\t%s.y -= 1.0;", fractVal);
797 // Compute v, at offset (-1,-1) 798 // Compute v, at offset (-1,-1)
798 { 799 {
799 SkString latticeCoords(""); 800 SkString latticeCoords("");
800 latticeCoords.appendf("vec2(%s.w, %s)", bcoords, chanCoord); 801 latticeCoords.appendf("vec2(%s.w, %s)", bcoords, chanCoord);
801 noiseCode.append("\n\tlattice = "); 802 noiseCode.append("\n\tlattice = ");
802 builder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_st r(), 803 fsBuilder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_ str(),
803 kVec2f_GrSLType); 804 kVec2f_GrSLType);
804 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); 805 noiseCode.appendf(".bgra;\n\t%s.y = ", uv);
805 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); 806 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
806 } 807 }
807 808
808 noiseCode.appendf("\n\t%s.x += 1.0;", fractVal); 809 noiseCode.appendf("\n\t%s.x += 1.0;", fractVal);
809 // Compute u, at offset (0,-1) 810 // Compute u, at offset (0,-1)
810 { 811 {
811 SkString latticeCoords(""); 812 SkString latticeCoords("");
812 latticeCoords.appendf("vec2(%s.z, %s)", bcoords, chanCoord); 813 latticeCoords.appendf("vec2(%s.z, %s)", bcoords, chanCoord);
813 noiseCode.append("\n\tlattice = "); 814 noiseCode.append("\n\tlattice = ");
814 builder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_st r(), 815 fsBuilder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_ str(),
815 kVec2f_GrSLType); 816 kVec2f_GrSLType);
816 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); 817 noiseCode.appendf(".bgra;\n\t%s.x = ", uv);
817 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); 818 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
818 } 819 }
819 820
820 // Compute 'b' as a linear interpolation of 'u' and 'v' 821 // Compute 'b' as a linear interpolation of 'u' and 'v'
821 noiseCode.appendf("\n\t%s.y = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th); 822 noiseCode.appendf("\n\t%s.y = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th);
822 // Compute the noise as a linear interpolation of 'a' and 'b' 823 // Compute the noise as a linear interpolation of 'a' and 'b'
823 noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth ); 824 noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth );
824 825
825 SkString noiseFuncName; 826 SkString noiseFuncName;
826 if (fStitchTiles) { 827 if (fStitchTiles) {
827 builder->fsEmitFunction(kFloat_GrSLType, 828 fsBuilder->emitFunction(kFloat_GrSLType,
828 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitch Args), 829 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitch Args),
829 gPerlinNoiseStitchArgs, noiseCode.c_str(), &nois eFuncName); 830 gPerlinNoiseStitchArgs, noiseCode.c_str(), &nois eFuncName);
830 } else { 831 } else {
831 builder->fsEmitFunction(kFloat_GrSLType, 832 fsBuilder->emitFunction(kFloat_GrSLType,
832 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs), 833 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs),
833 gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncN ame); 834 gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncN ame);
834 } 835 }
835 836
836 // There are rounding errors if the floor operation is not performed here 837 // There are rounding errors if the floor operation is not performed here
837 builder->fsCodeAppendf("\n\t\tvec2 %s = floor(%s.xy) * %s;", 838 fsBuilder->codeAppendf("\n\t\tvec2 %s = floor(%s.xy) * %s;",
838 noiseVec, vCoords.c_str(), baseFrequencyUni); 839 noiseVec, vCoords.c_str(), baseFrequencyUni);
839 840
840 // Clear the color accumulator 841 // Clear the color accumulator
841 builder->fsCodeAppendf("\n\t\t%s = vec4(0.0);", outputColor); 842 fsBuilder->codeAppendf("\n\t\t%s = vec4(0.0);", outputColor);
842 843
843 if (fStitchTiles) { 844 if (fStitchTiles) {
844 // Set up TurbulenceInitial stitch values. 845 // Set up TurbulenceInitial stitch values.
845 builder->fsCodeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni) ; 846 fsBuilder->codeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni) ;
846 } 847 }
847 848
848 builder->fsCodeAppendf("\n\t\tfloat %s = 1.0;", ratio); 849 fsBuilder->codeAppendf("\n\t\tfloat %s = 1.0;", ratio);
849 850
850 // Loop over all octaves 851 // Loop over all octaves
851 builder->fsCodeAppendf("\n\t\tfor (int octave = 0; octave < %d; ++octave) {" , fNumOctaves); 852 fsBuilder->codeAppendf("\n\t\tfor (int octave = 0; octave < %d; ++octave) {" , fNumOctaves);
852 853
853 builder->fsCodeAppendf("\n\t\t\t%s += ", outputColor); 854 fsBuilder->codeAppendf("\n\t\t\t%s += ", outputColor);
854 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) { 855 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) {
855 builder->fsCodeAppend("abs("); 856 fsBuilder->codeAppend("abs(");
856 } 857 }
857 if (fStitchTiles) { 858 if (fStitchTiles) {
858 builder->fsCodeAppendf( 859 fsBuilder->codeAppendf(
859 "vec4(\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s)," 860 "vec4(\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s),"
860 "\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s))", 861 "\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s))",
861 noiseFuncName.c_str(), chanCoordR, noiseVec, stitchData, 862 noiseFuncName.c_str(), chanCoordR, noiseVec, stitchData,
862 noiseFuncName.c_str(), chanCoordG, noiseVec, stitchData, 863 noiseFuncName.c_str(), chanCoordG, noiseVec, stitchData,
863 noiseFuncName.c_str(), chanCoordB, noiseVec, stitchData, 864 noiseFuncName.c_str(), chanCoordB, noiseVec, stitchData,
864 noiseFuncName.c_str(), chanCoordA, noiseVec, stitchData); 865 noiseFuncName.c_str(), chanCoordA, noiseVec, stitchData);
865 } else { 866 } else {
866 builder->fsCodeAppendf( 867 fsBuilder->codeAppendf(
867 "vec4(\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s)," 868 "vec4(\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s),"
868 "\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s))", 869 "\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s))",
869 noiseFuncName.c_str(), chanCoordR, noiseVec, 870 noiseFuncName.c_str(), chanCoordR, noiseVec,
870 noiseFuncName.c_str(), chanCoordG, noiseVec, 871 noiseFuncName.c_str(), chanCoordG, noiseVec,
871 noiseFuncName.c_str(), chanCoordB, noiseVec, 872 noiseFuncName.c_str(), chanCoordB, noiseVec,
872 noiseFuncName.c_str(), chanCoordA, noiseVec); 873 noiseFuncName.c_str(), chanCoordA, noiseVec);
873 } 874 }
874 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) { 875 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) {
875 builder->fsCodeAppendf(")"); // end of "abs(" 876 fsBuilder->codeAppendf(")"); // end of "abs("
876 } 877 }
877 builder->fsCodeAppendf(" * %s;", ratio); 878 fsBuilder->codeAppendf(" * %s;", ratio);
878 879
879 builder->fsCodeAppendf("\n\t\t\t%s *= vec2(2.0);", noiseVec); 880 fsBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", noiseVec);
880 builder->fsCodeAppendf("\n\t\t\t%s *= 0.5;", ratio); 881 fsBuilder->codeAppendf("\n\t\t\t%s *= 0.5;", ratio);
881 882
882 if (fStitchTiles) { 883 if (fStitchTiles) {
883 builder->fsCodeAppendf("\n\t\t\t%s *= vec2(2.0);", stitchData); 884 fsBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", stitchData);
884 } 885 }
885 builder->fsCodeAppend("\n\t\t}"); // end of the for loop on octaves 886 fsBuilder->codeAppend("\n\t\t}"); // end of the for loop on octaves
886 887
887 if (fType == SkPerlinNoiseShader::kFractalNoise_Type) { 888 if (fType == SkPerlinNoiseShader::kFractalNoise_Type) {
888 // The value of turbulenceFunctionResult comes from ((turbulenceFunction Result) + 1) / 2 889 // The value of turbulenceFunctionResult comes from ((turbulenceFunction Result) + 1) / 2
889 // by fractalNoise and (turbulenceFunctionResult) by turbulence. 890 // by fractalNoise and (turbulenceFunctionResult) by turbulence.
890 builder->fsCodeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);", outputC olor, outputColor); 891 fsBuilder->codeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);", outputC olor, outputColor);
891 } 892 }
892 893
893 builder->fsCodeAppendf("\n\t\t%s.a *= %s;", outputColor, alphaUni); 894 fsBuilder->codeAppendf("\n\t\t%s.a *= %s;", outputColor, alphaUni);
894 895
895 // Clamp values 896 // Clamp values
896 builder->fsCodeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", outputColor, outpu tColor); 897 fsBuilder->codeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", outputColor, outpu tColor);
897 898
898 // Pre-multiply the result 899 // Pre-multiply the result
899 builder->fsCodeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n", 900 fsBuilder->codeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n",
900 outputColor, outputColor, outputColor, outputColor); 901 outputColor, outputColor, outputColor, outputColor);
901 } 902 }
902 903
903 void GrGLPerlinNoise::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, Gr EffectKeyBuilder* b) { 904 void GrGLPerlinNoise::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, Gr EffectKeyBuilder* b) {
904 const GrPerlinNoiseEffect& turbulence = drawEffect.castEffect<GrPerlinNoiseE ffect>(); 905 const GrPerlinNoiseEffect& turbulence = drawEffect.castEffect<GrPerlinNoiseE ffect>();
905 906
906 uint32_t key = turbulence.numOctaves(); 907 uint32_t key = turbulence.numOctaves();
907 908
908 key = key << 3; // Make room for next 3 bits 909 key = key << 3; // Make room for next 3 bits
909 910
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 str->append(" seed: "); 1044 str->append(" seed: ");
1044 str->appendScalar(fSeed); 1045 str->appendScalar(fSeed);
1045 str->append(" stitch tiles: "); 1046 str->append(" stitch tiles: ");
1046 str->append(fStitchTiles ? "true " : "false "); 1047 str->append(fStitchTiles ? "true " : "false ");
1047 1048
1048 this->INHERITED::toString(str); 1049 this->INHERITED::toString(str);
1049 1050
1050 str->append(")"); 1051 str->append(")");
1051 } 1052 }
1052 #endif 1053 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698