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 "SkFlattenableBuffers.h" | 10 #include "SkFlattenableBuffers.h" |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 ///////////////////////////////////////////////////////////////////// | 742 ///////////////////////////////////////////////////////////////////// |
743 | 743 |
744 void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder, | 744 void GrGLSimplexNoise::emitCode(GrGLShaderBuilder* builder, |
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 const char* 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_ShaderType, |
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_ShaderType, |
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_ShaderT
ype, |
762 kVec2f_GrSLType, "baseFrequency"); | 762 kVec2f_GrSLType, "baseFrequency"); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
902 builder->fsCodeAppendf("\t\tconst vec4 %s = vec4(109.0, 167.0, 23.0, 67.0);\
n", yOffsets); | 902 builder->fsCodeAppendf("\t\tconst vec4 %s = vec4(109.0, 167.0, 23.0, 67.0);\
n", yOffsets); |
903 | 903 |
904 // There are rounding errors if the floor operation is not performed here | 904 // There are rounding errors if the floor operation is not performed here |
905 builder->fsCodeAppendf( | 905 builder->fsCodeAppendf( |
906 "\t\tvec3 %s = vec3(floor((%s*vec3(%s, 1.0)).xy) * vec2(0.66) * %s, 0.0)
;\n", | 906 "\t\tvec3 %s = vec3(floor((%s*vec3(%s, 1.0)).xy) * vec2(0.66) * %s, 0.0)
;\n", |
907 noiseVecIni, invMatrixUni, vCoords, baseFrequencyUni); | 907 noiseVecIni, invMatrixUni, vCoords.c_str(), baseFrequencyUni); |
908 | 908 |
909 // Perturb the texcoords with three components of noise | 909 // Perturb the texcoords with three components of noise |
910 builder->fsCodeAppendf("\t\t%s += 0.1 * vec3(%s(%s + vec3( 0.0, 0.0, %s))
," | 910 builder->fsCodeAppendf("\t\t%s += 0.1 * vec3(%s(%s + vec3( 0.0, 0.0, %s))
," |
911 "%s(%s + vec3( 43.0, 17.0, %s))
," | 911 "%s(%s + vec3( 43.0, 17.0, %s))
," |
912 "%s(%s + vec3(-17.0, -43.0, %s))
);\n", | 912 "%s(%s + vec3(-17.0, -43.0, %s))
);\n", |
913 noiseVecIni, noiseFuncName.c_str(), noiseVecIni, seed
Uni, | 913 noiseVecIni, noiseFuncName.c_str(), noiseVecIni, seed
Uni, |
914 noiseFuncName.c_str(), noiseVecIni, seed
Uni, | 914 noiseFuncName.c_str(), noiseVecIni, seed
Uni, |
915 noiseFuncName.c_str(), noiseVecIni, seed
Uni); | 915 noiseFuncName.c_str(), noiseVecIni, seed
Uni); |
916 | 916 |
917 builder->fsCodeAppendf("\t\t%s = vec4(0.0);\n", outputColor); | 917 builder->fsCodeAppendf("\t\t%s = vec4(0.0);\n", outputColor); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 } | 958 } |
959 | 959 |
960 void GrGLPerlinNoise::emitCode(GrGLShaderBuilder* builder, | 960 void GrGLPerlinNoise::emitCode(GrGLShaderBuilder* builder, |
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 const char* 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_ShaderType, |
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_ShaderT
ype, |
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_ShaderType, |
978 kFloat_GrSLType, "alpha"); | 978 kFloat_GrSLType, "alpha"); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitchAr
gs), | 1141 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseStitchAr
gs), |
1142 gPerlinNoiseStitchArgs, noiseCode.c_str(), &noiseF
uncName); | 1142 gPerlinNoiseStitchArgs, noiseCode.c_str(), &noiseF
uncName); |
1143 } else { | 1143 } else { |
1144 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kFloat_Gr
SLType, | 1144 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, kFloat_Gr
SLType, |
1145 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs), | 1145 "perlinnoise", SK_ARRAY_COUNT(gPerlinNoiseArgs), |
1146 gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncNam
e); | 1146 gPerlinNoiseArgs, noiseCode.c_str(), &noiseFuncNam
e); |
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, baseFrequencyUni); | 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) { |
1157 // Set up TurbulenceInitial stitch values. | 1157 // Set up TurbulenceInitial stitch values. |
1158 builder->fsCodeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni)
; | 1158 builder->fsCodeAppendf("\n\t\tvec2 %s = %s;", stitchData, stitchDataUni)
; |
1159 } | 1159 } |
1160 | 1160 |
1161 builder->fsCodeAppendf("\n\t\tfloat %s = 1.0;", ratio); | 1161 builder->fsCodeAppendf("\n\t\tfloat %s = 1.0;", ratio); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |