| 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 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 kNone_SkFilterQuality); | 614 kNone_SkFilterQuality); |
| 615 } | 615 } |
| 616 | 616 |
| 617 GrGLPerlinNoise::GrGLPerlinNoise(const GrProcessor& processor) | 617 GrGLPerlinNoise::GrGLPerlinNoise(const GrProcessor& processor) |
| 618 : fType(processor.cast<GrPerlinNoiseEffect>().type()) | 618 : fType(processor.cast<GrPerlinNoiseEffect>().type()) |
| 619 , fStitchTiles(processor.cast<GrPerlinNoiseEffect>().stitchTiles()) | 619 , fStitchTiles(processor.cast<GrPerlinNoiseEffect>().stitchTiles()) |
| 620 , fNumOctaves(processor.cast<GrPerlinNoiseEffect>().numOctaves()) { | 620 , fNumOctaves(processor.cast<GrPerlinNoiseEffect>().numOctaves()) { |
| 621 } | 621 } |
| 622 | 622 |
| 623 void GrGLPerlinNoise::emitCode(EmitArgs& args) { | 623 void GrGLPerlinNoise::emitCode(EmitArgs& args) { |
| 624 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; | 624 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 625 SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 625 SkString vCoords = fragBuilder->ensureFSCoords2D(args.fCoords, 0); |
| 626 | 626 |
| 627 fBaseFrequencyUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragmen
t_Visibility, | 627 fBaseFrequencyUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragmen
t_Visibility, |
| 628 kVec2f_GrSLType, kDefault_GrSLPrecis
ion, | 628 kVec2f_GrSLType, kDefault_GrSL
Precision, |
| 629 "baseFrequency"); | 629 "baseFrequency"); |
| 630 const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyU
ni); | 630 const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyU
ni); |
| 631 | 631 |
| 632 const char* stitchDataUni = nullptr; | 632 const char* stitchDataUni = nullptr; |
| 633 if (fStitchTiles) { | 633 if (fStitchTiles) { |
| 634 fStitchDataUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, | 634 fStitchDataUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, |
| 635 kVec2f_GrSLType, kDefault_GrSLPreci
sion, | 635 kVec2f_GrSLType, kDefault_GrS
LPrecision, |
| 636 "stitchData"); | 636 "stitchData"); |
| 637 stitchDataUni = args.fBuilder->getUniformCStr(fStitchDataUni); | 637 stitchDataUni = args.fBuilder->getUniformCStr(fStitchDataUni); |
| 638 } | 638 } |
| 639 | 639 |
| 640 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8 | 640 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8 |
| 641 const char* chanCoordR = "0.125"; | 641 const char* chanCoordR = "0.125"; |
| 642 const char* chanCoordG = "0.375"; | 642 const char* chanCoordG = "0.375"; |
| 643 const char* chanCoordB = "0.625"; | 643 const char* chanCoordB = "0.625"; |
| 644 const char* chanCoordA = "0.875"; | 644 const char* chanCoordA = "0.875"; |
| 645 const char* chanCoord = "chanCoord"; | 645 const char* chanCoord = "chanCoord"; |
| 646 const char* stitchData = "stitchData"; | 646 const char* stitchData = "stitchData"; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 noiseCode.appendf("\t%s.zw = %s.xy + vec2(1.0);\n", floorVal, floorVal); | 678 noiseCode.appendf("\t%s.zw = %s.xy + vec2(1.0);\n", floorVal, floorVal); |
| 679 noiseCode.appendf("\tvec2 %s = fract(%s);\n", fractVal, noiseVec); | 679 noiseCode.appendf("\tvec2 %s = fract(%s);\n", fractVal, noiseVec); |
| 680 | 680 |
| 681 // smooth curve : t * t * (3 - 2 * t) | 681 // smooth curve : t * t * (3 - 2 * t) |
| 682 noiseCode.appendf("\n\tvec2 %s = %s * %s * (vec2(3.0) - vec2(2.0) * %s);", | 682 noiseCode.appendf("\n\tvec2 %s = %s * %s * (vec2(3.0) - vec2(2.0) * %s);", |
| 683 noiseSmooth, fractVal, fractVal, fractVal); | 683 noiseSmooth, fractVal, fractVal, fractVal); |
| 684 | 684 |
| 685 // Adjust frequencies if we're stitching tiles | 685 // Adjust frequencies if we're stitching tiles |
| 686 if (fStitchTiles) { | 686 if (fStitchTiles) { |
| 687 noiseCode.appendf("\n\tif(%s.x >= %s.x) { %s.x -= %s.x; }", | 687 noiseCode.appendf("\n\tif(%s.x >= %s.x) { %s.x -= %s.x; }", |
| 688 floorVal, stitchData, floorVal, stitchData); | 688 floorVal, stitchData, floorVal, stitchData); |
| 689 noiseCode.appendf("\n\tif(%s.y >= %s.y) { %s.y -= %s.y; }", | 689 noiseCode.appendf("\n\tif(%s.y >= %s.y) { %s.y -= %s.y; }", |
| 690 floorVal, stitchData, floorVal, stitchData); | 690 floorVal, stitchData, floorVal, stitchData); |
| 691 noiseCode.appendf("\n\tif(%s.z >= %s.x) { %s.z -= %s.x; }", | 691 noiseCode.appendf("\n\tif(%s.z >= %s.x) { %s.z -= %s.x; }", |
| 692 floorVal, stitchData, floorVal, stitchData); | 692 floorVal, stitchData, floorVal, stitchData); |
| 693 noiseCode.appendf("\n\tif(%s.w >= %s.y) { %s.w -= %s.y; }", | 693 noiseCode.appendf("\n\tif(%s.w >= %s.y) { %s.w -= %s.y; }", |
| 694 floorVal, stitchData, floorVal, stitchData); | 694 floorVal, stitchData, floorVal, stitchData); |
| 695 } | 695 } |
| 696 | 696 |
| 697 // Get texture coordinates and normalize | 697 // Get texture coordinates and normalize |
| 698 noiseCode.appendf("\n\t%s = fract(floor(mod(%s, 256.0)) / vec4(256.0));\n", | 698 noiseCode.appendf("\n\t%s = fract(floor(mod(%s, 256.0)) / vec4(256.0));\n", |
| 699 floorVal, floorVal); | 699 floorVal, floorVal); |
| 700 | 700 |
| 701 // Get permutation for x | 701 // Get permutation for x |
| 702 { | 702 { |
| 703 SkString xCoords(""); | 703 SkString xCoords(""); |
| 704 xCoords.appendf("vec2(%s.x, 0.5)", floorVal); | 704 xCoords.appendf("vec2(%s.x, 0.5)", floorVal); |
| 705 | 705 |
| 706 noiseCode.appendf("\n\tvec2 %s;\n\t%s.x = ", latticeIdx, latticeIdx); | 706 noiseCode.appendf("\n\tvec2 %s;\n\t%s.x = ", latticeIdx, latticeIdx); |
| 707 fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[0], xCoords.c_
str(), | 707 fragBuilder->appendTextureLookup(&noiseCode, args.fSamplers[0], xCoords.
c_str(), |
| 708 kVec2f_GrSLType); | 708 kVec2f_GrSLType); |
| 709 noiseCode.append(".r;"); | 709 noiseCode.append(".r;"); |
| 710 } | 710 } |
| 711 | 711 |
| 712 // Get permutation for x + 1 | 712 // Get permutation for x + 1 |
| 713 { | 713 { |
| 714 SkString xCoords(""); | 714 SkString xCoords(""); |
| 715 xCoords.appendf("vec2(%s.z, 0.5)", floorVal); | 715 xCoords.appendf("vec2(%s.z, 0.5)", floorVal); |
| 716 | 716 |
| 717 noiseCode.appendf("\n\t%s.y = ", latticeIdx); | 717 noiseCode.appendf("\n\t%s.y = ", latticeIdx); |
| 718 fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[0], xCoords.c_
str(), | 718 fragBuilder->appendTextureLookup(&noiseCode, args.fSamplers[0], xCoords.
c_str(), |
| 719 kVec2f_GrSLType); | 719 kVec2f_GrSLType); |
| 720 noiseCode.append(".r;"); | 720 noiseCode.append(".r;"); |
| 721 } | 721 } |
| 722 | 722 |
| 723 #if defined(SK_BUILD_FOR_ANDROID) | 723 #if defined(SK_BUILD_FOR_ANDROID) |
| 724 // Android rounding for Tegra devices, like, for example: Xoom (Tegra 2), Ne
xus 7 (Tegra 3). | 724 // Android rounding for Tegra devices, like, for example: Xoom (Tegra 2), Ne
xus 7 (Tegra 3). |
| 725 // The issue is that colors aren't accurate enough on Tegra devices. For exa
mple, if an 8 bit | 725 // The issue is that colors aren't accurate enough on Tegra devices. For exa
mple, if an 8 bit |
| 726 // value of 124 (or 0.486275 here) is entered, we can get a texture value of
123.513725 | 726 // value of 124 (or 0.486275 here) is entered, we can get a texture value of
123.513725 |
| 727 // (or 0.484368 here). The following rounding operation prevents these preci
sion issues from | 727 // (or 0.484368 here). The following rounding operation prevents these preci
sion issues from |
| 728 // affecting the result of the noise by making sure that we only have multip
les of 1/255. | 728 // affecting the result of the noise by making sure that we only have multip
les of 1/255. |
| 729 // (Note that 1/255 is about 0.003921569, which is the value used here). | 729 // (Note that 1/255 is about 0.003921569, which is the value used here). |
| 730 noiseCode.appendf("\n\t%s = floor(%s * vec2(255.0) + vec2(0.5)) * vec2(0.003
921569);", | 730 noiseCode.appendf("\n\t%s = floor(%s * vec2(255.0) + vec2(0.5)) * vec2(0.003
921569);", |
| 731 latticeIdx, latticeIdx); | 731 latticeIdx, latticeIdx); |
| 732 #endif | 732 #endif |
| 733 | 733 |
| 734 // Get (x,y) coordinates with the permutated x | 734 // Get (x,y) coordinates with the permutated x |
| 735 noiseCode.appendf("\n\tvec4 %s = fract(%s.xyxy + %s.yyww);", bcoords, lattic
eIdx, floorVal); | 735 noiseCode.appendf("\n\tvec4 %s = fract(%s.xyxy + %s.yyww);", bcoords, lattic
eIdx, floorVal); |
| 736 | 736 |
| 737 noiseCode.appendf("\n\n\tvec2 %s;", uv); | 737 noiseCode.appendf("\n\n\tvec2 %s;", uv); |
| 738 // Compute u, at offset (0,0) | 738 // Compute u, at offset (0,0) |
| 739 { | 739 { |
| 740 SkString latticeCoords(""); | 740 SkString latticeCoords(""); |
| 741 latticeCoords.appendf("vec2(%s.x, %s)", bcoords, chanCoord); | 741 latticeCoords.appendf("vec2(%s.x, %s)", bcoords, chanCoord); |
| 742 noiseCode.appendf("\n\tvec4 %s = ", lattice); | 742 noiseCode.appendf("\n\tvec4 %s = ", lattice); |
| 743 fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoo
rds.c_str(), | 743 fragBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeC
oords.c_str(), |
| 744 kVec2f_GrSLType); | 744 kVec2f_GrSLType); |
| 745 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); | 745 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); |
| 746 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); | 746 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); |
| 747 } | 747 } |
| 748 | 748 |
| 749 noiseCode.appendf("\n\t%s.x -= 1.0;", fractVal); | 749 noiseCode.appendf("\n\t%s.x -= 1.0;", fractVal); |
| 750 // Compute v, at offset (-1,0) | 750 // Compute v, at offset (-1,0) |
| 751 { | 751 { |
| 752 SkString latticeCoords(""); | 752 SkString latticeCoords(""); |
| 753 latticeCoords.appendf("vec2(%s.y, %s)", bcoords, chanCoord); | 753 latticeCoords.appendf("vec2(%s.y, %s)", bcoords, chanCoord); |
| 754 noiseCode.append("\n\tlattice = "); | 754 noiseCode.append("\n\tlattice = "); |
| 755 fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoo
rds.c_str(), | 755 fragBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeC
oords.c_str(), |
| 756 kVec2f_GrSLType); | 756 kVec2f_GrSLType); |
| 757 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); | 757 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); |
| 758 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); | 758 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); |
| 759 } | 759 } |
| 760 | 760 |
| 761 // Compute 'a' as a linear interpolation of 'u' and 'v' | 761 // Compute 'a' as a linear interpolation of 'u' and 'v' |
| 762 noiseCode.appendf("\n\tvec2 %s;", ab); | 762 noiseCode.appendf("\n\tvec2 %s;", ab); |
| 763 noiseCode.appendf("\n\t%s.x = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo
th); | 763 noiseCode.appendf("\n\t%s.x = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo
th); |
| 764 | 764 |
| 765 noiseCode.appendf("\n\t%s.y -= 1.0;", fractVal); | 765 noiseCode.appendf("\n\t%s.y -= 1.0;", fractVal); |
| 766 // Compute v, at offset (-1,-1) | 766 // Compute v, at offset (-1,-1) |
| 767 { | 767 { |
| 768 SkString latticeCoords(""); | 768 SkString latticeCoords(""); |
| 769 latticeCoords.appendf("vec2(%s.w, %s)", bcoords, chanCoord); | 769 latticeCoords.appendf("vec2(%s.w, %s)", bcoords, chanCoord); |
| 770 noiseCode.append("\n\tlattice = "); | 770 noiseCode.append("\n\tlattice = "); |
| 771 fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoo
rds.c_str(), | 771 fragBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeC
oords.c_str(), |
| 772 kVec2f_GrSLType); | 772 kVec2f_GrSLType); |
| 773 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); | 773 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); |
| 774 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); | 774 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); |
| 775 } | 775 } |
| 776 | 776 |
| 777 noiseCode.appendf("\n\t%s.x += 1.0;", fractVal); | 777 noiseCode.appendf("\n\t%s.x += 1.0;", fractVal); |
| 778 // Compute u, at offset (0,-1) | 778 // Compute u, at offset (0,-1) |
| 779 { | 779 { |
| 780 SkString latticeCoords(""); | 780 SkString latticeCoords(""); |
| 781 latticeCoords.appendf("vec2(%s.z, %s)", bcoords, chanCoord); | 781 latticeCoords.appendf("vec2(%s.z, %s)", bcoords, chanCoord); |
| 782 noiseCode.append("\n\tlattice = "); | 782 noiseCode.append("\n\tlattice = "); |
| 783 fsBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeCoo
rds.c_str(), | 783 fragBuilder->appendTextureLookup(&noiseCode, args.fSamplers[1], latticeC
oords.c_str(), |
| 784 kVec2f_GrSLType); | 784 kVec2f_GrSLType); |
| 785 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); | 785 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); |
| 786 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); | 786 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); |
| 787 } | 787 } |
| 788 | 788 |
| 789 // Compute 'b' as a linear interpolation of 'u' and 'v' | 789 // Compute 'b' as a linear interpolation of 'u' and 'v' |
| 790 noiseCode.appendf("\n\t%s.y = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo
th); | 790 noiseCode.appendf("\n\t%s.y = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo
th); |
| 791 // Compute the noise as a linear interpolation of 'a' and 'b' | 791 // Compute the noise as a linear interpolation of 'a' and 'b' |
| 792 noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth
); | 792 noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth
); |
| 793 | 793 |
| 794 SkString noiseFuncName; | 794 SkString noiseFuncName; |
| 795 if (fStitchTiles) { | 795 if (fStitchTiles) { |
| 796 fsBuilder->emitFunction(kFloat_GrSLType, | 796 fragBuilder->emitFunction(kFloat_GrSLType, |
| 797 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitch
Args), | 797 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStit
chArgs), |
| 798 gPerlinNoiseStitchArgs, noiseCode.c_str(), &nois
eFuncName); | 798 gPerlinNoiseStitchArgs, noiseCode.c_str(), &no
iseFuncName); |
| 799 } else { | 799 } else { |
| 800 fsBuilder->emitFunction(kFloat_GrSLType, | 800 fragBuilder->emitFunction(kFloat_GrSLType, |
| 801 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs), | 801 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs
), |
| 802 gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncN
ame); | 802 gPerlinNoiseArgs, noiseCode.c_str(), &noiseFun
cName); |
| 803 } | 803 } |
| 804 | 804 |
| 805 // There are rounding errors if the floor operation is not performed here | 805 // There are rounding errors if the floor operation is not performed here |
| 806 fsBuilder->codeAppendf("\n\t\tvec2 %s = floor(%s.xy) * %s;", | 806 fragBuilder->codeAppendf("\n\t\tvec2 %s = floor(%s.xy) * %s;", |
| 807 noiseVec, vCoords.c_str(), baseFrequencyUni); | 807 noiseVec, vCoords.c_str(), baseFrequencyUni); |
| 808 | 808 |
| 809 // Clear the color accumulator | 809 // Clear the color accumulator |
| 810 fsBuilder->codeAppendf("\n\t\t%s = vec4(0.0);", args.fOutputColor); | 810 fragBuilder->codeAppendf("\n\t\t%s = vec4(0.0);", args.fOutputColor); |
| 811 | 811 |
| 812 if (fStitchTiles) { | 812 if (fStitchTiles) { |
| 813 // Set up TurbulenceInitial stitch values. | 813 // Set up TurbulenceInitial stitch values. |
| 814 fsBuilder->codeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni)
; | 814 fragBuilder->codeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUn
i); |
| 815 } | 815 } |
| 816 | 816 |
| 817 fsBuilder->codeAppendf("\n\t\tfloat %s = 1.0;", ratio); | 817 fragBuilder->codeAppendf("\n\t\tfloat %s = 1.0;", ratio); |
| 818 | 818 |
| 819 // Loop over all octaves | 819 // Loop over all octaves |
| 820 fsBuilder->codeAppendf("\n\t\tfor (int octave = 0; octave < %d; ++octave) {"
, fNumOctaves); | 820 fragBuilder->codeAppendf("\n\t\tfor (int octave = 0; octave < %d; ++octave)
{", fNumOctaves); |
| 821 | 821 |
| 822 fsBuilder->codeAppendf("\n\t\t\t%s += ", args.fOutputColor); | 822 fragBuilder->codeAppendf("\n\t\t\t%s += ", args.fOutputColor); |
| 823 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) { | 823 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) { |
| 824 fsBuilder->codeAppend("abs("); | 824 fragBuilder->codeAppend("abs("); |
| 825 } | 825 } |
| 826 if (fStitchTiles) { | 826 if (fStitchTiles) { |
| 827 fsBuilder->codeAppendf( | 827 fragBuilder->codeAppendf( |
| 828 "vec4(\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s)," | 828 "vec4(\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s)," |
| 829 "\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s))", | 829 "\n\t\t\t\t%s(%s, %s, %s),\n\t\t\t\t%s(%s, %s, %s))", |
| 830 noiseFuncName.c_str(), chanCoordR, noiseVec, stitchData, | 830 noiseFuncName.c_str(), chanCoordR, noiseVec, stitchData, |
| 831 noiseFuncName.c_str(), chanCoordG, noiseVec, stitchData, | 831 noiseFuncName.c_str(), chanCoordG, noiseVec, stitchData, |
| 832 noiseFuncName.c_str(), chanCoordB, noiseVec, stitchData, | 832 noiseFuncName.c_str(), chanCoordB, noiseVec, stitchData, |
| 833 noiseFuncName.c_str(), chanCoordA, noiseVec, stitchData); | 833 noiseFuncName.c_str(), chanCoordA, noiseVec, stitchData); |
| 834 } else { | 834 } else { |
| 835 fsBuilder->codeAppendf( | 835 fragBuilder->codeAppendf( |
| 836 "vec4(\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s)," | 836 "vec4(\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s)," |
| 837 "\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s))", | 837 "\n\t\t\t\t%s(%s, %s),\n\t\t\t\t%s(%s, %s))", |
| 838 noiseFuncName.c_str(), chanCoordR, noiseVec, | 838 noiseFuncName.c_str(), chanCoordR, noiseVec, |
| 839 noiseFuncName.c_str(), chanCoordG, noiseVec, | 839 noiseFuncName.c_str(), chanCoordG, noiseVec, |
| 840 noiseFuncName.c_str(), chanCoordB, noiseVec, | 840 noiseFuncName.c_str(), chanCoordB, noiseVec, |
| 841 noiseFuncName.c_str(), chanCoordA, noiseVec); | 841 noiseFuncName.c_str(), chanCoordA, noiseVec); |
| 842 } | 842 } |
| 843 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) { | 843 if (fType != SkPerlinNoiseShader::kFractalNoise_Type) { |
| 844 fsBuilder->codeAppendf(")"); // end of "abs(" | 844 fragBuilder->codeAppendf(")"); // end of "abs(" |
| 845 } | 845 } |
| 846 fsBuilder->codeAppendf(" * %s;", ratio); | 846 fragBuilder->codeAppendf(" * %s;", ratio); |
| 847 | 847 |
| 848 fsBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", noiseVec); | 848 fragBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", noiseVec); |
| 849 fsBuilder->codeAppendf("\n\t\t\t%s *= 0.5;", ratio); | 849 fragBuilder->codeAppendf("\n\t\t\t%s *= 0.5;", ratio); |
| 850 | 850 |
| 851 if (fStitchTiles) { | 851 if (fStitchTiles) { |
| 852 fsBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", stitchData); | 852 fragBuilder->codeAppendf("\n\t\t\t%s *= vec2(2.0);", stitchData); |
| 853 } | 853 } |
| 854 fsBuilder->codeAppend("\n\t\t}"); // end of the for loop on octaves | 854 fragBuilder->codeAppend("\n\t\t}"); // end of the for loop on octaves |
| 855 | 855 |
| 856 if (fType == SkPerlinNoiseShader::kFractalNoise_Type) { | 856 if (fType == SkPerlinNoiseShader::kFractalNoise_Type) { |
| 857 // The value of turbulenceFunctionResult comes from ((turbulenceFunction
Result) + 1) / 2 | 857 // The value of turbulenceFunctionResult comes from ((turbulenceFunction
Result) + 1) / 2 |
| 858 // by fractalNoise and (turbulenceFunctionResult) by turbulence. | 858 // by fractalNoise and (turbulenceFunctionResult) by turbulence. |
| 859 fsBuilder->codeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);", | 859 fragBuilder->codeAppendf("\n\t\t%s = %s * vec4(0.5) + vec4(0.5);", |
| 860 args.fOutputColor,args.fOutputColor); | 860 args.fOutputColor,args.fOutputColor); |
| 861 } | 861 } |
| 862 | 862 |
| 863 // Clamp values | 863 // Clamp values |
| 864 fsBuilder->codeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", args.fOutputColor,
args.fOutputColor); | 864 fragBuilder->codeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", args.fOutputColo
r, args.fOutputColor); |
| 865 | 865 |
| 866 // Pre-multiply the result | 866 // Pre-multiply the result |
| 867 fsBuilder->codeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n", | 867 fragBuilder->codeAppendf("\n\t\t%s = vec4(%s.rgb * %s.aaa, %s.a);\n", |
| 868 args.fOutputColor, args.fOutputColor, | 868 args.fOutputColor, args.fOutputColor, |
| 869 args.fOutputColor, args.fOutputColor); | 869 args.fOutputColor, args.fOutputColor); |
| 870 } | 870 } |
| 871 | 871 |
| 872 void GrGLPerlinNoise::GenKey(const GrProcessor& processor, const GrGLSLCaps&, | 872 void GrGLPerlinNoise::GenKey(const GrProcessor& processor, const GrGLSLCaps&, |
| 873 GrProcessorKeyBuilder* b) { | 873 GrProcessorKeyBuilder* b) { |
| 874 const GrPerlinNoiseEffect& turbulence = processor.cast<GrPerlinNoiseEffect>(
); | 874 const GrPerlinNoiseEffect& turbulence = processor.cast<GrPerlinNoiseEffect>(
); |
| 875 | 875 |
| 876 uint32_t key = turbulence.numOctaves(); | 876 uint32_t key = turbulence.numOctaves(); |
| 877 | 877 |
| 878 key = key << 3; // Make room for next 3 bits | 878 key = key << 3; // Make room for next 3 bits |
| 879 | 879 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 str->append(" seed: "); | 996 str->append(" seed: "); |
| 997 str->appendScalar(fSeed); | 997 str->appendScalar(fSeed); |
| 998 str->append(" stitch tiles: "); | 998 str->append(" stitch tiles: "); |
| 999 str->append(fStitchTiles ? "true " : "false "); | 999 str->append(fStitchTiles ? "true " : "false "); |
| 1000 | 1000 |
| 1001 this->INHERITED::toString(str); | 1001 this->INHERITED::toString(str); |
| 1002 | 1002 |
| 1003 str->append(")"); | 1003 str->append(")"); |
| 1004 } | 1004 } |
| 1005 #endif | 1005 #endif |
| OLD | NEW |