OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
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 "SkLightingImageFilter.h" | 8 #include "SkLightingImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 /////////////////////////////////////////////////////////////////////////////// | 443 /////////////////////////////////////////////////////////////////////////////// |
444 | 444 |
445 class GrGLLight { | 445 class GrGLLight { |
446 public: | 446 public: |
447 virtual ~GrGLLight() {} | 447 virtual ~GrGLLight() {} |
448 | 448 |
449 /** | 449 /** |
450 * This is called by GrGLLightingEffect::emitCode() before either of the two
virtual functions | 450 * This is called by GrGLLightingEffect::emitCode() before either of the two
virtual functions |
451 * below. It adds a vec3f uniform visible in the FS that represents the cons
tant light color. | 451 * below. It adds a vec3f uniform visible in the FS that represents the cons
tant light color. |
452 */ | 452 */ |
453 void emitLightColorUniform(GrGLProgramBuilder*); | 453 void emitLightColorUniform(GrGLFPBuilder*); |
454 | 454 |
455 /** | 455 /** |
456 * These two functions are called from GrGLLightingEffect's emitCode() funct
ion. | 456 * These two functions are called from GrGLLightingEffect's emitCode() funct
ion. |
457 * emitSurfaceToLight places an expression in param out that is the vector f
rom the surface to | 457 * emitSurfaceToLight places an expression in param out that is the vector f
rom the surface to |
458 * the light. The expression will be used in the FS. emitLightColor writes a
n expression into | 458 * the light. The expression will be used in the FS. emitLightColor writes a
n expression into |
459 * the FS that is the color of the light. Either function may add functions
and/or uniforms to | 459 * the FS that is the color of the light. Either function may add functions
and/or uniforms to |
460 * the FS. The default of emitLightColor appends the name of the constant li
ght color uniform | 460 * the FS. The default of emitLightColor appends the name of the constant li
ght color uniform |
461 * and so this function only needs to be overridden if the light color varie
s spatially. | 461 * and so this function only needs to be overridden if the light color varie
s spatially. |
462 */ | 462 */ |
463 virtual void emitSurfaceToLight(GrGLProgramBuilder*, const char* z) = 0; | 463 virtual void emitSurfaceToLight(GrGLFPBuilder*, const char* z) = 0; |
464 virtual void emitLightColor(GrGLProgramBuilder*, const char *surfaceToLight)
; | 464 virtual void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight); |
465 | 465 |
466 // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig
ht must call | 466 // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig
ht must call |
467 // INHERITED::setData(). | 467 // INHERITED::setData(). |
468 virtual void setData(const GrGLProgramDataManager&, | 468 virtual void setData(const GrGLProgramDataManager&, |
469 const SkLight* light) const; | 469 const SkLight* light) const; |
470 | 470 |
471 protected: | 471 protected: |
472 /** | 472 /** |
473 * Gets the constant light color uniform. Subclasses can use this in their e
mitLightColor | 473 * Gets the constant light color uniform. Subclasses can use this in their e
mitLightColor |
474 * function. | 474 * function. |
475 */ | 475 */ |
476 UniformHandle lightColorUni() const { return fColorUni; } | 476 UniformHandle lightColorUni() const { return fColorUni; } |
477 | 477 |
478 private: | 478 private: |
479 UniformHandle fColorUni; | 479 UniformHandle fColorUni; |
480 | 480 |
481 typedef SkRefCnt INHERITED; | 481 typedef SkRefCnt INHERITED; |
482 }; | 482 }; |
483 | 483 |
484 /////////////////////////////////////////////////////////////////////////////// | 484 /////////////////////////////////////////////////////////////////////////////// |
485 | 485 |
486 class GrGLDistantLight : public GrGLLight { | 486 class GrGLDistantLight : public GrGLLight { |
487 public: | 487 public: |
488 virtual ~GrGLDistantLight() {} | 488 virtual ~GrGLDistantLight() {} |
489 virtual void setData(const GrGLProgramDataManager&, | 489 virtual void setData(const GrGLProgramDataManager&, |
490 const SkLight* light) const SK_OVERRIDE; | 490 const SkLight* light) const SK_OVERRIDE; |
491 virtual void emitSurfaceToLight(GrGLProgramBuilder*, const char* z) SK_OVERR
IDE; | 491 virtual void emitSurfaceToLight(GrGLFPBuilder*, const char* z) SK_OVERRIDE; |
492 | 492 |
493 private: | 493 private: |
494 typedef GrGLLight INHERITED; | 494 typedef GrGLLight INHERITED; |
495 UniformHandle fDirectionUni; | 495 UniformHandle fDirectionUni; |
496 }; | 496 }; |
497 | 497 |
498 /////////////////////////////////////////////////////////////////////////////// | 498 /////////////////////////////////////////////////////////////////////////////// |
499 | 499 |
500 class GrGLPointLight : public GrGLLight { | 500 class GrGLPointLight : public GrGLLight { |
501 public: | 501 public: |
502 virtual ~GrGLPointLight() {} | 502 virtual ~GrGLPointLight() {} |
503 virtual void setData(const GrGLProgramDataManager&, | 503 virtual void setData(const GrGLProgramDataManager&, |
504 const SkLight* light) const SK_OVERRIDE; | 504 const SkLight* light) const SK_OVERRIDE; |
505 virtual void emitSurfaceToLight(GrGLProgramBuilder*, const char* z) SK_OVERR
IDE; | 505 virtual void emitSurfaceToLight(GrGLFPBuilder*, const char* z) SK_OVERRIDE; |
506 | 506 |
507 private: | 507 private: |
508 typedef GrGLLight INHERITED; | 508 typedef GrGLLight INHERITED; |
509 UniformHandle fLocationUni; | 509 UniformHandle fLocationUni; |
510 }; | 510 }; |
511 | 511 |
512 /////////////////////////////////////////////////////////////////////////////// | 512 /////////////////////////////////////////////////////////////////////////////// |
513 | 513 |
514 class GrGLSpotLight : public GrGLLight { | 514 class GrGLSpotLight : public GrGLLight { |
515 public: | 515 public: |
516 virtual ~GrGLSpotLight() {} | 516 virtual ~GrGLSpotLight() {} |
517 virtual void setData(const GrGLProgramDataManager&, | 517 virtual void setData(const GrGLProgramDataManager&, |
518 const SkLight* light) const SK_OVERRIDE; | 518 const SkLight* light) const SK_OVERRIDE; |
519 virtual void emitSurfaceToLight(GrGLProgramBuilder*, const char* z) SK_OVERR
IDE; | 519 virtual void emitSurfaceToLight(GrGLFPBuilder*, const char* z) SK_OVERRIDE; |
520 virtual void emitLightColor(GrGLProgramBuilder*, const char *surfaceToLight)
SK_OVERRIDE; | 520 virtual void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight) SK_O
VERRIDE; |
521 | 521 |
522 private: | 522 private: |
523 typedef GrGLLight INHERITED; | 523 typedef GrGLLight INHERITED; |
524 | 524 |
525 SkString fLightColorFunc; | 525 SkString fLightColorFunc; |
526 UniformHandle fLocationUni; | 526 UniformHandle fLocationUni; |
527 UniformHandle fExponentUni; | 527 UniformHandle fExponentUni; |
528 UniformHandle fCosOuterConeAngleUni; | 528 UniformHandle fCosOuterConeAngleUni; |
529 UniformHandle fCosInnerConeAngleUni; | 529 UniformHandle fCosInnerConeAngleUni; |
530 UniformHandle fConeScaleUni; | 530 UniformHandle fConeScaleUni; |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 } | 1221 } |
1222 } | 1222 } |
1223 | 1223 |
1224 } | 1224 } |
1225 | 1225 |
1226 class GrGLLightingEffect : public GrGLFragmentProcessor { | 1226 class GrGLLightingEffect : public GrGLFragmentProcessor { |
1227 public: | 1227 public: |
1228 GrGLLightingEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 1228 GrGLLightingEffect(const GrBackendProcessorFactory&, const GrProcessor&); |
1229 virtual ~GrGLLightingEffect(); | 1229 virtual ~GrGLLightingEffect(); |
1230 | 1230 |
1231 virtual void emitCode(GrGLProgramBuilder*, | 1231 virtual void emitCode(GrGLFPBuilder*, |
1232 const GrFragmentProcessor&, | 1232 const GrFragmentProcessor&, |
1233 const GrProcessorKey&, | 1233 const GrProcessorKey&, |
1234 const char* outputColor, | 1234 const char* outputColor, |
1235 const char* inputColor, | 1235 const char* inputColor, |
1236 const TransformedCoordsArray&, | 1236 const TransformedCoordsArray&, |
1237 const TextureSamplerArray&) SK_OVERRIDE; | 1237 const TextureSamplerArray&) SK_OVERRIDE; |
1238 | 1238 |
1239 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder* b); | 1239 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder* b); |
1240 | 1240 |
1241 /** | 1241 /** |
1242 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); | 1242 * Subclasses of GrGLLightingEffect must call INHERITED::setData(); |
1243 */ | 1243 */ |
1244 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 1244 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
1245 | 1245 |
1246 protected: | 1246 protected: |
1247 virtual void emitLightFunc(GrGLProgramBuilder*, SkString* funcName) = 0; | 1247 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0; |
1248 | 1248 |
1249 private: | 1249 private: |
1250 typedef GrGLFragmentProcessor INHERITED; | 1250 typedef GrGLFragmentProcessor INHERITED; |
1251 | 1251 |
1252 UniformHandle fImageIncrementUni; | 1252 UniformHandle fImageIncrementUni; |
1253 UniformHandle fSurfaceScaleUni; | 1253 UniformHandle fSurfaceScaleUni; |
1254 GrGLLight* fLight; | 1254 GrGLLight* fLight; |
1255 }; | 1255 }; |
1256 | 1256 |
1257 /////////////////////////////////////////////////////////////////////////////// | 1257 /////////////////////////////////////////////////////////////////////////////// |
1258 | 1258 |
1259 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { | 1259 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { |
1260 public: | 1260 public: |
1261 GrGLDiffuseLightingEffect(const GrBackendProcessorFactory&, const GrProcesso
r&); | 1261 GrGLDiffuseLightingEffect(const GrBackendProcessorFactory&, const GrProcesso
r&); |
1262 virtual void emitLightFunc(GrGLProgramBuilder*, SkString* funcName) SK_OVERR
IDE; | 1262 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) SK_OVERRIDE; |
1263 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 1263 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
1264 | 1264 |
1265 private: | 1265 private: |
1266 typedef GrGLLightingEffect INHERITED; | 1266 typedef GrGLLightingEffect INHERITED; |
1267 | 1267 |
1268 UniformHandle fKDUni; | 1268 UniformHandle fKDUni; |
1269 }; | 1269 }; |
1270 | 1270 |
1271 /////////////////////////////////////////////////////////////////////////////// | 1271 /////////////////////////////////////////////////////////////////////////////// |
1272 | 1272 |
1273 class GrGLSpecularLightingEffect : public GrGLLightingEffect { | 1273 class GrGLSpecularLightingEffect : public GrGLLightingEffect { |
1274 public: | 1274 public: |
1275 GrGLSpecularLightingEffect(const GrBackendProcessorFactory&, const GrProcess
or&); | 1275 GrGLSpecularLightingEffect(const GrBackendProcessorFactory&, const GrProcess
or&); |
1276 virtual void emitLightFunc(GrGLProgramBuilder*, SkString* funcName) SK_OVERR
IDE; | 1276 virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) SK_OVERRIDE; |
1277 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 1277 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
1278 | 1278 |
1279 private: | 1279 private: |
1280 typedef GrGLLightingEffect INHERITED; | 1280 typedef GrGLLightingEffect INHERITED; |
1281 | 1281 |
1282 UniformHandle fKSUni; | 1282 UniformHandle fKSUni; |
1283 UniformHandle fShininessUni; | 1283 UniformHandle fShininessUni; |
1284 }; | 1284 }; |
1285 | 1285 |
1286 /////////////////////////////////////////////////////////////////////////////// | 1286 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1354 const GrProcessor& fp) | 1354 const GrProcessor& fp) |
1355 : INHERITED(factory) { | 1355 : INHERITED(factory) { |
1356 const GrLightingEffect& m = fp.cast<GrLightingEffect>(); | 1356 const GrLightingEffect& m = fp.cast<GrLightingEffect>(); |
1357 fLight = m.light()->createGLLight(); | 1357 fLight = m.light()->createGLLight(); |
1358 } | 1358 } |
1359 | 1359 |
1360 GrGLLightingEffect::~GrGLLightingEffect() { | 1360 GrGLLightingEffect::~GrGLLightingEffect() { |
1361 delete fLight; | 1361 delete fLight; |
1362 } | 1362 } |
1363 | 1363 |
1364 void GrGLLightingEffect::emitCode(GrGLProgramBuilder* builder, | 1364 void GrGLLightingEffect::emitCode(GrGLFPBuilder* builder, |
1365 const GrFragmentProcessor&, | 1365 const GrFragmentProcessor&, |
1366 const GrProcessorKey& key, | 1366 const GrProcessorKey& key, |
1367 const char* outputColor, | 1367 const char* outputColor, |
1368 const char* inputColor, | 1368 const char* inputColor, |
1369 const TransformedCoordsArray& coords, | 1369 const TransformedCoordsArray& coords, |
1370 const TextureSamplerArray& samplers) { | 1370 const TextureSamplerArray& samplers) { |
1371 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, | 1371 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, |
1372 kVec2f_GrSLType, | 1372 kVec2f_GrSLType, |
1373 "ImageIncrement"); | 1373 "ImageIncrement"); |
1374 fSurfaceScaleUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, | 1374 fSurfaceScaleUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibil
ity, |
1375 kFloat_GrSLType, | 1375 kFloat_GrSLType, |
1376 "SurfaceScale"); | 1376 "SurfaceScale"); |
1377 fLight->emitLightColorUniform(builder); | 1377 fLight->emitLightColorUniform(builder); |
1378 SkString lightFunc; | 1378 SkString lightFunc; |
1379 this->emitLightFunc(builder, &lightFunc); | 1379 this->emitLightFunc(builder, &lightFunc); |
1380 static const GrGLShaderVar gSobelArgs[] = { | 1380 static const GrGLShaderVar gSobelArgs[] = { |
1381 GrGLShaderVar("a", kFloat_GrSLType), | 1381 GrGLShaderVar("a", kFloat_GrSLType), |
1382 GrGLShaderVar("b", kFloat_GrSLType), | 1382 GrGLShaderVar("b", kFloat_GrSLType), |
1383 GrGLShaderVar("c", kFloat_GrSLType), | 1383 GrGLShaderVar("c", kFloat_GrSLType), |
1384 GrGLShaderVar("d", kFloat_GrSLType), | 1384 GrGLShaderVar("d", kFloat_GrSLType), |
1385 GrGLShaderVar("e", kFloat_GrSLType), | 1385 GrGLShaderVar("e", kFloat_GrSLType), |
1386 GrGLShaderVar("f", kFloat_GrSLType), | 1386 GrGLShaderVar("f", kFloat_GrSLType), |
1387 GrGLShaderVar("scale", kFloat_GrSLType), | 1387 GrGLShaderVar("scale", kFloat_GrSLType), |
1388 }; | 1388 }; |
1389 SkString sobelFuncName; | 1389 SkString sobelFuncName; |
1390 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 1390 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
1391 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); | 1391 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); |
1392 | 1392 |
1393 fsBuilder->emitFunction(kFloat_GrSLType, | 1393 fsBuilder->emitFunction(kFloat_GrSLType, |
1394 "sobel", | 1394 "sobel", |
1395 SK_ARRAY_COUNT(gSobelArgs), | 1395 SK_ARRAY_COUNT(gSobelArgs), |
1396 gSobelArgs, | 1396 gSobelArgs, |
1397 "\treturn (-a + b - 2.0 * c + 2.0 * d -e + f) * scal
e;\n", | 1397 "\treturn (-a + b - 2.0 * c + 2.0 * d -e + f) * scal
e;\n", |
1398 &sobelFuncName); | 1398 &sobelFuncName); |
1399 static const GrGLShaderVar gPointToNormalArgs[] = { | 1399 static const GrGLShaderVar gPointToNormalArgs[] = { |
1400 GrGLShaderVar("x", kFloat_GrSLType), | 1400 GrGLShaderVar("x", kFloat_GrSLType), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 | 1476 |
1477 /////////////////////////////////////////////////////////////////////////////// | 1477 /////////////////////////////////////////////////////////////////////////////// |
1478 | 1478 |
1479 /////////////////////////////////////////////////////////////////////////////// | 1479 /////////////////////////////////////////////////////////////////////////////// |
1480 | 1480 |
1481 GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrBackendProcessorFac
tory& factory, | 1481 GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrBackendProcessorFac
tory& factory, |
1482 const GrProcessor& proc) | 1482 const GrProcessor& proc) |
1483 : INHERITED(factory, proc) { | 1483 : INHERITED(factory, proc) { |
1484 } | 1484 } |
1485 | 1485 |
1486 void GrGLDiffuseLightingEffect::emitLightFunc(GrGLProgramBuilder* builder, SkStr
ing* funcName) { | 1486 void GrGLDiffuseLightingEffect::emitLightFunc(GrGLFPBuilder* builder, SkString*
funcName) { |
1487 const char* kd; | 1487 const char* kd; |
1488 fKDUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1488 fKDUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
1489 kFloat_GrSLType, | 1489 kFloat_GrSLType, |
1490 "KD", | 1490 "KD", |
1491 &kd); | 1491 &kd); |
1492 | 1492 |
1493 static const GrGLShaderVar gLightArgs[] = { | 1493 static const GrGLShaderVar gLightArgs[] = { |
1494 GrGLShaderVar("normal", kVec3f_GrSLType), | 1494 GrGLShaderVar("normal", kVec3f_GrSLType), |
1495 GrGLShaderVar("surfaceToLight", kVec3f_GrSLType), | 1495 GrGLShaderVar("surfaceToLight", kVec3f_GrSLType), |
1496 GrGLShaderVar("lightColor", kVec3f_GrSLType) | 1496 GrGLShaderVar("lightColor", kVec3f_GrSLType) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1555 light, surfaceScale, matrix, ks, shi
niness); | 1555 light, surfaceScale, matrix, ks, shi
niness); |
1556 } | 1556 } |
1557 | 1557 |
1558 /////////////////////////////////////////////////////////////////////////////// | 1558 /////////////////////////////////////////////////////////////////////////////// |
1559 | 1559 |
1560 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrBackendProcessorF
actory& factory, | 1560 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrBackendProcessorF
actory& factory, |
1561 const GrProcessor& proc) | 1561 const GrProcessor& proc) |
1562 : INHERITED(factory, proc) { | 1562 : INHERITED(factory, proc) { |
1563 } | 1563 } |
1564 | 1564 |
1565 void GrGLSpecularLightingEffect::emitLightFunc(GrGLProgramBuilder* builder, SkSt
ring* funcName) { | 1565 void GrGLSpecularLightingEffect::emitLightFunc(GrGLFPBuilder* builder, SkString*
funcName) { |
1566 const char* ks; | 1566 const char* ks; |
1567 const char* shininess; | 1567 const char* shininess; |
1568 | 1568 |
1569 fKSUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1569 fKSUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
1570 kFloat_GrSLType, "KS", &ks); | 1570 kFloat_GrSLType, "KS", &ks); |
1571 fShininessUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, | 1571 fShininessUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, |
1572 kFloat_GrSLType, "Shininess", &shininess
); | 1572 kFloat_GrSLType, "Shininess", &shininess
); |
1573 | 1573 |
1574 static const GrGLShaderVar gLightArgs[] = { | 1574 static const GrGLShaderVar gLightArgs[] = { |
1575 GrGLShaderVar("normal", kVec3f_GrSLType), | 1575 GrGLShaderVar("normal", kVec3f_GrSLType), |
(...skipping 15 matching lines...) Expand all Loading... |
1591 | 1591 |
1592 void GrGLSpecularLightingEffect::setData(const GrGLProgramDataManager& pdman, | 1592 void GrGLSpecularLightingEffect::setData(const GrGLProgramDataManager& pdman, |
1593 const GrProcessor& effect) { | 1593 const GrProcessor& effect) { |
1594 INHERITED::setData(pdman, effect); | 1594 INHERITED::setData(pdman, effect); |
1595 const GrSpecularLightingEffect& spec = effect.cast<GrSpecularLightingEffect>
(); | 1595 const GrSpecularLightingEffect& spec = effect.cast<GrSpecularLightingEffect>
(); |
1596 pdman.set1f(fKSUni, spec.ks()); | 1596 pdman.set1f(fKSUni, spec.ks()); |
1597 pdman.set1f(fShininessUni, spec.shininess()); | 1597 pdman.set1f(fShininessUni, spec.shininess()); |
1598 } | 1598 } |
1599 | 1599 |
1600 /////////////////////////////////////////////////////////////////////////////// | 1600 /////////////////////////////////////////////////////////////////////////////// |
1601 void GrGLLight::emitLightColorUniform(GrGLProgramBuilder* builder) { | 1601 void GrGLLight::emitLightColorUniform(GrGLFPBuilder* builder) { |
1602 fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1602 fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
1603 kVec3f_GrSLType, "LightColor"); | 1603 kVec3f_GrSLType, "LightColor"); |
1604 } | 1604 } |
1605 | 1605 |
1606 void GrGLLight::emitLightColor(GrGLProgramBuilder* builder, | 1606 void GrGLLight::emitLightColor(GrGLFPBuilder* builder, |
1607 const char *surfaceToLight) { | 1607 const char *surfaceToLight) { |
1608 builder->getFragmentShaderBuilder()->codeAppend(builder->getUniformCStr(this
->lightColorUni())); | 1608 builder->getFragmentShaderBuilder()->codeAppend(builder->getUniformCStr(this
->lightColorUni())); |
1609 } | 1609 } |
1610 | 1610 |
1611 void GrGLLight::setData(const GrGLProgramDataManager& pdman, | 1611 void GrGLLight::setData(const GrGLProgramDataManager& pdman, |
1612 const SkLight* light) const { | 1612 const SkLight* light) const { |
1613 setUniformPoint3(pdman, fColorUni, light->color() * SkScalarInvert(SkIntToSc
alar(255))); | 1613 setUniformPoint3(pdman, fColorUni, light->color() * SkScalarInvert(SkIntToSc
alar(255))); |
1614 } | 1614 } |
1615 | 1615 |
1616 /////////////////////////////////////////////////////////////////////////////// | 1616 /////////////////////////////////////////////////////////////////////////////// |
1617 | 1617 |
1618 void GrGLDistantLight::setData(const GrGLProgramDataManager& pdman, | 1618 void GrGLDistantLight::setData(const GrGLProgramDataManager& pdman, |
1619 const SkLight* light) const { | 1619 const SkLight* light) const { |
1620 INHERITED::setData(pdman, light); | 1620 INHERITED::setData(pdman, light); |
1621 SkASSERT(light->type() == SkLight::kDistant_LightType); | 1621 SkASSERT(light->type() == SkLight::kDistant_LightType); |
1622 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh
t); | 1622 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh
t); |
1623 setUniformNormal3(pdman, fDirectionUni, distantLight->direction()); | 1623 setUniformNormal3(pdman, fDirectionUni, distantLight->direction()); |
1624 } | 1624 } |
1625 | 1625 |
1626 void GrGLDistantLight::emitSurfaceToLight(GrGLProgramBuilder* builder, const cha
r* z) { | 1626 void GrGLDistantLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z)
{ |
1627 const char* dir; | 1627 const char* dir; |
1628 fDirectionUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, kVec3f_GrSLType, | 1628 fDirectionUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility
, kVec3f_GrSLType, |
1629 "LightDirection", &dir); | 1629 "LightDirection", &dir); |
1630 builder->getFragmentShaderBuilder()->codeAppend(dir); | 1630 builder->getFragmentShaderBuilder()->codeAppend(dir); |
1631 } | 1631 } |
1632 | 1632 |
1633 /////////////////////////////////////////////////////////////////////////////// | 1633 /////////////////////////////////////////////////////////////////////////////// |
1634 | 1634 |
1635 void GrGLPointLight::setData(const GrGLProgramDataManager& pdman, | 1635 void GrGLPointLight::setData(const GrGLProgramDataManager& pdman, |
1636 const SkLight* light) const { | 1636 const SkLight* light) const { |
1637 INHERITED::setData(pdman, light); | 1637 INHERITED::setData(pdman, light); |
1638 SkASSERT(light->type() == SkLight::kPoint_LightType); | 1638 SkASSERT(light->type() == SkLight::kPoint_LightType); |
1639 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); | 1639 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); |
1640 setUniformPoint3(pdman, fLocationUni, pointLight->location()); | 1640 setUniformPoint3(pdman, fLocationUni, pointLight->location()); |
1641 } | 1641 } |
1642 | 1642 |
1643 void GrGLPointLight::emitSurfaceToLight(GrGLProgramBuilder* builder, const char*
z) { | 1643 void GrGLPointLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) { |
1644 const char* loc; | 1644 const char* loc; |
1645 fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, | 1645 fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, |
1646 "LightLocation", &loc); | 1646 "LightLocation", &loc); |
1647 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 1647 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
1648 fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", | 1648 fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", |
1649 loc, fsBuilder->fragmentPosition(), z); | 1649 loc, fsBuilder->fragmentPosition(), z); |
1650 } | 1650 } |
1651 | 1651 |
1652 /////////////////////////////////////////////////////////////////////////////// | 1652 /////////////////////////////////////////////////////////////////////////////// |
1653 | 1653 |
1654 void GrGLSpotLight::setData(const GrGLProgramDataManager& pdman, | 1654 void GrGLSpotLight::setData(const GrGLProgramDataManager& pdman, |
1655 const SkLight* light) const { | 1655 const SkLight* light) const { |
1656 INHERITED::setData(pdman, light); | 1656 INHERITED::setData(pdman, light); |
1657 SkASSERT(light->type() == SkLight::kSpot_LightType); | 1657 SkASSERT(light->type() == SkLight::kSpot_LightType); |
1658 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); | 1658 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); |
1659 setUniformPoint3(pdman, fLocationUni, spotLight->location()); | 1659 setUniformPoint3(pdman, fLocationUni, spotLight->location()); |
1660 pdman.set1f(fExponentUni, spotLight->specularExponent()); | 1660 pdman.set1f(fExponentUni, spotLight->specularExponent()); |
1661 pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); | 1661 pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); |
1662 pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); | 1662 pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); |
1663 pdman.set1f(fConeScaleUni, spotLight->coneScale()); | 1663 pdman.set1f(fConeScaleUni, spotLight->coneScale()); |
1664 setUniformNormal3(pdman, fSUni, spotLight->s()); | 1664 setUniformNormal3(pdman, fSUni, spotLight->s()); |
1665 } | 1665 } |
1666 | 1666 |
1667 void GrGLSpotLight::emitSurfaceToLight(GrGLProgramBuilder* builder, const char*
z) { | 1667 void GrGLSpotLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) { |
1668 const char* location; | 1668 const char* location; |
1669 fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1669 fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
1670 kVec3f_GrSLType, "LightLocation", &locati
on); | 1670 kVec3f_GrSLType, "LightLocation", &locati
on); |
1671 | 1671 |
1672 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 1672 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
1673 fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", | 1673 fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", |
1674 location, fsBuilder->fragmentPosition(), z); | 1674 location, fsBuilder->fragmentPosition(), z); |
1675 } | 1675 } |
1676 | 1676 |
1677 void GrGLSpotLight::emitLightColor(GrGLProgramBuilder* builder, | 1677 void GrGLSpotLight::emitLightColor(GrGLFPBuilder* builder, |
1678 const char *surfaceToLight) { | 1678 const char *surfaceToLight) { |
1679 | 1679 |
1680 const char* color = builder->getUniformCStr(this->lightColorUni()); // creat
ed by parent class. | 1680 const char* color = builder->getUniformCStr(this->lightColorUni()); // creat
ed by parent class. |
1681 | 1681 |
1682 const char* exponent; | 1682 const char* exponent; |
1683 const char* cosInner; | 1683 const char* cosInner; |
1684 const char* cosOuter; | 1684 const char* cosOuter; |
1685 const char* coneScale; | 1685 const char* coneScale; |
1686 const char* s; | 1686 const char* s; |
1687 fExponentUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1687 fExponentUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
(...skipping 14 matching lines...) Expand all Loading... |
1702 lightColorBody.appendf("\tfloat cosAngle = -dot(surfaceToLight, %s);\n", s); | 1702 lightColorBody.appendf("\tfloat cosAngle = -dot(surfaceToLight, %s);\n", s); |
1703 lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosOuter); | 1703 lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosOuter); |
1704 lightColorBody.appendf("\t\treturn vec3(0);\n"); | 1704 lightColorBody.appendf("\t\treturn vec3(0);\n"); |
1705 lightColorBody.appendf("\t}\n"); | 1705 lightColorBody.appendf("\t}\n"); |
1706 lightColorBody.appendf("\tfloat scale = pow(cosAngle, %s);\n", exponent); | 1706 lightColorBody.appendf("\tfloat scale = pow(cosAngle, %s);\n", exponent); |
1707 lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosInner); | 1707 lightColorBody.appendf("\tif (cosAngle < %s) {\n", cosInner); |
1708 lightColorBody.appendf("\t\treturn %s * scale * (cosAngle - %s) * %s;\n", | 1708 lightColorBody.appendf("\t\treturn %s * scale * (cosAngle - %s) * %s;\n", |
1709 color, cosOuter, coneScale); | 1709 color, cosOuter, coneScale); |
1710 lightColorBody.appendf("\t}\n"); | 1710 lightColorBody.appendf("\t}\n"); |
1711 lightColorBody.appendf("\treturn %s;\n", color); | 1711 lightColorBody.appendf("\treturn %s;\n", color); |
1712 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 1712 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
1713 fsBuilder->emitFunction(kVec3f_GrSLType, | 1713 fsBuilder->emitFunction(kVec3f_GrSLType, |
1714 "lightColor", | 1714 "lightColor", |
1715 SK_ARRAY_COUNT(gLightColorArgs), | 1715 SK_ARRAY_COUNT(gLightColorArgs), |
1716 gLightColorArgs, | 1716 gLightColorArgs, |
1717 lightColorBody.c_str(), | 1717 lightColorBody.c_str(), |
1718 &fLightColorFunc); | 1718 &fLightColorFunc); |
1719 | 1719 |
1720 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1720 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1721 } | 1721 } |
1722 | 1722 |
1723 #endif | 1723 #endif |
1724 | 1724 |
1725 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1725 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1726 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1726 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1727 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1727 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1728 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1728 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |