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

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

Issue 23826002: Rename ShaderType enum to ShaderVisibility (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « src/effects/SkMorphologyImageFilter.cpp ('k') | src/effects/SkTableColorFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkFlattenableBuffers.h" 10 #include "SkFlattenableBuffers.h"
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 const GrDrawEffect&, 745 const GrDrawEffect&,
746 EffectKey key, 746 EffectKey key,
747 const char* outputColor, 747 const char* outputColor,
748 const char* inputColor, 748 const char* inputColor,
749 const TextureSamplerArray&) { 749 const TextureSamplerArray&) {
750 sk_ignore_unused_variable(inputColor); 750 sk_ignore_unused_variable(inputColor);
751 751
752 SkString vCoords; 752 SkString vCoords;
753 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &vCoords); 753 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &vCoords);
754 754
755 fSeedUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 755 fSeedUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
756 kFloat_GrSLType, "seed"); 756 kFloat_GrSLType, "seed");
757 const char* seedUni = builder->getUniformCStr(fSeedUni); 757 const char* seedUni = builder->getUniformCStr(fSeedUni);
758 fInvMatrixUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 758 fInvMatrixUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
759 kMat33f_GrSLType, "invMatrix"); 759 kMat33f_GrSLType, "invMatrix");
760 const char* invMatrixUni = builder->getUniformCStr(fInvMatrixUni); 760 const char* invMatrixUni = builder->getUniformCStr(fInvMatrixUni);
761 fBaseFrequencyUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderT ype, 761 fBaseFrequencyUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibil ity,
762 kVec2f_GrSLType, "baseFrequency"); 762 kVec2f_GrSLType, "baseFrequency");
763 const char* baseFrequencyUni = builder->getUniformCStr(fBaseFrequencyUni); 763 const char* baseFrequencyUni = builder->getUniformCStr(fBaseFrequencyUni);
764 fAlphaUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 764 fAlphaUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
765 kFloat_GrSLType, "alpha"); 765 kFloat_GrSLType, "alpha");
766 const char* alphaUni = builder->getUniformCStr(fAlphaUni); 766 const char* alphaUni = builder->getUniformCStr(fAlphaUni);
767 767
768 // Add vec3 modulo 289 function 768 // Add vec3 modulo 289 function
769 static const GrGLShaderVar gVec3Args[] = { 769 static const GrGLShaderVar gVec3Args[] = {
770 GrGLShaderVar("x", kVec3f_GrSLType) 770 GrGLShaderVar("x", kVec3f_GrSLType)
771 }; 771 };
772 772
773 SkString mod289_3_funcName; 773 SkString mod289_3_funcName;
774 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kVec3f_GrSLTy pe, 774 builder->fsEmitFunction(kVec3f_GrSLType,
775 "mod289", SK_ARRAY_COUNT(gVec3Args), gVec3Args, 775 "mod289", SK_ARRAY_COUNT(gVec3Args), gVec3Args,
776 "const vec2 C = vec2(1.0 / 289.0, 289.0);\n" 776 "const vec2 C = vec2(1.0 / 289.0, 289.0);\n"
777 "return x - floor(x * C.xxx) * C.yyy;", &mod289_3_func Name); 777 "return x - floor(x * C.xxx) * C.yyy;", &mod289_3_fu ncName);
778 778
779 // Add vec4 modulo 289 function 779 // Add vec4 modulo 289 function
780 static const GrGLShaderVar gVec4Args[] = { 780 static const GrGLShaderVar gVec4Args[] = {
781 GrGLShaderVar("x", kVec4f_GrSLType) 781 GrGLShaderVar("x", kVec4f_GrSLType)
782 }; 782 };
783 783
784 SkString mod289_4_funcName; 784 SkString mod289_4_funcName;
785 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kVec4f_GrSLTy pe, 785 builder->fsEmitFunction(kVec4f_GrSLType,
786 "mod289", SK_ARRAY_COUNT(gVec4Args), gVec4Args, 786 "mod289", SK_ARRAY_COUNT(gVec4Args), gVec4Args,
787 "const vec2 C = vec2(1.0 / 289.0, 289.0);\n" 787 "const vec2 C = vec2(1.0 / 289.0, 289.0);\n"
788 "return x - floor(x * C.xxxx) * C.yyyy;", &mod289_4_fu ncName); 788 "return x - floor(x * C.xxxx) * C.yyyy;", &mod289_4_ funcName);
789 789
790 // Add vec4 permute function 790 // Add vec4 permute function
791 SkString permuteCode; 791 SkString permuteCode;
792 permuteCode.appendf("const vec2 C = vec2(34.0, 1.0);\n" 792 permuteCode.appendf("const vec2 C = vec2(34.0, 1.0);\n"
793 "return %s(((x * C.xxxx) + C.yyyy) * x);", mod289_4_func Name.c_str()); 793 "return %s(((x * C.xxxx) + C.yyyy) * x);", mod289_4_func Name.c_str());
794 SkString permuteFuncName; 794 SkString permuteFuncName;
795 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kVec4f_GrSLTy pe, 795 builder->fsEmitFunction(kVec4f_GrSLType,
796 "permute", SK_ARRAY_COUNT(gVec4Args), gVec4Args, 796 "permute", SK_ARRAY_COUNT(gVec4Args), gVec4Args,
797 permuteCode.c_str(), &permuteFuncName); 797 permuteCode.c_str(), &permuteFuncName);
798 798
799 // Add vec4 taylorInvSqrt function 799 // Add vec4 taylorInvSqrt function
800 SkString taylorInvSqrtFuncName; 800 SkString taylorInvSqrtFuncName;
801 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kVec4f_GrSLTy pe, 801 builder->fsEmitFunction(kVec4f_GrSLType,
802 "taylorInvSqrt", SK_ARRAY_COUNT(gVec4Args), gVec4Args, 802 "taylorInvSqrt", SK_ARRAY_COUNT(gVec4Args), gVec4Arg s,
803 "const vec2 C = vec2(-0.85373472095314, 1.792842914001 59);\n" 803 "const vec2 C = vec2(-0.85373472095314, 1.7928429140 0159);\n"
804 "return x * C.xxxx + C.yyyy;", &taylorInvSqrtFuncName) ; 804 "return x * C.xxxx + C.yyyy;", &taylorInvSqrtFuncNam e);
805 805
806 // Add vec3 noise function 806 // Add vec3 noise function
807 static const GrGLShaderVar gNoiseVec3Args[] = { 807 static const GrGLShaderVar gNoiseVec3Args[] = {
808 GrGLShaderVar("v", kVec3f_GrSLType) 808 GrGLShaderVar("v", kVec3f_GrSLType)
809 }; 809 };
810 810
811 SkString noiseCode; 811 SkString noiseCode;
812 noiseCode.append( 812 noiseCode.append(
813 "const vec2 C = vec2(1.0/6.0, 1.0/3.0);\n" 813 "const vec2 C = vec2(1.0/6.0, 1.0/3.0);\n"
814 "const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n" 814 "const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 "p2 *= norm.z;\n" 879 "p2 *= norm.z;\n"
880 "p3 *= norm.w;\n" 880 "p3 *= norm.w;\n"
881 881
882 // Mix final noise value 882 // Mix final noise value
883 "vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)) , 0.0);\n" 883 "vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)) , 0.0);\n"
884 "m = m * m;\n" 884 "m = m * m;\n"
885 "return 42.0 * dot(m*m, vec4(dot(p0,x0), dot(p1,x1), dot(p2,x2), dot(p3, x3)));", 885 "return 42.0 * dot(m*m, vec4(dot(p0,x0), dot(p1,x1), dot(p2,x2), dot(p3, x3)));",
886 taylorInvSqrtFuncName.c_str()); 886 taylorInvSqrtFuncName.c_str());
887 887
888 SkString noiseFuncName; 888 SkString noiseFuncName;
889 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kFloat_GrSLTy pe, 889 builder->fsEmitFunction(kFloat_GrSLType,
890 "snoise", SK_ARRAY_COUNT(gNoiseVec3Args), gNoiseVec3Ar gs, 890 "snoise", SK_ARRAY_COUNT(gNoiseVec3Args), gNoiseVec3 Args,
891 noiseCode.c_str(), &noiseFuncName); 891 noiseCode.c_str(), &noiseFuncName);
892 892
893 const char* noiseVecIni = "noiseVecIni"; 893 const char* noiseVecIni = "noiseVecIni";
894 const char* factors = "factors"; 894 const char* factors = "factors";
895 const char* sum = "sum"; 895 const char* sum = "sum";
896 const char* xOffsets = "xOffsets"; 896 const char* xOffsets = "xOffsets";
897 const char* yOffsets = "yOffsets"; 897 const char* yOffsets = "yOffsets";
898 const char* channel = "channel"; 898 const char* channel = "channel";
899 899
900 // Fill with some prime numbers 900 // Fill with some prime numbers
901 builder->fsCodeAppendf("\t\tconst vec4 %s = vec4(13.0, 53.0, 101.0, 151.0);\ n", xOffsets); 901 builder->fsCodeAppendf("\t\tconst vec4 %s = vec4(13.0, 53.0, 101.0, 151.0);\ n", xOffsets);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 const GrDrawEffect&, 961 const GrDrawEffect&,
962 EffectKey key, 962 EffectKey key,
963 const char* outputColor, 963 const char* outputColor,
964 const char* inputColor, 964 const char* inputColor,
965 const TextureSamplerArray& samplers) { 965 const TextureSamplerArray& samplers) {
966 sk_ignore_unused_variable(inputColor); 966 sk_ignore_unused_variable(inputColor);
967 967
968 SkString vCoords; 968 SkString vCoords;
969 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &vCoords); 969 fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &vCoords);
970 970
971 fInvMatrixUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 971 fInvMatrixUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
972 kMat33f_GrSLType, "invMatrix"); 972 kMat33f_GrSLType, "invMatrix");
973 const char* invMatrixUni = builder->getUniformCStr(fInvMatrixUni); 973 const char* invMatrixUni = builder->getUniformCStr(fInvMatrixUni);
974 fBaseFrequencyUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderT ype, 974 fBaseFrequencyUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibil ity,
975 kVec2f_GrSLType, "baseFrequency"); 975 kVec2f_GrSLType, "baseFrequency");
976 const char* baseFrequencyUni = builder->getUniformCStr(fBaseFrequencyUni); 976 const char* baseFrequencyUni = builder->getUniformCStr(fBaseFrequencyUni);
977 fAlphaUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, 977 fAlphaUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
978 kFloat_GrSLType, "alpha"); 978 kFloat_GrSLType, "alpha");
979 const char* alphaUni = builder->getUniformCStr(fAlphaUni); 979 const char* alphaUni = builder->getUniformCStr(fAlphaUni);
980 980
981 const char* stitchDataUni = NULL; 981 const char* stitchDataUni = NULL;
982 if (fStitchTiles) { 982 if (fStitchTiles) {
983 fStitchDataUni = builder->addUniform(GrGLShaderBuilder::kFragment_Shader Type, 983 fStitchDataUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi lity,
984 kVec2f_GrSLType, "stitchData"); 984 kVec2f_GrSLType, "stitchData");
985 stitchDataUni = builder->getUniformCStr(fStitchDataUni); 985 stitchDataUni = builder->getUniformCStr(fStitchDataUni);
986 } 986 }
987 987
988 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8 988 // There are 4 lines, so the center of each line is 1/8, 3/8, 5/8 and 7/8
989 const char* chanCoordR = "0.125"; 989 const char* chanCoordR = "0.125";
990 const char* chanCoordG = "0.375"; 990 const char* chanCoordG = "0.375";
991 const char* chanCoordB = "0.625"; 991 const char* chanCoordB = "0.625";
992 const char* chanCoordA = "0.875"; 992 const char* chanCoordA = "0.875";
993 const char* chanCoord = "chanCoord"; 993 const char* chanCoord = "chanCoord";
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal); 1130 noiseCode.appendf(dotLattice, lattice, lattice, inc8bit, fractVal);
1131 } 1131 }
1132 1132
1133 // Compute 'b' as a linear interpolation of 'u' and 'v' 1133 // Compute 'b' as a linear interpolation of 'u' and 'v'
1134 noiseCode.appendf("\n\t%s.y = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th); 1134 noiseCode.appendf("\n\t%s.y = mix(%s.x, %s.y, %s.x);", ab, uv, uv, noiseSmoo th);
1135 // Compute the noise as a linear interpolation of 'a' and 'b' 1135 // Compute the noise as a linear interpolation of 'a' and 'b'
1136 noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth ); 1136 noiseCode.appendf("\n\treturn mix(%s.x, %s.y, %s.y);\n", ab, ab, noiseSmooth );
1137 1137
1138 SkString noiseFuncName; 1138 SkString noiseFuncName;
1139 if (fStitchTiles) { 1139 if (fStitchTiles) {
1140 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kFloat_Gr SLType, 1140 builder->fsEmitFunction(kFloat_GrSLType,
1141 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitchAr gs), 1141 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitch Args),
1142 gPerlinNoiseStitchArgs, noiseCode.c_str(), &noiseF uncName); 1142 gPerlinNoiseStitchArgs, noiseCode.c_str(), &nois eFuncName);
1143 } else { 1143 } else {
1144 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kFloat_Gr SLType, 1144 builder->fsEmitFunction(kFloat_GrSLType,
1145 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs), 1145 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs),
1146 gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncNam e); 1146 gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncN ame);
1147 } 1147 }
1148 1148
1149 // There are rounding errors if the floor operation is not performed here 1149 // There are rounding errors if the floor operation is not performed here
1150 builder->fsCodeAppendf("\n\t\tvec2 %s = floor((%s * vec3(%s, 1.0)).xy) * %s; ", 1150 builder->fsCodeAppendf("\n\t\tvec2 %s = floor((%s * vec3(%s, 1.0)).xy) * %s; ",
1151 noiseVec, invMatrixUni, vCoords.c_str(), baseFrequenc yUni); 1151 noiseVec, invMatrixUni, vCoords.c_str(), baseFrequenc yUni);
1152 1152
1153 // Clear the color accumulator 1153 // Clear the color accumulator
1154 builder->fsCodeAppendf("\n\t\t%s = vec4(0.0);", outputColor); 1154 builder->fsCodeAppendf("\n\t\t%s = vec4(0.0);", outputColor);
1155 1155
1156 if (fStitchTiles) { 1156 if (fStitchTiles) {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 str->append(" seed: "); 1369 str->append(" seed: ");
1370 str->appendScalar(fSeed); 1370 str->appendScalar(fSeed);
1371 str->append(" stitch tiles: "); 1371 str->append(" stitch tiles: ");
1372 str->append(fStitchTiles ? "true " : "false "); 1372 str->append(fStitchTiles ? "true " : "false ");
1373 1373
1374 this->INHERITED::toString(str); 1374 this->INHERITED::toString(str);
1375 1375
1376 str->append(")"); 1376 str->append(")");
1377 } 1377 }
1378 #endif 1378 #endif
OLDNEW
« no previous file with comments | « src/effects/SkMorphologyImageFilter.cpp ('k') | src/effects/SkTableColorFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698