Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 | 480 |
| 481 ///////////////////////////////////////////////////////////////////// | 481 ///////////////////////////////////////////////////////////////////// |
| 482 | 482 |
| 483 #if SK_SUPPORT_GPU | 483 #if SK_SUPPORT_GPU |
| 484 | 484 |
| 485 class GrGLPerlinNoise : public GrGLFragmentProcessor { | 485 class GrGLPerlinNoise : public GrGLFragmentProcessor { |
| 486 public: | 486 public: |
| 487 GrGLPerlinNoise(const GrProcessor&); | 487 GrGLPerlinNoise(const GrProcessor&); |
| 488 virtual ~GrGLPerlinNoise() {} | 488 virtual ~GrGLPerlinNoise() {} |
| 489 | 489 |
| 490 virtual void emitCode(GrGLFPBuilder*, | 490 virtual void emitCode(EmitArgs&) override; |
| 491 const GrFragmentProcessor&, | |
| 492 const char* outputColor, | |
| 493 const char* inputColor, | |
| 494 const TransformedCoordsArray&, | |
| 495 const TextureSamplerArray&) override; | |
| 496 | 491 |
| 497 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 492 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; |
| 498 | 493 |
| 499 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder* b); | 494 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor KeyBuilder* b); |
| 500 | 495 |
| 501 private: | 496 private: |
| 502 | 497 |
| 503 GrGLProgramDataManager::UniformHandle fStitchDataUni; | 498 GrGLProgramDataManager::UniformHandle fStitchDataUni; |
| 504 SkPerlinNoiseShader::Type fType; | 499 SkPerlinNoiseShader::Type fType; |
| 505 bool fStitchTiles; | 500 bool fStitchTiles; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 | 627 |
| 633 return effect; | 628 return effect; |
| 634 } | 629 } |
| 635 | 630 |
| 636 GrGLPerlinNoise::GrGLPerlinNoise(const GrProcessor& processor) | 631 GrGLPerlinNoise::GrGLPerlinNoise(const GrProcessor& processor) |
| 637 : fType(processor.cast<GrPerlinNoiseEffect>().type()) | 632 : fType(processor.cast<GrPerlinNoiseEffect>().type()) |
| 638 , fStitchTiles(processor.cast<GrPerlinNoiseEffect>().stitchTiles()) | 633 , fStitchTiles(processor.cast<GrPerlinNoiseEffect>().stitchTiles()) |
| 639 , fNumOctaves(processor.cast<GrPerlinNoiseEffect>().numOctaves()) { | 634 , fNumOctaves(processor.cast<GrPerlinNoiseEffect>().numOctaves()) { |
| 640 } | 635 } |
| 641 | 636 |
| 642 void GrGLPerlinNoise::emitCode(GrGLFPBuilder* builder, | 637 void GrGLPerlinNoise::emitCode(EmitArgs& args) { |
| 643 const GrFragmentProcessor&, | 638 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); |
| 644 const char* outputColor, | 639 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 645 const char* inputColor, | |
| 646 const TransformedCoordsArray& coords, | |
| 647 const TextureSamplerArray& samplers) { | |
| 648 sk_ignore_unused_variable(inputColor); | |
| 649 | 640 |
| 650 GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 641 fBaseFrequencyUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_ Visibility, |
| 651 SkString vCoords = fsBuilder->ensureFSCoords2D(coords, 0); | |
| 652 | |
| 653 fBaseFrequencyUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi lity, | |
| 654 kVec2f_GrSLType, kDefault_GrSLPrecis ion, | 642 kVec2f_GrSLType, kDefault_GrSLPrecis ion, |
| 655 "baseFrequency"); | 643 "baseFrequency"); |
| 656 const char* baseFrequencyUni = builder->getUniformCStr(fBaseFrequencyUni); | 644 const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyU ni); |
| 657 fAlphaUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 645 fAlphaUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili ty, |
| 658 kFloat_GrSLType, kDefault_GrSLPrecision, | 646 kFloat_GrSLType, kDefault_GrSLPrecision, |
| 659 "alpha"); | 647 "alpha"); |
| 660 const char* alphaUni = builder->getUniformCStr(fAlphaUni); | 648 const char* alphaUni = args.fBuilder->getUniformCStr(fAlphaUni); |
| 661 | 649 |
| 662 const char* stitchDataUni = NULL; | 650 const char* stitchDataUni = NULL; |
| 663 if (fStitchTiles) { | 651 if (fStitchTiles) { |
| 664 fStitchDataUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib ility, | 652 fStitchDataUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment _Visibility, |
| 665 kVec2f_GrSLType, kDefault_GrSLPreci sion, | 653 kVec2f_GrSLType, kDefault_GrSLPreci sion, |
| 666 "stitchData"); | 654 "stitchData"); |
| 667 stitchDataUni = builder->getUniformCStr(fStitchDataUni); | 655 stitchDataUni = args.fBuilder->getUniformCStr(fStitchDataUni); |
| 668 } | 656 } |
| 669 | 657 |
| 670 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8 | 658 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8 |
| 671 const char* chanCoordR = "0.125"; | 659 const char* chanCoordR = "0.125"; |
| 672 const char* chanCoordG = "0.375"; | 660 const char* chanCoordG = "0.375"; |
| 673 const char* chanCoordB = "0.625"; | 661 const char* chanCoordB = "0.625"; |
| 674 const char* chanCoordA = "0.875"; | 662 const char* chanCoordA = "0.875"; |
| 675 const char* chanCoord = "chanCoord"; | 663 const char* chanCoord = "chanCoord"; |
| 676 const char* stitchData = "stitchData"; | 664 const char* stitchData = "stitchData"; |
| 677 const char* ratio = "ratio"; | 665 const char* ratio = "ratio"; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 // Get texture coordinates and normalize | 715 // Get texture coordinates and normalize |
| 728 noiseCode.appendf("\n\t%s = fract(floor(mod(%s, 256.0)) / vec4(256.0));\n", | 716 noiseCode.appendf("\n\t%s = fract(floor(mod(%s, 256.0)) / vec4(256.0));\n", |
| 729 floorVal, floorVal); | 717 floorVal, floorVal); |
| 730 | 718 |
| 731 // Get permutation for x | 719 // Get permutation for x |
| 732 { | 720 { |
| 733 SkString xCoords(""); | 721 SkString xCoords(""); |
| 734 xCoords.appendf("vec2(%s.x, 0.5)", floorVal); | 722 xCoords.appendf("vec2(%s.x, 0.5)", floorVal); |
| 735 | 723 |
| 736 noiseCode.appendf("\n\tvec2 %s;\n\t%s.x = ", latticeIdx, latticeIdx); | 724 noiseCode.appendf("\n\tvec2 %s;\n\t%s.x = ", latticeIdx, latticeIdx); |
| 737 fsBuilder->appendTextureLookup(&noiseCode, samplers[0], xCoords.c_str(), kVec2f_GrSLType); | 725 fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[0], xCoords.c_ str(), kVec2f_GrSLType); |
|
joshualitt
2015/07/22 19:34:05
line wrap @100
| |
| 738 noiseCode.append(".r;"); | 726 noiseCode.append(".r;"); |
| 739 } | 727 } |
| 740 | 728 |
| 741 // Get permutation for x + 1 | 729 // Get permutation for x + 1 |
| 742 { | 730 { |
| 743 SkString xCoords(""); | 731 SkString xCoords(""); |
| 744 xCoords.appendf("vec2(%s.z, 0.5)", floorVal); | 732 xCoords.appendf("vec2(%s.z, 0.5)", floorVal); |
| 745 | 733 |
| 746 noiseCode.appendf("\n\t%s.y = ", latticeIdx); | 734 noiseCode.appendf("\n\t%s.y = ", latticeIdx); |
| 747 fsBuilder->appendTextureLookup(&noiseCode, samplers[0], xCoords.c_str(), kVec2f_GrSLType); | 735 fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[0], xCoords.c_ str(), kVec2f_GrSLType); |
|
joshualitt
2015/07/22 19:34:05
line wrap @100
| |
| 748 noiseCode.append(".r;"); | 736 noiseCode.append(".r;"); |
| 749 } | 737 } |
| 750 | 738 |
| 751 #if defined(SK_BUILD_FOR_ANDROID) | 739 #if defined(SK_BUILD_FOR_ANDROID) |
| 752 // Android rounding for Tegra devices, like, for example: Xoom (Tegra 2), Ne xus 7 (Tegra 3). | 740 // Android rounding for Tegra devices, like, for example: Xoom (Tegra 2), Ne xus 7 (Tegra 3). |
| 753 // The issue is that colors aren't accurate enough on Tegra devices. For exa mple, if an 8 bit | 741 // The issue is that colors aren't accurate enough on Tegra devices. For exa mple, if an 8 bit |
| 754 // value of 124 (or 0.486275 here) is entered, we can get a texture value of 123.513725 | 742 // value of 124 (or 0.486275 here) is entered, we can get a texture value of 123.513725 |
| 755 // (or 0.484368 here). The following rounding operation prevents these preci sion issues from | 743 // (or 0.484368 here). The following rounding operation prevents these preci sion issues from |
| 756 // affecting the result of the noise by making sure that we only have multip les of 1/255. | 744 // affecting the result of the noise by making sure that we only have multip les of 1/255. |
| 757 // (Note that 1/255 is about 0.003921569, which is the value used here). | 745 // (Note that 1/255 is about 0.003921569, which is the value used here). |
| 758 noiseCode.appendf("\n\t%s = floor(%s * vec2(255.0) + vec2(0.5)) * vec2(0.003 921569);", | 746 noiseCode.appendf("\n\t%s = floor(%s * vec2(255.0) + vec2(0.5)) * vec2(0.003 921569);", |
| 759 latticeIdx, latticeIdx); | 747 latticeIdx, latticeIdx); |
| 760 #endif | 748 #endif |
| 761 | 749 |
| 762 // Get (x,y) coordinates with the permutated x | 750 // Get (x,y) coordinates with the permutated x |
| 763 noiseCode.appendf("\n\tvec4 %s = fract(%s.xyxy + %s.yyww);", bcoords, lattic eIdx, floorVal); | 751 noiseCode.appendf("\n\tvec4 %s = fract(%s.xyxy + %s.yyww);", bcoords, lattic eIdx, floorVal); |
| 764 | 752 |
| 765 noiseCode.appendf("\n\n\tvec2 %s;", uv); | 753 noiseCode.appendf("\n\n\tvec2 %s;", uv); |
| 766 // Compute u, at offset (0,0) | 754 // Compute u, at offset (0,0) |
| 767 { | 755 { |
| 768 SkString latticeCoords(""); | 756 SkString latticeCoords(""); |
| 769 latticeCoords.appendf("vec2(%s.x, %s)", bcoords, chanCoord); | 757 latticeCoords.appendf("vec2(%s.x, %s)", bcoords, chanCoord); |
| 770 noiseCode.appendf("\n\tvec4 %s = ", lattice); | 758 noiseCode.appendf("\n\tvec4 %s = ", lattice); |
| 771 fsBuilder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_ str(), | 759 fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoo rds.c_str(), |
| 772 kVec2f_GrSLType); | 760 kVec2f_GrSLType); |
| 773 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); | 761 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); |
| 774 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); | 762 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); |
| 775 } | 763 } |
| 776 | 764 |
| 777 noiseCode.appendf("\n\t%s.x -= 1.0;", fractVal); | 765 noiseCode.appendf("\n\t%s.x -= 1.0;", fractVal); |
| 778 // Compute v, at offset (-1,0) | 766 // Compute v, at offset (-1,0) |
| 779 { | 767 { |
| 780 SkString latticeCoords(""); | 768 SkString latticeCoords(""); |
| 781 latticeCoords.appendf("vec2(%s.y, %s)", bcoords, chanCoord); | 769 latticeCoords.appendf("vec2(%s.y, %s)", bcoords, chanCoord); |
| 782 noiseCode.append("\n\tlattice = "); | 770 noiseCode.append("\n\tlattice = "); |
| 783 fsBuilder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_ str(), | 771 fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoo rds.c_str(), |
| 784 kVec2f_GrSLType); | 772 kVec2f_GrSLType); |
| 785 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); | 773 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); |
| 786 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); | 774 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); |
| 787 } | 775 } |
| 788 | 776 |
| 789 // Compute 'a' as a linear interpolation of 'u' and 'v' | 777 // Compute 'a' as a linear interpolation of 'u' and 'v' |
| 790 noiseCode.appendf("\n\tvec2 %s;", ab); | 778 noiseCode.appendf("\n\tvec2 %s;", ab); |
| 791 noiseCode.appendf("\n\t%s.x = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th); | 779 noiseCode.appendf("\n\t%s.x = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th); |
| 792 | 780 |
| 793 noiseCode.appendf("\n\t%s.y -= 1.0;", fractVal); | 781 noiseCode.appendf("\n\t%s.y -= 1.0;", fractVal); |
| 794 // Compute v, at offset (-1,-1) | 782 // Compute v, at offset (-1,-1) |
| 795 { | 783 { |
| 796 SkString latticeCoords(""); | 784 SkString latticeCoords(""); |
| 797 latticeCoords.appendf("vec2(%s.w, %s)", bcoords, chanCoord); | 785 latticeCoords.appendf("vec2(%s.w, %s)", bcoords, chanCoord); |
| 798 noiseCode.append("\n\tlattice = "); | 786 noiseCode.append("\n\tlattice = "); |
| 799 fsBuilder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_ str(), | 787 fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoo rds.c_str(), |
| 800 kVec2f_GrSLType); | 788 kVec2f_GrSLType); |
| 801 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); | 789 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); |
| 802 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); | 790 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); |
| 803 } | 791 } |
| 804 | 792 |
| 805 noiseCode.appendf("\n\t%s.x += 1.0;", fractVal); | 793 noiseCode.appendf("\n\t%s.x += 1.0;", fractVal); |
| 806 // Compute u, at offset (0,-1) | 794 // Compute u, at offset (0,-1) |
| 807 { | 795 { |
| 808 SkString latticeCoords(""); | 796 SkString latticeCoords(""); |
| 809 latticeCoords.appendf("vec2(%s.z, %s)", bcoords, chanCoord); | 797 latticeCoords.appendf("vec2(%s.z, %s)", bcoords, chanCoord); |
| 810 noiseCode.append("\n\tlattice = "); | 798 noiseCode.append("\n\tlattice = "); |
| 811 fsBuilder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_ str(), | 799 fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoo rds.c_str(), |
| 812 kVec2f_GrSLType); | 800 kVec2f_GrSLType); |
| 813 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); | 801 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); |
| 814 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); | 802 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); |
| 815 } | 803 } |
| 816 | 804 |
| 817 // Compute 'b' as a linear interpolation of 'u' and 'v' | 805 // Compute 'b' as a linear interpolation of 'u' and 'v' |
| 818 noiseCode.appendf("\n\t%s.y = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th); | 806 noiseCode.appendf("\n\t%s.y = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th); |
| 819 // Compute the noise as a linear interpolation of 'a' and 'b' | 807 // Compute the noise as a linear interpolation of 'a' and 'b' |
| 820 noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth ); | 808 noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth ); |
| 821 | 809 |
| 822 SkString noiseFuncName; | 810 SkString noiseFuncName; |
| 823 if (fStitchTiles) { | 811 if (fStitchTiles) { |
| 824 fsBuilder->emitFunction(kFloat_GrSLType, | 812 fsBuilder->emitFunction(kFloat_GrSLType, |
| 825 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitch Args), | 813 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitch Args), |
| 826 gPerlinNoiseStitchArgs, noiseCode.c_str(), &nois eFuncName); | 814 gPerlinNoiseStitchArgs, noiseCode.c_str(), &nois eFuncName); |
| 827 } else { | 815 } else { |
| 828 fsBuilder->emitFunction(kFloat_GrSLType, | 816 fsBuilder->emitFunction(kFloat_GrSLType, |
| 829 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs), | 817 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs), |
| 830 gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncN ame); | 818 gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncN ame); |
| 831 } | 819 } |
| 832 | 820 |
| 833 // There are rounding errors if the floor operation is not performed here | 821 // There are rounding errors if the floor operation is not performed here |
| 834 fsBuilder->codeAppendf("\n\t\tvec2 %s = floor(%s.xy) * %s;", | 822 fsBuilder->codeAppendf("\n\t\tvec2 %s = floor(%s.xy) * %s;", |
| 835 noiseVec, vCoords.c_str(), baseFrequencyUni); | 823 noiseVec, vCoords.c_str(), baseFrequencyUni); |
| 836 | 824 |
| 837 // Clear the color accumulator | 825 // Clear the color accumulator |
| 838 fsBuilder->codeAppendf("\n\t\t%s = vec4(0.0);", outputColor); | 826 fsBuilder->codeAppendf("\n\t\t%s = vec4(0.0);", args.fOutputColor); |
| 839 | 827 |
| 840 if (fStitchTiles) { | 828 if (fStitchTiles) { |
| 841 // Set up TurbulenceInitial stitch values. | 829 // Set up TurbulenceInitial stitch values. |
| 842 fsBuilder->codeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni) ; | 830 fsBuilder->codeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni) ; |
| 843 } | 831 } |
| 844 | 832 |
| 845 fsBuilder->codeAppendf("\n\t\tfloat %s = 1.0;", ratio); | 833 fsBuilder->codeAppendf("\n\t\tfloat %s = 1.0;", ratio); |
| 846 | 834 |
| 847 // Loop over all octaves | 835 // Loop over all octaves |
| 848 fsBuilder->codeAppendf("\n\t\tfor (int octave = 0; octave < %d; ++octave) {" , fNumOctaves); | 836 fsBuilder->codeAppendf("\n\t\tfor (int octave = 0; octave < %d; ++octave) {" , fNumOctaves); |
| 849 | 837 |
| 850 fsBuilder->codeAppendf("\n\t\t\t%s += ", outputColor); | 838 fsBuilder->codeAppendf("\n\t\t\t%s += ", args.fOutputColor); |
| 851 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) { | 839 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) { |
| 852 fsBuilder->codeAppend("abs("); | 840 fsBuilder->codeAppend("abs("); |
| 853 } | 841 } |
| 854 if (fStitchTiles) { | 842 if (fStitchTiles) { |
| 855 fsBuilder->codeAppendf( | 843 fsBuilder->codeAppendf( |
| 856 "vec4(\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s)," | 844 "vec4(\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s)," |
| 857 "\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s))", | 845 "\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s))", |
| 858 noiseFuncName.c_str(), chanCoordR, noiseVec, stitchData, | 846 noiseFuncName.c_str(), chanCoordR, noiseVec, stitchData, |
| 859 noiseFuncName.c_str(), chanCoordG, noiseVec, stitchData, | 847 noiseFuncName.c_str(), chanCoordG, noiseVec, stitchData, |
| 860 noiseFuncName.c_str(), chanCoordB, noiseVec, stitchData, | 848 noiseFuncName.c_str(), chanCoordB, noiseVec, stitchData, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 877 fsBuilder->codeAppendf("\n\t\t\t%s *= 0.5;", ratio); | 865 fsBuilder->codeAppendf("\n\t\t\t%s *= 0.5;", ratio); |
| 878 | 866 |
| 879 if (fStitchTiles) { | 867 if (fStitchTiles) { |
| 880 fsBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", stitchData); | 868 fsBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", stitchData); |
| 881 } | 869 } |
| 882 fsBuilder->codeAppend("\n\t\t}"); // end of the for loop on octaves | 870 fsBuilder->codeAppend("\n\t\t}"); // end of the for loop on octaves |
| 883 | 871 |
| 884 if (fType == SkPerlinNoiseShader::kFractalNoise_Type) { | 872 if (fType == SkPerlinNoiseShader::kFractalNoise_Type) { |
| 885 // The value of turbulenceFunctionResult comes from ((turbulenceFunction Result) + 1) / 2 | 873 // The value of turbulenceFunctionResult comes from ((turbulenceFunction Result) + 1) / 2 |
| 886 // by fractalNoise and (turbulenceFunctionResult) by turbulence. | 874 // by fractalNoise and (turbulenceFunctionResult) by turbulence. |
| 887 fsBuilder->codeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);", outputC olor, outputColor); | 875 fsBuilder->codeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);", args.fO utputColor, args.fOutputColor); |
|
joshualitt
2015/07/22 19:34:05
line wrap @100
| |
| 888 } | 876 } |
| 889 | 877 |
| 890 fsBuilder->codeAppendf("\n\t\t%s.a *= %s;", outputColor, alphaUni); | 878 fsBuilder->codeAppendf("\n\t\t%s.a *= %s;", args.fOutputColor, alphaUni); |
| 891 | 879 |
| 892 // Clamp values | 880 // Clamp values |
| 893 fsBuilder->codeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", outputColor, outpu tColor); | 881 fsBuilder->codeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", args.fOutputColor, args.fOutputColor); |
| 894 | 882 |
| 895 // Pre-multiply the result | 883 // Pre-multiply the result |
| 896 fsBuilder->codeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n", | 884 fsBuilder->codeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n", |
| 897 outputColor, outputColor, outputColor, outputColor); | 885 args.fOutputColor, args.fOutputColor, args.fOutputCol or, args.fOutputColor); |
|
joshualitt
2015/07/22 19:34:05
line wrap @100
| |
| 898 } | 886 } |
| 899 | 887 |
| 900 void GrGLPerlinNoise::GenKey(const GrProcessor& processor, const GrGLSLCaps&, | 888 void GrGLPerlinNoise::GenKey(const GrProcessor& processor, const GrGLSLCaps&, |
| 901 GrProcessorKeyBuilder* b) { | 889 GrProcessorKeyBuilder* b) { |
| 902 const GrPerlinNoiseEffect& turbulence = processor.cast<GrPerlinNoiseEffect>( ); | 890 const GrPerlinNoiseEffect& turbulence = processor.cast<GrPerlinNoiseEffect>( ); |
| 903 | 891 |
| 904 uint32_t key = turbulence.numOctaves(); | 892 uint32_t key = turbulence.numOctaves(); |
| 905 | 893 |
| 906 key = key << 3; // Make room for next 3 bits | 894 key = key << 3; // Make room for next 3 bits |
| 907 | 895 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1035 str->append(" seed: "); | 1023 str->append(" seed: "); |
| 1036 str->appendScalar(fSeed); | 1024 str->appendScalar(fSeed); |
| 1037 str->append(" stitch tiles: "); | 1025 str->append(" stitch tiles: "); |
| 1038 str->append(fStitchTiles ? "true " : "false "); | 1026 str->append(fStitchTiles ? "true " : "false "); |
| 1039 | 1027 |
| 1040 this->INHERITED::toString(str); | 1028 this->INHERITED::toString(str); |
| 1041 | 1029 |
| 1042 str->append(")"); | 1030 str->append(")"); |
| 1043 } | 1031 } |
| 1044 #endif | 1032 #endif |
| OLD | NEW |