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 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 | 653 |
654 /** | 654 /** |
655 * These two functions are called from GrGLLightingEffect's emitCode() funct
ion. | 655 * These two functions are called from GrGLLightingEffect's emitCode() funct
ion. |
656 * emitSurfaceToLight places an expression in param out that is the vector f
rom the surface to | 656 * emitSurfaceToLight places an expression in param out that is the vector f
rom the surface to |
657 * the light. The expression will be used in the FS. emitLightColor writes a
n expression into | 657 * the light. The expression will be used in the FS. emitLightColor writes a
n expression into |
658 * the FS that is the color of the light. Either function may add functions
and/or uniforms to | 658 * the FS that is the color of the light. Either function may add functions
and/or uniforms to |
659 * the FS. The default of emitLightColor appends the name of the constant li
ght color uniform | 659 * the FS. The default of emitLightColor appends the name of the constant li
ght color uniform |
660 * and so this function only needs to be overridden if the light color varie
s spatially. | 660 * and so this function only needs to be overridden if the light color varie
s spatially. |
661 */ | 661 */ |
662 virtual void emitSurfaceToLight(GrGLSLUniformHandler*, | 662 virtual void emitSurfaceToLight(GrGLSLUniformHandler*, |
663 GrGLSLFragmentBuilder*, | 663 GrGLSLFPFragmentBuilder*, |
664 const char* z) = 0; | 664 const char* z) = 0; |
665 virtual void emitLightColor(GrGLSLUniformHandler*, | 665 virtual void emitLightColor(GrGLSLUniformHandler*, |
666 GrGLSLFragmentBuilder*, | 666 GrGLSLFPFragmentBuilder*, |
667 const char *surfaceToLight); | 667 const char *surfaceToLight); |
668 | 668 |
669 // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig
ht must call | 669 // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig
ht must call |
670 // INHERITED::setData(). | 670 // INHERITED::setData(). |
671 virtual void setData(const GrGLSLProgramDataManager&, const SkImageFilterLig
ht* light) const; | 671 virtual void setData(const GrGLSLProgramDataManager&, const SkImageFilterLig
ht* light) const; |
672 | 672 |
673 protected: | 673 protected: |
674 /** | 674 /** |
675 * Gets the constant light color uniform. Subclasses can use this in their e
mitLightColor | 675 * Gets the constant light color uniform. Subclasses can use this in their e
mitLightColor |
676 * function. | 676 * function. |
677 */ | 677 */ |
678 UniformHandle lightColorUni() const { return fColorUni; } | 678 UniformHandle lightColorUni() const { return fColorUni; } |
679 | 679 |
680 private: | 680 private: |
681 UniformHandle fColorUni; | 681 UniformHandle fColorUni; |
682 | 682 |
683 typedef SkRefCnt INHERITED; | 683 typedef SkRefCnt INHERITED; |
684 }; | 684 }; |
685 | 685 |
686 /////////////////////////////////////////////////////////////////////////////// | 686 /////////////////////////////////////////////////////////////////////////////// |
687 | 687 |
688 class GrGLDistantLight : public GrGLLight { | 688 class GrGLDistantLight : public GrGLLight { |
689 public: | 689 public: |
690 virtual ~GrGLDistantLight() {} | 690 virtual ~GrGLDistantLight() {} |
691 void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh
t) const override; | 691 void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh
t) const override; |
692 void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, const
char* z) override; | 692 void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, con
st char* z) override; |
693 | 693 |
694 private: | 694 private: |
695 typedef GrGLLight INHERITED; | 695 typedef GrGLLight INHERITED; |
696 UniformHandle fDirectionUni; | 696 UniformHandle fDirectionUni; |
697 }; | 697 }; |
698 | 698 |
699 /////////////////////////////////////////////////////////////////////////////// | 699 /////////////////////////////////////////////////////////////////////////////// |
700 | 700 |
701 class GrGLPointLight : public GrGLLight { | 701 class GrGLPointLight : public GrGLLight { |
702 public: | 702 public: |
703 virtual ~GrGLPointLight() {} | 703 virtual ~GrGLPointLight() {} |
704 void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh
t) const override; | 704 void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh
t) const override; |
705 void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, const
char* z) override; | 705 void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, con
st char* z) override; |
706 | 706 |
707 private: | 707 private: |
708 typedef GrGLLight INHERITED; | 708 typedef GrGLLight INHERITED; |
709 UniformHandle fLocationUni; | 709 UniformHandle fLocationUni; |
710 }; | 710 }; |
711 | 711 |
712 /////////////////////////////////////////////////////////////////////////////// | 712 /////////////////////////////////////////////////////////////////////////////// |
713 | 713 |
714 class GrGLSpotLight : public GrGLLight { | 714 class GrGLSpotLight : public GrGLLight { |
715 public: | 715 public: |
716 virtual ~GrGLSpotLight() {} | 716 virtual ~GrGLSpotLight() {} |
717 void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh
t) const override; | 717 void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* ligh
t) const override; |
718 void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, const
char* z) override; | 718 void emitSurfaceToLight(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, con
st char* z) override; |
719 void emitLightColor(GrGLSLUniformHandler*, | 719 void emitLightColor(GrGLSLUniformHandler*, |
720 GrGLSLFragmentBuilder*, | 720 GrGLSLFPFragmentBuilder*, |
721 const char *surfaceToLight) override; | 721 const char *surfaceToLight) override; |
722 | 722 |
723 private: | 723 private: |
724 typedef GrGLLight INHERITED; | 724 typedef GrGLLight INHERITED; |
725 | 725 |
726 SkString fLightColorFunc; | 726 SkString fLightColorFunc; |
727 UniformHandle fLocationUni; | 727 UniformHandle fLocationUni; |
728 UniformHandle fExponentUni; | 728 UniformHandle fExponentUni; |
729 UniformHandle fCosOuterConeAngleUni; | 729 UniformHandle fCosOuterConeAngleUni; |
730 UniformHandle fCosInnerConeAngleUni; | 730 UniformHandle fCosInnerConeAngleUni; |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 | 1577 |
1578 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); | 1578 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); |
1579 | 1579 |
1580 protected: | 1580 protected: |
1581 /** | 1581 /** |
1582 * Subclasses of GrGLLightingEffect must call INHERITED::onSetData(); | 1582 * Subclasses of GrGLLightingEffect must call INHERITED::onSetData(); |
1583 */ | 1583 */ |
1584 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 1584 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
1585 | 1585 |
1586 virtual void emitLightFunc(GrGLSLUniformHandler*, | 1586 virtual void emitLightFunc(GrGLSLUniformHandler*, |
1587 GrGLSLFragmentBuilder*, | 1587 GrGLSLFPFragmentBuilder*, |
1588 SkString* funcName) = 0; | 1588 SkString* funcName) = 0; |
1589 | 1589 |
1590 private: | 1590 private: |
1591 typedef GrGLSLFragmentProcessor INHERITED; | 1591 typedef GrGLSLFragmentProcessor INHERITED; |
1592 | 1592 |
1593 UniformHandle fImageIncrementUni; | 1593 UniformHandle fImageIncrementUni; |
1594 UniformHandle fSurfaceScaleUni; | 1594 UniformHandle fSurfaceScaleUni; |
1595 GrTextureDomain::GLDomain fDomain; | 1595 GrTextureDomain::GLDomain fDomain; |
1596 GrGLLight* fLight; | 1596 GrGLLight* fLight; |
1597 }; | 1597 }; |
1598 | 1598 |
1599 /////////////////////////////////////////////////////////////////////////////// | 1599 /////////////////////////////////////////////////////////////////////////////// |
1600 | 1600 |
1601 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { | 1601 class GrGLDiffuseLightingEffect : public GrGLLightingEffect { |
1602 public: | 1602 public: |
1603 void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, SkString*
funcName) override; | 1603 void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, SkString
* funcName) override; |
1604 | 1604 |
1605 protected: | 1605 protected: |
1606 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 1606 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
1607 | 1607 |
1608 private: | 1608 private: |
1609 typedef GrGLLightingEffect INHERITED; | 1609 typedef GrGLLightingEffect INHERITED; |
1610 | 1610 |
1611 UniformHandle fKDUni; | 1611 UniformHandle fKDUni; |
1612 }; | 1612 }; |
1613 | 1613 |
1614 /////////////////////////////////////////////////////////////////////////////// | 1614 /////////////////////////////////////////////////////////////////////////////// |
1615 | 1615 |
1616 class GrGLSpecularLightingEffect : public GrGLLightingEffect { | 1616 class GrGLSpecularLightingEffect : public GrGLLightingEffect { |
1617 public: | 1617 public: |
1618 void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFragmentBuilder*, SkString*
funcName) override; | 1618 void emitLightFunc(GrGLSLUniformHandler*, GrGLSLFPFragmentBuilder*, SkString
* funcName) override; |
1619 | 1619 |
1620 protected: | 1620 protected: |
1621 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 1621 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
1622 | 1622 |
1623 private: | 1623 private: |
1624 typedef GrGLLightingEffect INHERITED; | 1624 typedef GrGLLightingEffect INHERITED; |
1625 | 1625 |
1626 UniformHandle fKSUni; | 1626 UniformHandle fKSUni; |
1627 UniformHandle fShininessUni; | 1627 UniformHandle fShininessUni; |
1628 }; | 1628 }; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1730 } | 1730 } |
1731 | 1731 |
1732 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 1732 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
1733 fImageIncrementUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 1733 fImageIncrementUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
1734 kVec2f_GrSLType, kDefault_Gr
SLPrecision, | 1734 kVec2f_GrSLType, kDefault_Gr
SLPrecision, |
1735 "ImageIncrement"); | 1735 "ImageIncrement"); |
1736 fSurfaceScaleUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 1736 fSurfaceScaleUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
1737 kFloat_GrSLType, kDefault_GrSL
Precision, | 1737 kFloat_GrSLType, kDefault_GrSL
Precision, |
1738 "SurfaceScale"); | 1738 "SurfaceScale"); |
1739 fLight->emitLightColorUniform(uniformHandler); | 1739 fLight->emitLightColorUniform(uniformHandler); |
1740 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 1740 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
1741 SkString lightFunc; | 1741 SkString lightFunc; |
1742 this->emitLightFunc(uniformHandler, fragBuilder, &lightFunc); | 1742 this->emitLightFunc(uniformHandler, fragBuilder, &lightFunc); |
1743 static const GrGLSLShaderVar gSobelArgs[] = { | 1743 static const GrGLSLShaderVar gSobelArgs[] = { |
1744 GrGLSLShaderVar("a", kFloat_GrSLType), | 1744 GrGLSLShaderVar("a", kFloat_GrSLType), |
1745 GrGLSLShaderVar("b", kFloat_GrSLType), | 1745 GrGLSLShaderVar("b", kFloat_GrSLType), |
1746 GrGLSLShaderVar("c", kFloat_GrSLType), | 1746 GrGLSLShaderVar("c", kFloat_GrSLType), |
1747 GrGLSLShaderVar("d", kFloat_GrSLType), | 1747 GrGLSLShaderVar("d", kFloat_GrSLType), |
1748 GrGLSLShaderVar("e", kFloat_GrSLType), | 1748 GrGLSLShaderVar("e", kFloat_GrSLType), |
1749 GrGLSLShaderVar("f", kFloat_GrSLType), | 1749 GrGLSLShaderVar("f", kFloat_GrSLType), |
1750 GrGLSLShaderVar("scale", kFloat_GrSLType), | 1750 GrGLSLShaderVar("scale", kFloat_GrSLType), |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1847 lighting.light()->transform(lighting
.filterMatrix())); | 1847 lighting.light()->transform(lighting
.filterMatrix())); |
1848 fDomain.setData(pdman, lighting.domain(), texture->origin()); | 1848 fDomain.setData(pdman, lighting.domain(), texture->origin()); |
1849 fLight->setData(pdman, transformedLight); | 1849 fLight->setData(pdman, transformedLight); |
1850 } | 1850 } |
1851 | 1851 |
1852 /////////////////////////////////////////////////////////////////////////////// | 1852 /////////////////////////////////////////////////////////////////////////////// |
1853 | 1853 |
1854 /////////////////////////////////////////////////////////////////////////////// | 1854 /////////////////////////////////////////////////////////////////////////////// |
1855 | 1855 |
1856 void GrGLDiffuseLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHandl
er, | 1856 void GrGLDiffuseLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHandl
er, |
1857 GrGLSLFragmentBuilder* fragBuilder
, | 1857 GrGLSLFPFragmentBuilder* fragBuild
er, |
1858 SkString* funcName) { | 1858 SkString* funcName) { |
1859 const char* kd; | 1859 const char* kd; |
1860 fKDUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 1860 fKDUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
1861 kFloat_GrSLType, kDefault_GrSLPrecision, | 1861 kFloat_GrSLType, kDefault_GrSLPrecision, |
1862 "KD", &kd); | 1862 "KD", &kd); |
1863 | 1863 |
1864 static const GrGLSLShaderVar gLightArgs[] = { | 1864 static const GrGLSLShaderVar gLightArgs[] = { |
1865 GrGLSLShaderVar("normal", kVec3f_GrSLType), | 1865 GrGLSLShaderVar("normal", kVec3f_GrSLType), |
1866 GrGLSLShaderVar("surfaceToLight", kVec3f_GrSLType), | 1866 GrGLSLShaderVar("surfaceToLight", kVec3f_GrSLType), |
1867 GrGLSLShaderVar("lightColor", kVec3f_GrSLType) | 1867 GrGLSLShaderVar("lightColor", kVec3f_GrSLType) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1936 d->fRandom->nextRangeU(0, tex->width()
), | 1936 d->fRandom->nextRangeU(0, tex->width()
), |
1937 d->fRandom->nextRangeU(0, tex->height(
))); | 1937 d->fRandom->nextRangeU(0, tex->height(
))); |
1938 return GrSpecularLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kA
lphaTextureIdx], | 1938 return GrSpecularLightingEffect::Create(d->fTextures[GrProcessorUnitTest::kA
lphaTextureIdx], |
1939 light, surfaceScale, matrix, ks, shi
niness, mode, | 1939 light, surfaceScale, matrix, ks, shi
niness, mode, |
1940 &srcBounds); | 1940 &srcBounds); |
1941 } | 1941 } |
1942 | 1942 |
1943 /////////////////////////////////////////////////////////////////////////////// | 1943 /////////////////////////////////////////////////////////////////////////////// |
1944 | 1944 |
1945 void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHand
ler, | 1945 void GrGLSpecularLightingEffect::emitLightFunc(GrGLSLUniformHandler* uniformHand
ler, |
1946 GrGLSLFragmentBuilder* fragBuilde
r, | 1946 GrGLSLFPFragmentBuilder* fragBuil
der, |
1947 SkString* funcName) { | 1947 SkString* funcName) { |
1948 const char* ks; | 1948 const char* ks; |
1949 const char* shininess; | 1949 const char* shininess; |
1950 | 1950 |
1951 fKSUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 1951 fKSUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
1952 kFloat_GrSLType, kDefault_GrSLPrecision,
"KS", &ks); | 1952 kFloat_GrSLType, kDefault_GrSLPrecision,
"KS", &ks); |
1953 fShininessUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 1953 fShininessUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
1954 kFloat_GrSLType, | 1954 kFloat_GrSLType, |
1955 kDefault_GrSLPrecision, | 1955 kDefault_GrSLPrecision, |
1956 "Shininess", | 1956 "Shininess", |
(...skipping 26 matching lines...) Expand all Loading... |
1983 } | 1983 } |
1984 | 1984 |
1985 /////////////////////////////////////////////////////////////////////////////// | 1985 /////////////////////////////////////////////////////////////////////////////// |
1986 void GrGLLight::emitLightColorUniform(GrGLSLUniformHandler* uniformHandler) { | 1986 void GrGLLight::emitLightColorUniform(GrGLSLUniformHandler* uniformHandler) { |
1987 fColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 1987 fColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
1988 kVec3f_GrSLType, kDefault_GrSLPrecisi
on, | 1988 kVec3f_GrSLType, kDefault_GrSLPrecisi
on, |
1989 "LightColor"); | 1989 "LightColor"); |
1990 } | 1990 } |
1991 | 1991 |
1992 void GrGLLight::emitLightColor(GrGLSLUniformHandler* uniformHandler, | 1992 void GrGLLight::emitLightColor(GrGLSLUniformHandler* uniformHandler, |
1993 GrGLSLFragmentBuilder* fragBuilder, | 1993 GrGLSLFPFragmentBuilder* fragBuilder, |
1994 const char *surfaceToLight) { | 1994 const char *surfaceToLight) { |
1995 fragBuilder->codeAppend(uniformHandler->getUniformCStr(this->lightColorUni()
)); | 1995 fragBuilder->codeAppend(uniformHandler->getUniformCStr(this->lightColorUni()
)); |
1996 } | 1996 } |
1997 | 1997 |
1998 void GrGLLight::setData(const GrGLSLProgramDataManager& pdman, | 1998 void GrGLLight::setData(const GrGLSLProgramDataManager& pdman, |
1999 const SkImageFilterLight* light) const { | 1999 const SkImageFilterLight* light) const { |
2000 setUniformPoint3(pdman, fColorUni, | 2000 setUniformPoint3(pdman, fColorUni, |
2001 light->color().makeScale(SkScalarInvert(SkIntToScalar(255))
)); | 2001 light->color().makeScale(SkScalarInvert(SkIntToScalar(255))
)); |
2002 } | 2002 } |
2003 | 2003 |
2004 /////////////////////////////////////////////////////////////////////////////// | 2004 /////////////////////////////////////////////////////////////////////////////// |
2005 | 2005 |
2006 void GrGLDistantLight::setData(const GrGLSLProgramDataManager& pdman, | 2006 void GrGLDistantLight::setData(const GrGLSLProgramDataManager& pdman, |
2007 const SkImageFilterLight* light) const { | 2007 const SkImageFilterLight* light) const { |
2008 INHERITED::setData(pdman, light); | 2008 INHERITED::setData(pdman, light); |
2009 SkASSERT(light->type() == SkImageFilterLight::kDistant_LightType); | 2009 SkASSERT(light->type() == SkImageFilterLight::kDistant_LightType); |
2010 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh
t); | 2010 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh
t); |
2011 setUniformNormal3(pdman, fDirectionUni, distantLight->direction()); | 2011 setUniformNormal3(pdman, fDirectionUni, distantLight->direction()); |
2012 } | 2012 } |
2013 | 2013 |
2014 void GrGLDistantLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler, | 2014 void GrGLDistantLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler, |
2015 GrGLSLFragmentBuilder* fragBuilder, | 2015 GrGLSLFPFragmentBuilder* fragBuilder, |
2016 const char* z) { | 2016 const char* z) { |
2017 const char* dir; | 2017 const char* dir; |
2018 fDirectionUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 2018 fDirectionUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
2019 kVec3f_GrSLType, kDefault_GrSLPre
cision, | 2019 kVec3f_GrSLType, kDefault_GrSLPre
cision, |
2020 "LightDirection", &dir); | 2020 "LightDirection", &dir); |
2021 fragBuilder->codeAppend(dir); | 2021 fragBuilder->codeAppend(dir); |
2022 } | 2022 } |
2023 | 2023 |
2024 /////////////////////////////////////////////////////////////////////////////// | 2024 /////////////////////////////////////////////////////////////////////////////// |
2025 | 2025 |
2026 void GrGLPointLight::setData(const GrGLSLProgramDataManager& pdman, | 2026 void GrGLPointLight::setData(const GrGLSLProgramDataManager& pdman, |
2027 const SkImageFilterLight* light) const { | 2027 const SkImageFilterLight* light) const { |
2028 INHERITED::setData(pdman, light); | 2028 INHERITED::setData(pdman, light); |
2029 SkASSERT(light->type() == SkImageFilterLight::kPoint_LightType); | 2029 SkASSERT(light->type() == SkImageFilterLight::kPoint_LightType); |
2030 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); | 2030 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); |
2031 setUniformPoint3(pdman, fLocationUni, pointLight->location()); | 2031 setUniformPoint3(pdman, fLocationUni, pointLight->location()); |
2032 } | 2032 } |
2033 | 2033 |
2034 void GrGLPointLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler, | 2034 void GrGLPointLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler, |
2035 GrGLSLFragmentBuilder* fragBuilder, | 2035 GrGLSLFPFragmentBuilder* fragBuilder, |
2036 const char* z) { | 2036 const char* z) { |
2037 const char* loc; | 2037 const char* loc; |
2038 fLocationUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 2038 fLocationUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
2039 kVec3f_GrSLType, kDefault_GrSLPrec
ision, | 2039 kVec3f_GrSLType, kDefault_GrSLPrec
ision, |
2040 "LightLocation", &loc); | 2040 "LightLocation", &loc); |
2041 fragBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", | 2041 fragBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", |
2042 loc, fragBuilder->fragmentPosition(), z); | 2042 loc, fragBuilder->fragmentPosition(), z); |
2043 } | 2043 } |
2044 | 2044 |
2045 /////////////////////////////////////////////////////////////////////////////// | 2045 /////////////////////////////////////////////////////////////////////////////// |
2046 | 2046 |
2047 void GrGLSpotLight::setData(const GrGLSLProgramDataManager& pdman, | 2047 void GrGLSpotLight::setData(const GrGLSLProgramDataManager& pdman, |
2048 const SkImageFilterLight* light) const { | 2048 const SkImageFilterLight* light) const { |
2049 INHERITED::setData(pdman, light); | 2049 INHERITED::setData(pdman, light); |
2050 SkASSERT(light->type() == SkImageFilterLight::kSpot_LightType); | 2050 SkASSERT(light->type() == SkImageFilterLight::kSpot_LightType); |
2051 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); | 2051 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); |
2052 setUniformPoint3(pdman, fLocationUni, spotLight->location()); | 2052 setUniformPoint3(pdman, fLocationUni, spotLight->location()); |
2053 pdman.set1f(fExponentUni, spotLight->specularExponent()); | 2053 pdman.set1f(fExponentUni, spotLight->specularExponent()); |
2054 pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); | 2054 pdman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); |
2055 pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); | 2055 pdman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); |
2056 pdman.set1f(fConeScaleUni, spotLight->coneScale()); | 2056 pdman.set1f(fConeScaleUni, spotLight->coneScale()); |
2057 setUniformNormal3(pdman, fSUni, spotLight->s()); | 2057 setUniformNormal3(pdman, fSUni, spotLight->s()); |
2058 } | 2058 } |
2059 | 2059 |
2060 void GrGLSpotLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler, | 2060 void GrGLSpotLight::emitSurfaceToLight(GrGLSLUniformHandler* uniformHandler, |
2061 GrGLSLFragmentBuilder* fragBuilder, | 2061 GrGLSLFPFragmentBuilder* fragBuilder, |
2062 const char* z) { | 2062 const char* z) { |
2063 const char* location; | 2063 const char* location; |
2064 fLocationUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 2064 fLocationUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
2065 kVec3f_GrSLType, kDefault_GrSLPrec
ision, | 2065 kVec3f_GrSLType, kDefault_GrSLPrec
ision, |
2066 "LightLocation", &location); | 2066 "LightLocation", &location); |
2067 | 2067 |
2068 fragBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", | 2068 fragBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))", |
2069 location, fragBuilder->fragmentPosition(), z); | 2069 location, fragBuilder->fragmentPosition(), z); |
2070 } | 2070 } |
2071 | 2071 |
2072 void GrGLSpotLight::emitLightColor(GrGLSLUniformHandler* uniformHandler, | 2072 void GrGLSpotLight::emitLightColor(GrGLSLUniformHandler* uniformHandler, |
2073 GrGLSLFragmentBuilder* fragBuilder, | 2073 GrGLSLFPFragmentBuilder* fragBuilder, |
2074 const char *surfaceToLight) { | 2074 const char *surfaceToLight) { |
2075 | 2075 |
2076 const char* color = uniformHandler->getUniformCStr(this->lightColorUni()); /
/ created by parent class. | 2076 const char* color = uniformHandler->getUniformCStr(this->lightColorUni()); /
/ created by parent class. |
2077 | 2077 |
2078 const char* exponent; | 2078 const char* exponent; |
2079 const char* cosInner; | 2079 const char* cosInner; |
2080 const char* cosOuter; | 2080 const char* cosOuter; |
2081 const char* coneScale; | 2081 const char* coneScale; |
2082 const char* s; | 2082 const char* s; |
2083 fExponentUni = uniformHandler->addUniform(kFragment_GrShaderFlag, | 2083 fExponentUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2118 | 2118 |
2119 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2119 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
2120 } | 2120 } |
2121 | 2121 |
2122 #endif | 2122 #endif |
2123 | 2123 |
2124 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2124 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
2125 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2125 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
2126 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2126 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
2127 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2127 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |