OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkTwoPointConicalGradient_gpu.h" | 8 #include "SkTwoPointConicalGradient_gpu.h" |
9 | 9 |
10 #include "SkTwoPointConicalGradient.h" | 10 #include "SkTwoPointConicalGradient.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 SkString p0; // start radius | 236 SkString p0; // start radius |
237 SkString p1; // start radius squared | 237 SkString p1; // start radius squared |
238 SkString p2; // difference in radii (r1 - r0) | 238 SkString p2; // difference in radii (r1 - r0) |
239 | 239 |
240 | 240 |
241 p0.appendf("%s.x", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); | 241 p0.appendf("%s.x", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); |
242 p1.appendf("%s.y", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); | 242 p1.appendf("%s.y", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); |
243 p2.appendf("%s.z", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); | 243 p2.appendf("%s.z", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); |
244 | 244 |
245 // We interpolate the linear component in coords[1]. | 245 // We interpolate the linear component in coords[1]. |
246 SkASSERT(args.fCoords[0].getType() == args.fCoords[1].getType()); | 246 SkASSERT(args.fTransformedCoords[0].getType() == args.fTransformedCoords[1].
getType()); |
247 const char* coords2D; | 247 const char* coords2D; |
248 SkString bVar; | 248 SkString bVar; |
249 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 249 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
250 if (kVec3f_GrSLType == args.fCoords[0].getType()) { | 250 if (kVec3f_GrSLType == args.fTransformedCoords[0].getType()) { |
251 fragBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x
/ %s.z);\n", | 251 fragBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x
/ %s.z);\n", |
252 args.fCoords[0].c_str(), args.fCoords[0].c_str(), | 252 args.fTransformedCoords[0].c_str(), |
253 args.fCoords[1].c_str(), args.fCoords[1].c_str())
; | 253 args.fTransformedCoords[0].c_str(), |
| 254 args.fTransformedCoords[1].c_str(), |
| 255 args.fTransformedCoords[1].c_str()); |
254 coords2D = "interpolants.xy"; | 256 coords2D = "interpolants.xy"; |
255 bVar = "interpolants.z"; | 257 bVar = "interpolants.z"; |
256 } else { | 258 } else { |
257 coords2D = args.fCoords[0].c_str(); | 259 coords2D = args.fTransformedCoords[0].c_str(); |
258 bVar.printf("%s.x", args.fCoords[1].c_str()); | 260 bVar.printf("%s.x", args.fTransformedCoords[1].c_str()); |
259 } | 261 } |
260 | 262 |
261 // output will default to transparent black (we simply won't write anything | 263 // output will default to transparent black (we simply won't write anything |
262 // else to it if invalid, instead of discarding or returning prematurely) | 264 // else to it if invalid, instead of discarding or returning prematurely) |
263 fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColo
r); | 265 fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColo
r); |
264 | 266 |
265 // c = (x^2)+(y^2) - params[1] | 267 // c = (x^2)+(y^2) - params[1] |
266 fragBuilder->codeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", | 268 fragBuilder->codeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", |
267 cName.c_str(), coords2D, coords2D, p1.c_str()); | 269 cName.c_str(), coords2D, coords2D, p1.c_str()); |
268 | 270 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 "Conical2FSParams"); | 518 "Conical2FSParams"); |
517 SkString tName("t"); | 519 SkString tName("t"); |
518 SkString p0; // focalX | 520 SkString p0; // focalX |
519 SkString p1; // 1 - focalX * focalX | 521 SkString p1; // 1 - focalX * focalX |
520 | 522 |
521 p0.appendf("%s.x", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); | 523 p0.appendf("%s.x", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); |
522 p1.appendf("%s.y", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); | 524 p1.appendf("%s.y", uniformHandler->getUniformVariable(fParamUni).getName().c
_str()); |
523 | 525 |
524 // if we have a vec3 from being in perspective, convert it to a vec2 first | 526 // if we have a vec3 from being in perspective, convert it to a vec2 first |
525 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 527 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
526 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0); | 528 SkString coords2DString = fragBuilder->ensureCoords2D(args.fTransformedCoord
s[0]); |
527 const char* coords2D = coords2DString.c_str(); | 529 const char* coords2D = coords2DString.c_str(); |
528 | 530 |
529 // t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2) | 531 // t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2) |
530 | 532 |
531 // output will default to transparent black (we simply won't write anything | 533 // output will default to transparent black (we simply won't write anything |
532 // else to it if invalid, instead of discarding or returning prematurely) | 534 // else to it if invalid, instead of discarding or returning prematurely) |
533 fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColo
r); | 535 fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColo
r); |
534 | 536 |
535 fragBuilder->codeAppendf("\tfloat xs = %s.x * %s.x;\n", coords2D, coords2D); | 537 fragBuilder->codeAppendf("\tfloat xs = %s.x * %s.x;\n", coords2D, coords2D); |
536 fragBuilder->codeAppendf("\tfloat ys = %s.y * %s.y;\n", coords2D, coords2D); | 538 fragBuilder->codeAppendf("\tfloat ys = %s.y * %s.y;\n", coords2D, coords2D); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 kFloat_GrSLType, kDefault_GrSLPrecisi
on, | 726 kFloat_GrSLType, kDefault_GrSLPrecisi
on, |
725 "Conical2FSParams"); | 727 "Conical2FSParams"); |
726 SkString tName("t"); | 728 SkString tName("t"); |
727 | 729 |
728 // this is the distance along x-axis from the end center to focal point in | 730 // this is the distance along x-axis from the end center to focal point in |
729 // transformed coordinates | 731 // transformed coordinates |
730 GrGLSLShaderVar focal = uniformHandler->getUniformVariable(fFocalUni); | 732 GrGLSLShaderVar focal = uniformHandler->getUniformVariable(fFocalUni); |
731 | 733 |
732 // if we have a vec3 from being in perspective, convert it to a vec2 first | 734 // if we have a vec3 from being in perspective, convert it to a vec2 first |
733 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 735 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
734 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0); | 736 SkString coords2DString = fragBuilder->ensureCoords2D(args.fTransformedCoord
s[0]); |
735 const char* coords2D = coords2DString.c_str(); | 737 const char* coords2D = coords2DString.c_str(); |
736 | 738 |
737 // t = p.x * focalX + length(p) | 739 // t = p.x * focalX + length(p) |
738 fragBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_
str(), | 740 fragBuilder->codeAppendf("\tfloat %s = %s.x * %s + length(%s);\n", tName.c_
str(), |
739 coords2D, focal.c_str(), coords2D); | 741 coords2D, focal.c_str(), coords2D); |
740 | 742 |
741 this->emitColor(fragBuilder, | 743 this->emitColor(fragBuilder, |
742 uniformHandler, | 744 uniformHandler, |
743 args.fGLSLCaps, | 745 args.fGLSLCaps, |
744 ge, | 746 ge, |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 SkString tName("t"); | 989 SkString tName("t"); |
988 | 990 |
989 GrGLSLShaderVar center = uniformHandler->getUniformVariable(fCenterUni); | 991 GrGLSLShaderVar center = uniformHandler->getUniformVariable(fCenterUni); |
990 // params.x = A | 992 // params.x = A |
991 // params.y = B | 993 // params.y = B |
992 // params.z = C | 994 // params.z = C |
993 GrGLSLShaderVar params = uniformHandler->getUniformVariable(fParamUni); | 995 GrGLSLShaderVar params = uniformHandler->getUniformVariable(fParamUni); |
994 | 996 |
995 // if we have a vec3 from being in perspective, convert it to a vec2 first | 997 // if we have a vec3 from being in perspective, convert it to a vec2 first |
996 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 998 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
997 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0); | 999 SkString coords2DString = fragBuilder->ensureCoords2D(args.fTransformedCoord
s[0]); |
998 const char* coords2D = coords2DString.c_str(); | 1000 const char* coords2D = coords2DString.c_str(); |
999 | 1001 |
1000 // p = coords2D | 1002 // p = coords2D |
1001 // e = center end | 1003 // e = center end |
1002 // r = radius end | 1004 // r = radius end |
1003 // A = dot(e, e) - r^2 + 2 * r - 1 | 1005 // A = dot(e, e) - r^2 + 2 * r - 1 |
1004 // B = (r -1) / A | 1006 // B = (r -1) / A |
1005 // C = 1 / A | 1007 // C = 1 / A |
1006 // d = dot(e, p) + B | 1008 // d = dot(e, p) + B |
1007 // t = d +/- sqrt(d^2 - A * dot(p, p) + C) | 1009 // t = d +/- sqrt(d^2 - A * dot(p, p) + C) |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 SkString tName("t"); | 1232 SkString tName("t"); |
1231 | 1233 |
1232 GrGLSLShaderVar center = uniformHandler->getUniformVariable(fCenterUni); | 1234 GrGLSLShaderVar center = uniformHandler->getUniformVariable(fCenterUni); |
1233 // params.x = A | 1235 // params.x = A |
1234 // params.y = B | 1236 // params.y = B |
1235 // params.z = C | 1237 // params.z = C |
1236 GrGLSLShaderVar params = uniformHandler->getUniformVariable(fParamUni); | 1238 GrGLSLShaderVar params = uniformHandler->getUniformVariable(fParamUni); |
1237 | 1239 |
1238 // if we have a vec3 from being in perspective, convert it to a vec2 first | 1240 // if we have a vec3 from being in perspective, convert it to a vec2 first |
1239 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 1241 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
1240 SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0); | 1242 SkString coords2DString = fragBuilder->ensureCoords2D(args.fTransformedCoord
s[0]); |
1241 const char* coords2D = coords2DString.c_str(); | 1243 const char* coords2D = coords2DString.c_str(); |
1242 | 1244 |
1243 // output will default to transparent black (we simply won't write anything | 1245 // output will default to transparent black (we simply won't write anything |
1244 // else to it if invalid, instead of discarding or returning prematurely) | 1246 // else to it if invalid, instead of discarding or returning prematurely) |
1245 fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColo
r); | 1247 fragBuilder->codeAppendf("\t%s = vec4(0.0,0.0,0.0,0.0);\n", args.fOutputColo
r); |
1246 | 1248 |
1247 // p = coords2D | 1249 // p = coords2D |
1248 // e = center end | 1250 // e = center end |
1249 // r = radius end | 1251 // r = radius end |
1250 // A = dot(e, e) - r^2 + 2 * r - 1 | 1252 // A = dot(e, e) - r^2 + 2 * r - 1 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 return CircleInside2PtConicalEffect::Make(ctx, shader, matrix, tm, info)
; | 1358 return CircleInside2PtConicalEffect::Make(ctx, shader, matrix, tm, info)
; |
1357 } else if (type == kEdge_ConicalType) { | 1359 } else if (type == kEdge_ConicalType) { |
1358 set_matrix_edge_conical(shader, &matrix); | 1360 set_matrix_edge_conical(shader, &matrix); |
1359 return Edge2PtConicalEffect::Make(ctx, shader, matrix, tm); | 1361 return Edge2PtConicalEffect::Make(ctx, shader, matrix, tm); |
1360 } else { | 1362 } else { |
1361 return CircleOutside2PtConicalEffect::Make(ctx, shader, matrix, tm, info
); | 1363 return CircleOutside2PtConicalEffect::Make(ctx, shader, matrix, tm, info
); |
1362 } | 1364 } |
1363 } | 1365 } |
1364 | 1366 |
1365 #endif | 1367 #endif |
OLD | NEW |