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

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

Issue 1885863004: Refactor how we store and use samplers in Ganesh (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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 "SkPerlinNoiseShader.h" 8 #include "SkPerlinNoiseShader.h"
9 #include "SkColorFilter.h" 9 #include "SkColorFilter.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 noiseCode.appendf("\n\tif(%s.z >= %s.x) { %s.z -= %s.x; }", 670 noiseCode.appendf("\n\tif(%s.z >= %s.x) { %s.z -= %s.x; }",
671 floorVal, stitchData, floorVal, stitchData); 671 floorVal, stitchData, floorVal, stitchData);
672 noiseCode.appendf("\n\tif(%s.w >= %s.y) { %s.w -= %s.y; }", 672 noiseCode.appendf("\n\tif(%s.w >= %s.y) { %s.w -= %s.y; }",
673 floorVal, stitchData, floorVal, stitchData); 673 floorVal, stitchData, floorVal, stitchData);
674 } 674 }
675 675
676 // Get texture coordinates and normalize 676 // Get texture coordinates and normalize
677 noiseCode.appendf("\n\t%s = fract(floor(mod(%s, 256.0)) / vec4(256.0));\n", 677 noiseCode.appendf("\n\t%s = fract(floor(mod(%s, 256.0)) / vec4(256.0));\n",
678 floorVal, floorVal); 678 floorVal, floorVal);
679 679
680 const GrGLSLSampler& sampler = uniformHandler->getSampler(args.fTexSamplers[ 0]);
680 // Get permutation for x 681 // Get permutation for x
681 { 682 {
682 SkString xCoords(""); 683 SkString xCoords("");
683 xCoords.appendf("vec2(%s.x, 0.5)", floorVal); 684 xCoords.appendf("vec2(%s.x, 0.5)", floorVal);
684 685
685 noiseCode.appendf("\n\tvec2 %s;\n\t%s.x = ", latticeIdx, latticeIdx); 686 noiseCode.appendf("\n\tvec2 %s;\n\t%s.x = ", latticeIdx, latticeIdx);
686 fragBuilder->appendTextureLookup(&noiseCode, args.fTexSamplers[0], xCoor ds.c_str(), 687 fragBuilder->appendTextureLookup(&noiseCode, sampler, xCoords.c_str(), k Vec2f_GrSLType);
687 kVec2f_GrSLType);
688 noiseCode.append(".r;"); 688 noiseCode.append(".r;");
689 } 689 }
690 690
691 // Get permutation for x + 1 691 // Get permutation for x + 1
692 { 692 {
693 SkString xCoords(""); 693 SkString xCoords("");
694 xCoords.appendf("vec2(%s.z, 0.5)", floorVal); 694 xCoords.appendf("vec2(%s.z, 0.5)", floorVal);
695 695
696 noiseCode.appendf("\n\t%s.y = ", latticeIdx); 696 noiseCode.appendf("\n\t%s.y = ", latticeIdx);
697 fragBuilder->appendTextureLookup(&noiseCode, args.fTexSamplers[0], xCoor ds.c_str(), 697 fragBuilder->appendTextureLookup(&noiseCode, sampler, xCoords.c_str(), k Vec2f_GrSLType);
698 kVec2f_GrSLType);
699 noiseCode.append(".r;"); 698 noiseCode.append(".r;");
700 } 699 }
701 700
702 #if defined(SK_BUILD_FOR_ANDROID) 701 #if defined(SK_BUILD_FOR_ANDROID)
703 // Android rounding for Tegra devices, like, for example: Xoom (Tegra 2), Ne xus 7 (Tegra 3). 702 // Android rounding for Tegra devices, like, for example: Xoom (Tegra 2), Ne xus 7 (Tegra 3).
704 // The issue is that colors aren't accurate enough on Tegra devices. For exa mple, if an 8 bit 703 // The issue is that colors aren't accurate enough on Tegra devices. For exa mple, if an 8 bit
705 // value of 124 (or 0.486275 here) is entered, we can get a texture value of 123.513725 704 // value of 124 (or 0.486275 here) is entered, we can get a texture value of 123.513725
706 // (or 0.484368 here). The following rounding operation prevents these preci sion issues from 705 // (or 0.484368 here). The following rounding operation prevents these preci sion issues from
707 // affecting the result of the noise by making sure that we only have multip les of 1/255. 706 // affecting the result of the noise by making sure that we only have multip les of 1/255.
708 // (Note that 1/255 is about 0.003921569, which is the value used here). 707 // (Note that 1/255 is about 0.003921569, which is the value used here).
709 noiseCode.appendf("\n\t%s = floor(%s * vec2(255.0) + vec2(0.5)) * vec2(0.003 921569);", 708 noiseCode.appendf("\n\t%s = floor(%s * vec2(255.0) + vec2(0.5)) * vec2(0.003 921569);",
710 latticeIdx, latticeIdx); 709 latticeIdx, latticeIdx);
711 #endif 710 #endif
712 711
713 // Get (x,y) coordinates with the permutated x 712 // Get (x,y) coordinates with the permutated x
714 noiseCode.appendf("\n\tvec4 %s = fract(%s.xyxy + %s.yyww);", bcoords, lattic eIdx, floorVal); 713 noiseCode.appendf("\n\tvec4 %s = fract(%s.xyxy + %s.yyww);", bcoords, lattic eIdx, floorVal);
715 714
715 const GrGLSLSampler& sampler1 = uniformHandler->getSampler(args.fTexSamplers [1]);
716
716 noiseCode.appendf("\n\n\tvec2 %s;", uv); 717 noiseCode.appendf("\n\n\tvec2 %s;", uv);
717 // Compute u, at offset (0,0) 718 // Compute u, at offset (0,0)
718 { 719 {
719 SkString latticeCoords(""); 720 SkString latticeCoords("");
720 latticeCoords.appendf("vec2(%s.x, %s)", bcoords, chanCoord); 721 latticeCoords.appendf("vec2(%s.x, %s)", bcoords, chanCoord);
721 noiseCode.appendf("\n\tvec4 %s = ", lattice); 722 noiseCode.appendf("\n\tvec4 %s = ", lattice);
722 fragBuilder->appendTextureLookup(&noiseCode, args.fTexSamplers[1], latti ceCoords.c_str(), 723 fragBuilder->appendTextureLookup(&noiseCode, sampler1, latticeCoords.c_s tr(),
723 kVec2f_GrSLType); 724 kVec2f_GrSLType);
724 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); 725 noiseCode.appendf(".bgra;\n\t%s.x = ", uv);
725 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); 726 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
726 } 727 }
727 728
728 noiseCode.appendf("\n\t%s.x -= 1.0;", fractVal); 729 noiseCode.appendf("\n\t%s.x -= 1.0;", fractVal);
729 // Compute v, at offset (-1,0) 730 // Compute v, at offset (-1,0)
730 { 731 {
731 SkString latticeCoords(""); 732 SkString latticeCoords("");
732 latticeCoords.appendf("vec2(%s.y, %s)", bcoords, chanCoord); 733 latticeCoords.appendf("vec2(%s.y, %s)", bcoords, chanCoord);
733 noiseCode.append("\n\tlattice = "); 734 noiseCode.append("\n\tlattice = ");
734 fragBuilder->appendTextureLookup(&noiseCode, args.fTexSamplers[1], latti ceCoords.c_str(), 735 fragBuilder->appendTextureLookup(&noiseCode, sampler1, latticeCoords.c_s tr(),
735 kVec2f_GrSLType); 736 kVec2f_GrSLType);
736 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); 737 noiseCode.appendf(".bgra;\n\t%s.y = ", uv);
737 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); 738 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
738 } 739 }
739 740
740 // Compute 'a' as a linear interpolation of 'u' and 'v' 741 // Compute 'a' as a linear interpolation of 'u' and 'v'
741 noiseCode.appendf("\n\tvec2 %s;", ab); 742 noiseCode.appendf("\n\tvec2 %s;", ab);
742 noiseCode.appendf("\n\t%s.x = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th); 743 noiseCode.appendf("\n\t%s.x = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th);
743 744
744 noiseCode.appendf("\n\t%s.y -= 1.0;", fractVal); 745 noiseCode.appendf("\n\t%s.y -= 1.0;", fractVal);
745 // Compute v, at offset (-1,-1) 746 // Compute v, at offset (-1,-1)
746 { 747 {
747 SkString latticeCoords(""); 748 SkString latticeCoords("");
748 latticeCoords.appendf("vec2(%s.w, %s)", bcoords, chanCoord); 749 latticeCoords.appendf("vec2(%s.w, %s)", bcoords, chanCoord);
749 noiseCode.append("\n\tlattice = "); 750 noiseCode.append("\n\tlattice = ");
750 fragBuilder->appendTextureLookup(&noiseCode, args.fTexSamplers[1], latti ceCoords.c_str(), 751 fragBuilder->appendTextureLookup(&noiseCode, sampler1, latticeCoords.c_s tr(),
751 kVec2f_GrSLType); 752 kVec2f_GrSLType);
752 noiseCode.appendf(".bgra;\n\t%s.y = ", uv); 753 noiseCode.appendf(".bgra;\n\t%s.y = ", uv);
753 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); 754 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
754 } 755 }
755 756
756 noiseCode.appendf("\n\t%s.x += 1.0;", fractVal); 757 noiseCode.appendf("\n\t%s.x += 1.0;", fractVal);
757 // Compute u, at offset (0,-1) 758 // Compute u, at offset (0,-1)
758 { 759 {
759 SkString latticeCoords(""); 760 SkString latticeCoords("");
760 latticeCoords.appendf("vec2(%s.z, %s)", bcoords, chanCoord); 761 latticeCoords.appendf("vec2(%s.z, %s)", bcoords, chanCoord);
761 noiseCode.append("\n\tlattice = "); 762 noiseCode.append("\n\tlattice = ");
762 fragBuilder->appendTextureLookup(&noiseCode, args.fTexSamplers[1], latti ceCoords.c_str(), 763 fragBuilder->appendTextureLookup(&noiseCode, sampler1, latticeCoords.c_s tr(),
763 kVec2f_GrSLType); 764 kVec2f_GrSLType);
764 noiseCode.appendf(".bgra;\n\t%s.x = ", uv); 765 noiseCode.appendf(".bgra;\n\t%s.x = ", uv);
765 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); 766 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
766 } 767 }
767 768
768 // Compute 'b' as a linear interpolation of 'u' and 'v' 769 // Compute 'b' as a linear interpolation of 'u' and 'v'
769 noiseCode.appendf("\n\t%s.y = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th); 770 noiseCode.appendf("\n\t%s.y = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th);
770 // Compute the noise as a linear interpolation of 'a' and 'b' 771 // Compute the noise as a linear interpolation of 'a' and 'b'
771 noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth ); 772 noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth );
772 773
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 str->append(" seed: "); 976 str->append(" seed: ");
976 str->appendScalar(fSeed); 977 str->appendScalar(fSeed);
977 str->append(" stitch tiles: "); 978 str->append(" stitch tiles: ");
978 str->append(fStitchTiles ? "true " : "false "); 979 str->append(fStitchTiles ? "true " : "false ");
979 980
980 this->INHERITED::toString(str); 981 this->INHERITED::toString(str);
981 982
982 str->append(")"); 983 str->append(")");
983 } 984 }
984 #endif 985 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698