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" |
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 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 #if SK_SUPPORT_GPU | 508 #if SK_SUPPORT_GPU |
509 | 509 |
510 #include "GrTBackendEffectFactory.h" | 510 #include "GrTBackendEffectFactory.h" |
511 | 511 |
512 class GrGLPerlinNoise : public GrGLEffect { | 512 class GrGLPerlinNoise : public GrGLEffect { |
513 public: | 513 public: |
514 GrGLPerlinNoise(const GrBackendEffectFactory& factory, | 514 GrGLPerlinNoise(const GrBackendEffectFactory& factory, |
515 const GrDrawEffect& drawEffect); | 515 const GrDrawEffect& drawEffect); |
516 virtual ~GrGLPerlinNoise() {} | 516 virtual ~GrGLPerlinNoise() {} |
517 | 517 |
518 virtual void emitCode(GrGLShaderBuilder*, | 518 virtual void emitCode(GrGLProgramBuilder*, |
519 const GrDrawEffect&, | 519 const GrDrawEffect&, |
520 const GrEffectKey&, | 520 const GrEffectKey&, |
521 const char* outputColor, | 521 const char* outputColor, |
522 const char* inputColor, | 522 const char* inputColor, |
523 const TransformedCoordsArray&, | 523 const TransformedCoordsArray&, |
524 const TextureSamplerArray&) SK_OVERRIDE; | 524 const TextureSamplerArray&) SK_OVERRIDE; |
525 | 525 |
526 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; | 526 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; |
527 | 527 |
528 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder* b); | 528 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder* b); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 return effect; | 656 return effect; |
657 } | 657 } |
658 | 658 |
659 GrGLPerlinNoise::GrGLPerlinNoise(const GrBackendEffectFactory& factory, const Gr
DrawEffect& drawEffect) | 659 GrGLPerlinNoise::GrGLPerlinNoise(const GrBackendEffectFactory& factory, const Gr
DrawEffect& drawEffect) |
660 : INHERITED (factory) | 660 : INHERITED (factory) |
661 , fType(drawEffect.castEffect<GrPerlinNoiseEffect>().type()) | 661 , fType(drawEffect.castEffect<GrPerlinNoiseEffect>().type()) |
662 , fStitchTiles(drawEffect.castEffect<GrPerlinNoiseEffect>().stitchTiles()) | 662 , fStitchTiles(drawEffect.castEffect<GrPerlinNoiseEffect>().stitchTiles()) |
663 , fNumOctaves(drawEffect.castEffect<GrPerlinNoiseEffect>().numOctaves()) { | 663 , fNumOctaves(drawEffect.castEffect<GrPerlinNoiseEffect>().numOctaves()) { |
664 } | 664 } |
665 | 665 |
666 void GrGLPerlinNoise::emitCode(GrGLShaderBuilder* builder, | 666 void GrGLPerlinNoise::emitCode(GrGLProgramBuilder* builder, |
667 const GrDrawEffect&, | 667 const GrDrawEffect&, |
668 const GrEffectKey& key, | 668 const GrEffectKey& key, |
669 const char* outputColor, | 669 const char* outputColor, |
670 const char* inputColor, | 670 const char* inputColor, |
671 const TransformedCoordsArray& coords, | 671 const TransformedCoordsArray& coords, |
672 const TextureSamplerArray& samplers) { | 672 const TextureSamplerArray& samplers) { |
673 sk_ignore_unused_variable(inputColor); | 673 sk_ignore_unused_variable(inputColor); |
674 | 674 |
675 SkString vCoords = builder->ensureFSCoords2D(coords, 0); | 675 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 676 SkString vCoords = fsBuilder->ensureFSCoords2D(coords, 0); |
676 | 677 |
677 fBaseFrequencyUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibil
ity, | 678 fBaseFrequencyUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, |
678 kVec2f_GrSLType, "baseFrequency"); | 679 kVec2f_GrSLType, "baseFrequency"); |
679 const char* baseFrequencyUni = builder->getUniformCStr(fBaseFrequencyUni); | 680 const char* baseFrequencyUni = builder->getUniformCStr(fBaseFrequencyUni); |
680 fAlphaUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 681 fAlphaUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
681 kFloat_GrSLType, "alpha"); | 682 kFloat_GrSLType, "alpha"); |
682 const char* alphaUni = builder->getUniformCStr(fAlphaUni); | 683 const char* alphaUni = builder->getUniformCStr(fAlphaUni); |
683 | 684 |
684 const char* stitchDataUni = NULL; | 685 const char* stitchDataUni = NULL; |
685 if (fStitchTiles) { | 686 if (fStitchTiles) { |
686 fStitchDataUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi
lity, | 687 fStitchDataUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, |
687 kVec2f_GrSLType, "stitchData"); | 688 kVec2f_GrSLType, "stitchData"); |
688 stitchDataUni = builder->getUniformCStr(fStitchDataUni); | 689 stitchDataUni = builder->getUniformCStr(fStitchDataUni); |
689 } | 690 } |
690 | 691 |
691 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8 | 692 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8 |
692 const char* chanCoordR = "0.125"; | 693 const char* chanCoordR = "0.125"; |
693 const char* chanCoordG = "0.375"; | 694 const char* chanCoordG = "0.375"; |
694 const char* chanCoordB = "0.625"; | 695 const char* chanCoordB = "0.625"; |
695 const char* chanCoordA = "0.875"; | 696 const char* chanCoordA = "0.875"; |
696 const char* chanCoord = "chanCoord"; | 697 const char* chanCoord = "chanCoord"; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 // Get texture coordinates and normalize | 749 // Get texture coordinates and normalize |
749 noiseCode.appendf("\n\t%s = fract(floor(mod(%s, 256.0)) / vec4(256.0));\n", | 750 noiseCode.appendf("\n\t%s = fract(floor(mod(%s, 256.0)) / vec4(256.0));\n", |
750 floorVal, floorVal); | 751 floorVal, floorVal); |
751 | 752 |
752 // Get permutation for x | 753 // Get permutation for x |
753 { | 754 { |
754 SkString xCoords(""); | 755 SkString xCoords(""); |
755 xCoords.appendf("vec2(%s.x, 0.5)", floorVal); | 756 xCoords.appendf("vec2(%s.x, 0.5)", floorVal); |
756 | 757 |
757 noiseCode.appendf("\n\tvec2 %s;\n\t%s.x = ", latticeIdx, latticeIdx); | 758 noiseCode.appendf("\n\tvec2 %s;\n\t%s.x = ", latticeIdx, latticeIdx); |
758 builder->appendTextureLookup(&noiseCode, samplers[0], xCoords.c_str(), k
Vec2f_GrSLType); | 759 fsBuilder->appendTextureLookup(&noiseCode, samplers[0], xCoords.c_str(),
kVec2f_GrSLType); |
759 noiseCode.append(".r;"); | 760 noiseCode.append(".r;"); |
760 } | 761 } |
761 | 762 |
762 // Get permutation for x + 1 | 763 // Get permutation for x + 1 |
763 { | 764 { |
764 SkString xCoords(""); | 765 SkString xCoords(""); |
765 xCoords.appendf("vec2(%s.z, 0.5)", floorVal); | 766 xCoords.appendf("vec2(%s.z, 0.5)", floorVal); |
766 | 767 |
767 noiseCode.appendf("\n\t%s.y = ", latticeIdx); | 768 noiseCode.appendf("\n\t%s.y = ", latticeIdx); |
768 builder->appendTextureLookup(&noiseCode, samplers[0], xCoords.c_str(), k
Vec2f_GrSLType); | 769 fsBuilder->appendTextureLookup(&noiseCode, samplers[0], xCoords.c_str(),
kVec2f_GrSLType); |
769 noiseCode.append(".r;"); | 770 noiseCode.append(".r;"); |
770 } | 771 } |
771 | 772 |
772 #if defined(SK_BUILD_FOR_ANDROID) | 773 #if defined(SK_BUILD_FOR_ANDROID) |
773 // Android rounding for Tegra devices, like, for example: Xoom (Tegra 2), Ne
xus 7 (Tegra 3). | 774 // Android rounding for Tegra devices, like, for example: Xoom (Tegra 2), Ne
xus 7 (Tegra 3). |
774 // The issue is that colors aren't accurate enough on Tegra devices. For exa
mple, if an 8 bit | 775 // The issue is that colors aren't accurate enough on Tegra devices. For exa
mple, if an 8 bit |
775 // value of 124 (or 0.486275 here) is entered, we can get a texture value of
123.513725 | 776 // value of 124 (or 0.486275 here) is entered, we can get a texture value of
123.513725 |
776 // (or 0.484368 here). The following rounding operation prevents these preci
sion issues from | 777 // (or 0.484368 here). The following rounding operation prevents these preci
sion issues from |
777 // affecting the result of the noise by making sure that we only have multip
les of 1/255. | 778 // affecting the result of the noise by making sure that we only have multip
les of 1/255. |
778 // (Note that 1/255 is about 0.003921569, which is the value used here). | 779 // (Note that 1/255 is about 0.003921569, which is the value used here). |
779 noiseCode.appendf("\n\t%s = floor(%s * vec2(255.0) + vec2(0.5)) * vec2(0.003
921569);", | 780 noiseCode.appendf("\n\t%s = floor(%s * vec2(255.0) + vec2(0.5)) * vec2(0.003
921569);", |
780 latticeIdx, latticeIdx); | 781 latticeIdx, latticeIdx); |
781 #endif | 782 #endif |
782 | 783 |
783 // Get (x,y) coordinates with the permutated x | 784 // Get (x,y) coordinates with the permutated x |
784 noiseCode.appendf("\n\tvec4 %s = fract(%s.xyxy + %s.yyww);", bcoords, lattic
eIdx, floorVal); | 785 noiseCode.appendf("\n\tvec4 %s = fract(%s.xyxy + %s.yyww);", bcoords, lattic
eIdx, floorVal); |
785 | 786 |
786 noiseCode.appendf("\n\n\tvec2 %s;", uv); | 787 noiseCode.appendf("\n\n\tvec2 %s;", uv); |
787 // Compute u, at offset (0,0) | 788 // Compute u, at offset (0,0) |
788 { | 789 { |
789 SkString latticeCoords(""); | 790 SkString latticeCoords(""); |
790 latticeCoords.appendf("vec2(%s.x, %s)", bcoords, chanCoord); | 791 latticeCoords.appendf("vec2(%s.x, %s)", bcoords, chanCoord); |
791 noiseCode.appendf("\n\tvec4 %s = ", lattice); | 792 noiseCode.appendf("\n\tvec4 %s = ", lattice); |
792 builder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_st
r(), | 793 fsBuilder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_
str(), |
793 kVec2f_GrSLType); | 794 kVec2f_GrSLType); |
794 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); | 795 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); |
795 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); | 796 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); |
796 } | 797 } |
797 | 798 |
798 noiseCode.appendf("\n\t%s.x -= 1.0;", fractVal); | 799 noiseCode.appendf("\n\t%s.x -= 1.0;", fractVal); |
799 // Compute v, at offset (-1,0) | 800 // Compute v, at offset (-1,0) |
800 { | 801 { |
801 SkString latticeCoords(""); | 802 SkString latticeCoords(""); |
802 latticeCoords.appendf("vec2(%s.y, %s)", bcoords, chanCoord); | 803 latticeCoords.appendf("vec2(%s.y, %s)", bcoords, chanCoord); |
803 noiseCode.append("\n\tlattice = "); | 804 noiseCode.append("\n\tlattice = "); |
804 builder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_st
r(), | 805 fsBuilder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_
str(), |
805 kVec2f_GrSLType); | 806 kVec2f_GrSLType); |
806 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); | 807 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); |
807 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); | 808 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); |
808 } | 809 } |
809 | 810 |
810 // Compute 'a' as a linear interpolation of 'u' and 'v' | 811 // Compute 'a' as a linear interpolation of 'u' and 'v' |
811 noiseCode.appendf("\n\tvec2 %s;", ab); | 812 noiseCode.appendf("\n\tvec2 %s;", ab); |
812 noiseCode.appendf("\n\t%s.x = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo
th); | 813 noiseCode.appendf("\n\t%s.x = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo
th); |
813 | 814 |
814 noiseCode.appendf("\n\t%s.y -= 1.0;", fractVal); | 815 noiseCode.appendf("\n\t%s.y -= 1.0;", fractVal); |
815 // Compute v, at offset (-1,-1) | 816 // Compute v, at offset (-1,-1) |
816 { | 817 { |
817 SkString latticeCoords(""); | 818 SkString latticeCoords(""); |
818 latticeCoords.appendf("vec2(%s.w, %s)", bcoords, chanCoord); | 819 latticeCoords.appendf("vec2(%s.w, %s)", bcoords, chanCoord); |
819 noiseCode.append("\n\tlattice = "); | 820 noiseCode.append("\n\tlattice = "); |
820 builder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_st
r(), | 821 fsBuilder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_
str(), |
821 kVec2f_GrSLType); | 822 kVec2f_GrSLType); |
822 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); | 823 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); |
823 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); | 824 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); |
824 } | 825 } |
825 | 826 |
826 noiseCode.appendf("\n\t%s.x += 1.0;", fractVal); | 827 noiseCode.appendf("\n\t%s.x += 1.0;", fractVal); |
827 // Compute u, at offset (0,-1) | 828 // Compute u, at offset (0,-1) |
828 { | 829 { |
829 SkString latticeCoords(""); | 830 SkString latticeCoords(""); |
830 latticeCoords.appendf("vec2(%s.z, %s)", bcoords, chanCoord); | 831 latticeCoords.appendf("vec2(%s.z, %s)", bcoords, chanCoord); |
831 noiseCode.append("\n\tlattice = "); | 832 noiseCode.append("\n\tlattice = "); |
832 builder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_st
r(), | 833 fsBuilder->appendTextureLookup(&noiseCode, samplers[1], latticeCoords.c_
str(), |
833 kVec2f_GrSLType); | 834 kVec2f_GrSLType); |
834 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); | 835 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); |
835 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); | 836 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); |
836 } | 837 } |
837 | 838 |
838 // Compute 'b' as a linear interpolation of 'u' and 'v' | 839 // Compute 'b' as a linear interpolation of 'u' and 'v' |
839 noiseCode.appendf("\n\t%s.y = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo
th); | 840 noiseCode.appendf("\n\t%s.y = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo
th); |
840 // Compute the noise as a linear interpolation of 'a' and 'b' | 841 // Compute the noise as a linear interpolation of 'a' and 'b' |
841 noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth
); | 842 noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth
); |
842 | 843 |
843 SkString noiseFuncName; | 844 SkString noiseFuncName; |
844 if (fStitchTiles) { | 845 if (fStitchTiles) { |
845 builder->fsEmitFunction(kFloat_GrSLType, | 846 fsBuilder->emitFunction(kFloat_GrSLType, |
846 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitch
Args), | 847 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitch
Args), |
847 gPerlinNoiseStitchArgs, noiseCode.c_str(), &nois
eFuncName); | 848 gPerlinNoiseStitchArgs, noiseCode.c_str(), &nois
eFuncName); |
848 } else { | 849 } else { |
849 builder->fsEmitFunction(kFloat_GrSLType, | 850 fsBuilder->emitFunction(kFloat_GrSLType, |
850 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs), | 851 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs), |
851 gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncN
ame); | 852 gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncN
ame); |
852 } | 853 } |
853 | 854 |
854 // There are rounding errors if the floor operation is not performed here | 855 // There are rounding errors if the floor operation is not performed here |
855 builder->fsCodeAppendf("\n\t\tvec2 %s = floor(%s.xy) * %s;", | 856 fsBuilder->codeAppendf("\n\t\tvec2 %s = floor(%s.xy) * %s;", |
856 noiseVec, vCoords.c_str(), baseFrequencyUni); | 857 noiseVec, vCoords.c_str(), baseFrequencyUni); |
857 | 858 |
858 // Clear the color accumulator | 859 // Clear the color accumulator |
859 builder->fsCodeAppendf("\n\t\t%s = vec4(0.0);", outputColor); | 860 fsBuilder->codeAppendf("\n\t\t%s = vec4(0.0);", outputColor); |
860 | 861 |
861 if (fStitchTiles) { | 862 if (fStitchTiles) { |
862 // Set up TurbulenceInitial stitch values. | 863 // Set up TurbulenceInitial stitch values. |
863 builder->fsCodeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni)
; | 864 fsBuilder->codeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni)
; |
864 } | 865 } |
865 | 866 |
866 builder->fsCodeAppendf("\n\t\tfloat %s = 1.0;", ratio); | 867 fsBuilder->codeAppendf("\n\t\tfloat %s = 1.0;", ratio); |
867 | 868 |
868 // Loop over all octaves | 869 // Loop over all octaves |
869 builder->fsCodeAppendf("\n\t\tfor (int octave = 0; octave < %d; ++octave) {"
, fNumOctaves); | 870 fsBuilder->codeAppendf("\n\t\tfor (int octave = 0; octave < %d; ++octave) {"
, fNumOctaves); |
870 | 871 |
871 builder->fsCodeAppendf("\n\t\t\t%s += ", outputColor); | 872 fsBuilder->codeAppendf("\n\t\t\t%s += ", outputColor); |
872 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) { | 873 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) { |
873 builder->fsCodeAppend("abs("); | 874 fsBuilder->codeAppend("abs("); |
874 } | 875 } |
875 if (fStitchTiles) { | 876 if (fStitchTiles) { |
876 builder->fsCodeAppendf( | 877 fsBuilder->codeAppendf( |
877 "vec4(\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s)," | 878 "vec4(\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s)," |
878 "\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s))", | 879 "\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s))", |
879 noiseFuncName.c_str(), chanCoordR, noiseVec, stitchData, | 880 noiseFuncName.c_str(), chanCoordR, noiseVec, stitchData, |
880 noiseFuncName.c_str(), chanCoordG, noiseVec, stitchData, | 881 noiseFuncName.c_str(), chanCoordG, noiseVec, stitchData, |
881 noiseFuncName.c_str(), chanCoordB, noiseVec, stitchData, | 882 noiseFuncName.c_str(), chanCoordB, noiseVec, stitchData, |
882 noiseFuncName.c_str(), chanCoordA, noiseVec, stitchData); | 883 noiseFuncName.c_str(), chanCoordA, noiseVec, stitchData); |
883 } else { | 884 } else { |
884 builder->fsCodeAppendf( | 885 fsBuilder->codeAppendf( |
885 "vec4(\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s)," | 886 "vec4(\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s)," |
886 "\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s))", | 887 "\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s))", |
887 noiseFuncName.c_str(), chanCoordR, noiseVec, | 888 noiseFuncName.c_str(), chanCoordR, noiseVec, |
888 noiseFuncName.c_str(), chanCoordG, noiseVec, | 889 noiseFuncName.c_str(), chanCoordG, noiseVec, |
889 noiseFuncName.c_str(), chanCoordB, noiseVec, | 890 noiseFuncName.c_str(), chanCoordB, noiseVec, |
890 noiseFuncName.c_str(), chanCoordA, noiseVec); | 891 noiseFuncName.c_str(), chanCoordA, noiseVec); |
891 } | 892 } |
892 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) { | 893 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) { |
893 builder->fsCodeAppendf(")"); // end of "abs(" | 894 fsBuilder->codeAppendf(")"); // end of "abs(" |
894 } | 895 } |
895 builder->fsCodeAppendf(" * %s;", ratio); | 896 fsBuilder->codeAppendf(" * %s;", ratio); |
896 | 897 |
897 builder->fsCodeAppendf("\n\t\t\t%s *= vec2(2.0);", noiseVec); | 898 fsBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", noiseVec); |
898 builder->fsCodeAppendf("\n\t\t\t%s *= 0.5;", ratio); | 899 fsBuilder->codeAppendf("\n\t\t\t%s *= 0.5;", ratio); |
899 | 900 |
900 if (fStitchTiles) { | 901 if (fStitchTiles) { |
901 builder->fsCodeAppendf("\n\t\t\t%s *= vec2(2.0);", stitchData); | 902 fsBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", stitchData); |
902 } | 903 } |
903 builder->fsCodeAppend("\n\t\t}"); // end of the for loop on octaves | 904 fsBuilder->codeAppend("\n\t\t}"); // end of the for loop on octaves |
904 | 905 |
905 if (fType == SkPerlinNoiseShader::kFractalNoise_Type) { | 906 if (fType == SkPerlinNoiseShader::kFractalNoise_Type) { |
906 // The value of turbulenceFunctionResult comes from ((turbulenceFunction
Result) + 1) / 2 | 907 // The value of turbulenceFunctionResult comes from ((turbulenceFunction
Result) + 1) / 2 |
907 // by fractalNoise and (turbulenceFunctionResult) by turbulence. | 908 // by fractalNoise and (turbulenceFunctionResult) by turbulence. |
908 builder->fsCodeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);", outputC
olor, outputColor); | 909 fsBuilder->codeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);", outputC
olor, outputColor); |
909 } | 910 } |
910 | 911 |
911 builder->fsCodeAppendf("\n\t\t%s.a *= %s;", outputColor, alphaUni); | 912 fsBuilder->codeAppendf("\n\t\t%s.a *= %s;", outputColor, alphaUni); |
912 | 913 |
913 // Clamp values | 914 // Clamp values |
914 builder->fsCodeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", outputColor, outpu
tColor); | 915 fsBuilder->codeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", outputColor, outpu
tColor); |
915 | 916 |
916 // Pre-multiply the result | 917 // Pre-multiply the result |
917 builder->fsCodeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n", | 918 fsBuilder->codeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n", |
918 outputColor, outputColor, outputColor, outputColor); | 919 outputColor, outputColor, outputColor, outputColor); |
919 } | 920 } |
920 | 921 |
921 void GrGLPerlinNoise::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, Gr
EffectKeyBuilder* b) { | 922 void GrGLPerlinNoise::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, Gr
EffectKeyBuilder* b) { |
922 const GrPerlinNoiseEffect& turbulence = drawEffect.castEffect<GrPerlinNoiseE
ffect>(); | 923 const GrPerlinNoiseEffect& turbulence = drawEffect.castEffect<GrPerlinNoiseE
ffect>(); |
923 | 924 |
924 uint32_t key = turbulence.numOctaves(); | 925 uint32_t key = turbulence.numOctaves(); |
925 | 926 |
926 key = key << 3; // Make room for next 3 bits | 927 key = key << 3; // Make room for next 3 bits |
927 | 928 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 str->append(" seed: "); | 1062 str->append(" seed: "); |
1062 str->appendScalar(fSeed); | 1063 str->appendScalar(fSeed); |
1063 str->append(" stitch tiles: "); | 1064 str->append(" stitch tiles: "); |
1064 str->append(fStitchTiles ? "true " : "false "); | 1065 str->append(fStitchTiles ? "true " : "false "); |
1065 | 1066 |
1066 this->INHERITED::toString(str); | 1067 this->INHERITED::toString(str); |
1067 | 1068 |
1068 str->append(")"); | 1069 str->append(")"); |
1069 } | 1070 } |
1070 #endif | 1071 #endif |
OLD | NEW |