| 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" |
| 11 #include "SkPoint3.h" |
| 11 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
| 13 #include "SkTypes.h" |
| 12 #include "SkWriteBuffer.h" | 14 #include "SkWriteBuffer.h" |
| 13 #include "SkReadBuffer.h" | |
| 14 #include "SkWriteBuffer.h" | |
| 15 #include "SkTypes.h" | |
| 16 | 15 |
| 17 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
| 18 #include "GrContext.h" | 17 #include "GrContext.h" |
| 19 #include "GrDrawContext.h" | 18 #include "GrDrawContext.h" |
| 20 #include "GrFragmentProcessor.h" | 19 #include "GrFragmentProcessor.h" |
| 21 #include "GrInvariantOutput.h" | 20 #include "GrInvariantOutput.h" |
| 22 #include "GrPaint.h" | 21 #include "GrPaint.h" |
| 23 #include "effects/GrSingleTextureEffect.h" | 22 #include "effects/GrSingleTextureEffect.h" |
| 24 #include "gl/GrGLProcessor.h" | 23 #include "gl/GrGLProcessor.h" |
| 25 #include "gl/builders/GrGLProgramBuilder.h" | 24 #include "gl/builders/GrGLProgramBuilder.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 40 | 39 |
| 41 #if SK_SUPPORT_GPU | 40 #if SK_SUPPORT_GPU |
| 42 void setUniformPoint3(const GrGLProgramDataManager& pdman, UniformHandle uni, | 41 void setUniformPoint3(const GrGLProgramDataManager& pdman, UniformHandle uni, |
| 43 const SkPoint3& point) { | 42 const SkPoint3& point) { |
| 44 GR_STATIC_ASSERT(sizeof(SkPoint3) == 3 * sizeof(GrGLfloat)); | 43 GR_STATIC_ASSERT(sizeof(SkPoint3) == 3 * sizeof(GrGLfloat)); |
| 45 pdman.set3fv(uni, 1, &point.fX); | 44 pdman.set3fv(uni, 1, &point.fX); |
| 46 } | 45 } |
| 47 | 46 |
| 48 void setUniformNormal3(const GrGLProgramDataManager& pdman, UniformHandle uni, | 47 void setUniformNormal3(const GrGLProgramDataManager& pdman, UniformHandle uni, |
| 49 const SkPoint3& point) { | 48 const SkPoint3& point) { |
| 50 setUniformPoint3(pdman, uni, SkPoint3(point.fX, point.fY, point.fZ)); | 49 setUniformPoint3(pdman, uni, point); |
| 51 } | 50 } |
| 52 #endif | 51 #endif |
| 53 | 52 |
| 54 // Shift matrix components to the left, as we advance pixels to the right. | 53 // Shift matrix components to the left, as we advance pixels to the right. |
| 55 inline void shiftMatrixLeft(int m[9]) { | 54 inline void shiftMatrixLeft(int m[9]) { |
| 56 m[0] = m[1]; | 55 m[0] = m[1]; |
| 57 m[3] = m[4]; | 56 m[3] = m[4]; |
| 58 m[6] = m[7]; | 57 m[6] = m[7]; |
| 59 m[1] = m[2]; | 58 m[1] = m[2]; |
| 60 m[4] = m[5]; | 59 m[4] = m[5]; |
| 61 m[7] = m[8]; | 60 m[7] = m[8]; |
| 62 } | 61 } |
| 63 | 62 |
| 64 class DiffuseLightingType { | 63 class DiffuseLightingType { |
| 65 public: | 64 public: |
| 66 DiffuseLightingType(SkScalar kd) | 65 DiffuseLightingType(SkScalar kd) |
| 67 : fKD(kd) {} | 66 : fKD(kd) {} |
| 68 SkPMColor light(const SkPoint3& normal, const SkPoint3& surfaceTolight, | 67 SkPMColor light(const SkPoint3& normal, const SkPoint3& surfaceTolight, |
| 69 const SkPoint3& lightColor) const { | 68 const SkPoint3& lightColor) const { |
| 70 SkScalar colorScale = SkScalarMul(fKD, normal.dot(surfaceTolight)); | 69 SkScalar colorScale = SkScalarMul(fKD, normal.dot(surfaceTolight)); |
| 71 colorScale = SkScalarClampMax(colorScale, SK_Scalar1); | 70 colorScale = SkScalarClampMax(colorScale, SK_Scalar1); |
| 72 SkPoint3 color(lightColor * colorScale); | 71 SkPoint3 color = lightColor.makeScale(colorScale); |
| 73 return SkPackARGB32(255, | 72 return SkPackARGB32(255, |
| 74 SkClampMax(SkScalarRoundToInt(color.fX), 255), | 73 SkClampMax(SkScalarRoundToInt(color.fX), 255), |
| 75 SkClampMax(SkScalarRoundToInt(color.fY), 255), | 74 SkClampMax(SkScalarRoundToInt(color.fY), 255), |
| 76 SkClampMax(SkScalarRoundToInt(color.fZ), 255)); | 75 SkClampMax(SkScalarRoundToInt(color.fZ), 255)); |
| 77 } | 76 } |
| 78 private: | 77 private: |
| 79 SkScalar fKD; | 78 SkScalar fKD; |
| 80 }; | 79 }; |
| 81 | 80 |
| 81 static SkScalar max_component(const SkPoint3& p) { |
| 82 return p.x() > p.y() ? (p.x() > p.z() ? p.x() : p.z()) : (p.y() > p.z() ? p.
y() : p.z()); |
| 83 } |
| 84 |
| 82 class SpecularLightingType { | 85 class SpecularLightingType { |
| 83 public: | 86 public: |
| 84 SpecularLightingType(SkScalar ks, SkScalar shininess) | 87 SpecularLightingType(SkScalar ks, SkScalar shininess) |
| 85 : fKS(ks), fShininess(shininess) {} | 88 : fKS(ks), fShininess(shininess) {} |
| 86 SkPMColor light(const SkPoint3& normal, const SkPoint3& surfaceTolight, | 89 SkPMColor light(const SkPoint3& normal, const SkPoint3& surfaceTolight, |
| 87 const SkPoint3& lightColor) const { | 90 const SkPoint3& lightColor) const { |
| 88 SkPoint3 halfDir(surfaceTolight); | 91 SkPoint3 halfDir(surfaceTolight); |
| 89 halfDir.fZ += SK_Scalar1; // eye position is always (0, 0, 1) | 92 halfDir.fZ += SK_Scalar1; // eye position is always (0, 0, 1) |
| 90 halfDir.normalize(); | 93 halfDir.normalize(); |
| 91 SkScalar colorScale = SkScalarMul(fKS, | 94 SkScalar colorScale = SkScalarMul(fKS, |
| 92 SkScalarPow(normal.dot(halfDir), fShininess)); | 95 SkScalarPow(normal.dot(halfDir), fShininess)); |
| 93 colorScale = SkScalarClampMax(colorScale, SK_Scalar1); | 96 colorScale = SkScalarClampMax(colorScale, SK_Scalar1); |
| 94 SkPoint3 color(lightColor * colorScale); | 97 SkPoint3 color = lightColor.makeScale(colorScale); |
| 95 return SkPackARGB32(SkClampMax(SkScalarRoundToInt(color.maxComponent()),
255), | 98 return SkPackARGB32(SkClampMax(SkScalarRoundToInt(max_component(color)),
255), |
| 96 SkClampMax(SkScalarRoundToInt(color.fX), 255), | 99 SkClampMax(SkScalarRoundToInt(color.fX), 255), |
| 97 SkClampMax(SkScalarRoundToInt(color.fY), 255), | 100 SkClampMax(SkScalarRoundToInt(color.fY), 255), |
| 98 SkClampMax(SkScalarRoundToInt(color.fZ), 255)); | 101 SkClampMax(SkScalarRoundToInt(color.fZ), 255)); |
| 99 } | 102 } |
| 100 private: | 103 private: |
| 101 SkScalar fKS; | 104 SkScalar fKS; |
| 102 SkScalar fShininess; | 105 SkScalar fShininess; |
| 103 }; | 106 }; |
| 104 | 107 |
| 105 inline SkScalar sobel(int a, int b, int c, int d, int e, int f, SkScalar scale)
{ | 108 inline SkScalar sobel(int a, int b, int c, int d, int e, int f, SkScalar scale)
{ |
| 106 return SkScalarMul(SkIntToScalar(-a + b - 2 * c + 2 * d -e + f), scale); | 109 return SkScalarMul(SkIntToScalar(-a + b - 2 * c + 2 * d -e + f), scale); |
| 107 } | 110 } |
| 108 | 111 |
| 109 inline SkPoint3 pointToNormal(SkScalar x, SkScalar y, SkScalar surfaceScale) { | 112 inline SkPoint3 pointToNormal(SkScalar x, SkScalar y, SkScalar surfaceScale) { |
| 110 SkPoint3 vector(SkScalarMul(-x, surfaceScale), | 113 SkPoint3 vector = SkPoint3::Make(SkScalarMul(-x, surfaceScale), |
| 111 SkScalarMul(-y, surfaceScale), | 114 SkScalarMul(-y, surfaceScale), |
| 112 SK_Scalar1); | 115 SK_Scalar1); |
| 113 vector.normalize(); | 116 vector.normalize(); |
| 114 return vector; | 117 return vector; |
| 115 } | 118 } |
| 116 | 119 |
| 117 inline SkPoint3 topLeftNormal(int m[9], SkScalar surfaceScale) { | 120 inline SkPoint3 topLeftNormal(int m[9], SkScalar surfaceScale) { |
| 118 return pointToNormal(sobel(0, 0, m[4], m[5], m[7], m[8], gTwoThirds), | 121 return pointToNormal(sobel(0, 0, m[4], m[5], m[7], m[8], gTwoThirds), |
| 119 sobel(0, 0, m[4], m[7], m[5], m[8], gTwoThirds), | 122 sobel(0, 0, m[4], m[7], m[5], m[8], gTwoThirds), |
| 120 surfaceScale); | 123 surfaceScale); |
| 121 } | 124 } |
| 122 | 125 |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 } | 708 } |
| 706 // Called to know whether the generated GrGLLight will require access to the
fragment position. | 709 // Called to know whether the generated GrGLLight will require access to the
fragment position. |
| 707 virtual bool requiresFragmentPosition() const = 0; | 710 virtual bool requiresFragmentPosition() const = 0; |
| 708 virtual SkLight* transform(const SkMatrix& matrix) const = 0; | 711 virtual SkLight* transform(const SkMatrix& matrix) const = 0; |
| 709 | 712 |
| 710 // Defined below SkLight's subclasses. | 713 // Defined below SkLight's subclasses. |
| 711 void flattenLight(SkWriteBuffer& buffer) const; | 714 void flattenLight(SkWriteBuffer& buffer) const; |
| 712 static SkLight* UnflattenLight(SkReadBuffer& buffer); | 715 static SkLight* UnflattenLight(SkReadBuffer& buffer); |
| 713 | 716 |
| 714 protected: | 717 protected: |
| 715 SkLight(SkColor color) | 718 SkLight(SkColor color) { |
| 716 : fColor(SkIntToScalar(SkColorGetR(color)), | 719 fColor = SkPoint3::Make(SkIntToScalar(SkColorGetR(color)), |
| 717 SkIntToScalar(SkColorGetG(color)), | 720 SkIntToScalar(SkColorGetG(color)), |
| 718 SkIntToScalar(SkColorGetB(color))) {} | 721 SkIntToScalar(SkColorGetB(color))); |
| 722 } |
| 719 SkLight(const SkPoint3& color) | 723 SkLight(const SkPoint3& color) |
| 720 : fColor(color) {} | 724 : fColor(color) {} |
| 721 SkLight(SkReadBuffer& buffer) { | 725 SkLight(SkReadBuffer& buffer) { |
| 722 fColor = readPoint3(buffer); | 726 fColor = readPoint3(buffer); |
| 723 } | 727 } |
| 724 | 728 |
| 725 virtual void onFlattenLight(SkWriteBuffer& buffer) const = 0; | 729 virtual void onFlattenLight(SkWriteBuffer& buffer) const = 0; |
| 726 | 730 |
| 727 | 731 |
| 728 private: | 732 private: |
| 729 typedef SkRefCnt INHERITED; | 733 typedef SkRefCnt INHERITED; |
| 730 SkPoint3 fColor; | 734 SkPoint3 fColor; |
| 731 }; | 735 }; |
| 732 | 736 |
| 733 /////////////////////////////////////////////////////////////////////////////// | 737 /////////////////////////////////////////////////////////////////////////////// |
| 734 | 738 |
| 735 class SkDistantLight : public SkLight { | 739 class SkDistantLight : public SkLight { |
| 736 public: | 740 public: |
| 737 SkDistantLight(const SkPoint3& direction, SkColor color) | 741 SkDistantLight(const SkPoint3& direction, SkColor color) |
| 738 : INHERITED(color), fDirection(direction) { | 742 : INHERITED(color), fDirection(direction) { |
| 739 } | 743 } |
| 740 | 744 |
| 741 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { | 745 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { |
| 742 return fDirection; | 746 return fDirection; |
| 743 }; | 747 }; |
| 744 SkPoint3 lightColor(const SkPoint3&) const { return color(); } | 748 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); } |
| 745 LightType type() const override { return kDistant_LightType; } | 749 LightType type() const override { return kDistant_LightType; } |
| 746 const SkPoint3& direction() const { return fDirection; } | 750 const SkPoint3& direction() const { return fDirection; } |
| 747 GrGLLight* createGLLight() const override { | 751 GrGLLight* createGLLight() const override { |
| 748 #if SK_SUPPORT_GPU | 752 #if SK_SUPPORT_GPU |
| 749 return SkNEW(GrGLDistantLight); | 753 return SkNEW(GrGLDistantLight); |
| 750 #else | 754 #else |
| 751 SkDEBUGFAIL("Should not call in GPU-less build"); | 755 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 752 return NULL; | 756 return NULL; |
| 753 #endif | 757 #endif |
| 754 } | 758 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 785 }; | 789 }; |
| 786 | 790 |
| 787 /////////////////////////////////////////////////////////////////////////////// | 791 /////////////////////////////////////////////////////////////////////////////// |
| 788 | 792 |
| 789 class SkPointLight : public SkLight { | 793 class SkPointLight : public SkLight { |
| 790 public: | 794 public: |
| 791 SkPointLight(const SkPoint3& location, SkColor color) | 795 SkPointLight(const SkPoint3& location, SkColor color) |
| 792 : INHERITED(color), fLocation(location) {} | 796 : INHERITED(color), fLocation(location) {} |
| 793 | 797 |
| 794 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { | 798 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { |
| 795 SkPoint3 direction(fLocation.fX - SkIntToScalar(x), | 799 SkPoint3 direction = SkPoint3::Make(fLocation.fX - SkIntToScalar(x), |
| 796 fLocation.fY - SkIntToScalar(y), | 800 fLocation.fY - SkIntToScalar(y), |
| 797 fLocation.fZ - SkScalarMul(SkIntToScalar(z), surfaceS
cale)); | 801 fLocation.fZ - SkScalarMul(SkIntToSc
alar(z), |
| 802 surfaceSc
ale)); |
| 798 direction.normalize(); | 803 direction.normalize(); |
| 799 return direction; | 804 return direction; |
| 800 }; | 805 }; |
| 801 SkPoint3 lightColor(const SkPoint3&) const { return color(); } | 806 const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); } |
| 802 LightType type() const override { return kPoint_LightType; } | 807 LightType type() const override { return kPoint_LightType; } |
| 803 const SkPoint3& location() const { return fLocation; } | 808 const SkPoint3& location() const { return fLocation; } |
| 804 GrGLLight* createGLLight() const override { | 809 GrGLLight* createGLLight() const override { |
| 805 #if SK_SUPPORT_GPU | 810 #if SK_SUPPORT_GPU |
| 806 return SkNEW(GrGLPointLight); | 811 return SkNEW(GrGLPointLight); |
| 807 #else | 812 #else |
| 808 SkDEBUGFAIL("Should not call in GPU-less build"); | 813 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 809 return NULL; | 814 return NULL; |
| 810 #endif | 815 #endif |
| 811 } | 816 } |
| 812 bool requiresFragmentPosition() const override { return true; } | 817 bool requiresFragmentPosition() const override { return true; } |
| 813 bool isEqual(const SkLight& other) const override { | 818 bool isEqual(const SkLight& other) const override { |
| 814 if (other.type() != kPoint_LightType) { | 819 if (other.type() != kPoint_LightType) { |
| 815 return false; | 820 return false; |
| 816 } | 821 } |
| 817 const SkPointLight& o = static_cast<const SkPointLight&>(other); | 822 const SkPointLight& o = static_cast<const SkPointLight&>(other); |
| 818 return INHERITED::isEqual(other) && | 823 return INHERITED::isEqual(other) && |
| 819 fLocation == o.fLocation; | 824 fLocation == o.fLocation; |
| 820 } | 825 } |
| 821 SkLight* transform(const SkMatrix& matrix) const override { | 826 SkLight* transform(const SkMatrix& matrix) const override { |
| 822 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); | 827 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); |
| 823 matrix.mapPoints(&location2, 1); | 828 matrix.mapPoints(&location2, 1); |
| 824 // Use X scale and Y scale on Z and average the result | 829 // Use X scale and Y scale on Z and average the result |
| 825 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); | 830 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); |
| 826 matrix.mapVectors(&locationZ, 1); | 831 matrix.mapVectors(&locationZ, 1); |
| 827 SkPoint3 location(location2.fX, location2.fY, SkScalarAve(locationZ.fX,
locationZ.fY)); | 832 SkPoint3 location = SkPoint3::Make(location2.fX, |
| 833 location2.fY, |
| 834 SkScalarAve(locationZ.fX, locationZ.f
Y)); |
| 828 return new SkPointLight(location, color()); | 835 return new SkPointLight(location, color()); |
| 829 } | 836 } |
| 830 | 837 |
| 831 SkPointLight(SkReadBuffer& buffer) : INHERITED(buffer) { | 838 SkPointLight(SkReadBuffer& buffer) : INHERITED(buffer) { |
| 832 fLocation = readPoint3(buffer); | 839 fLocation = readPoint3(buffer); |
| 833 } | 840 } |
| 834 | 841 |
| 835 protected: | 842 protected: |
| 836 SkPointLight(const SkPoint3& location, const SkPoint3& color) | 843 SkPointLight(const SkPoint3& location, const SkPoint3& color) |
| 837 : INHERITED(color), fLocation(location) {} | 844 : INHERITED(color), fLocation(location) {} |
| (...skipping 27 matching lines...) Expand all Loading... |
| 865 fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold; | 872 fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold; |
| 866 fConeScale = SkScalarInvert(antiAliasThreshold); | 873 fConeScale = SkScalarInvert(antiAliasThreshold); |
| 867 } | 874 } |
| 868 | 875 |
| 869 SkLight* transform(const SkMatrix& matrix) const override { | 876 SkLight* transform(const SkMatrix& matrix) const override { |
| 870 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); | 877 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); |
| 871 matrix.mapPoints(&location2, 1); | 878 matrix.mapPoints(&location2, 1); |
| 872 // Use X scale and Y scale on Z and average the result | 879 // Use X scale and Y scale on Z and average the result |
| 873 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); | 880 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); |
| 874 matrix.mapVectors(&locationZ, 1); | 881 matrix.mapVectors(&locationZ, 1); |
| 875 SkPoint3 location(location2.fX, location2.fY, SkScalarAve(locationZ.fX,
locationZ.fY)); | 882 SkPoint3 location = SkPoint3::Make(location2.fX, location2.fY, |
| 883 SkScalarAve(locationZ.fX, locationZ.f
Y)); |
| 876 SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY); | 884 SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY); |
| 877 matrix.mapPoints(&target2, 1); | 885 matrix.mapPoints(&target2, 1); |
| 878 SkPoint targetZ = SkPoint::Make(fTarget.fZ, fTarget.fZ); | 886 SkPoint targetZ = SkPoint::Make(fTarget.fZ, fTarget.fZ); |
| 879 matrix.mapVectors(&targetZ, 1); | 887 matrix.mapVectors(&targetZ, 1); |
| 880 SkPoint3 target(target2.fX, target2.fY, SkScalarAve(targetZ.fX, targetZ.
fY)); | 888 SkPoint3 target = SkPoint3::Make(target2.fX, target2.fY, |
| 889 SkScalarAve(targetZ.fX, targetZ.fY)); |
| 881 SkPoint3 s = target - location; | 890 SkPoint3 s = target - location; |
| 882 s.normalize(); | 891 s.normalize(); |
| 883 return new SkSpotLight(location, | 892 return new SkSpotLight(location, |
| 884 target, | 893 target, |
| 885 fSpecularExponent, | 894 fSpecularExponent, |
| 886 fCosOuterConeAngle, | 895 fCosOuterConeAngle, |
| 887 fCosInnerConeAngle, | 896 fCosInnerConeAngle, |
| 888 fConeScale, | 897 fConeScale, |
| 889 s, | 898 s, |
| 890 color()); | 899 color()); |
| 891 } | 900 } |
| 892 | 901 |
| 893 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { | 902 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { |
| 894 SkPoint3 direction(fLocation.fX - SkIntToScalar(x), | 903 SkPoint3 direction = SkPoint3::Make(fLocation.fX - SkIntToScalar(x), |
| 895 fLocation.fY - SkIntToScalar(y), | 904 fLocation.fY - SkIntToScalar(y), |
| 896 fLocation.fZ - SkScalarMul(SkIntToScalar(z), surfaceS
cale)); | 905 fLocation.fZ - SkScalarMul(SkIntToSc
alar(z), |
| 906 surfaceSc
ale)); |
| 897 direction.normalize(); | 907 direction.normalize(); |
| 898 return direction; | 908 return direction; |
| 899 }; | 909 }; |
| 900 SkPoint3 lightColor(const SkPoint3& surfaceToLight) const { | 910 SkPoint3 lightColor(const SkPoint3& surfaceToLight) const { |
| 901 SkScalar cosAngle = -surfaceToLight.dot(fS); | 911 SkScalar cosAngle = -surfaceToLight.dot(fS); |
| 902 if (cosAngle < fCosOuterConeAngle) { | 912 SkScalar scale = 0; |
| 903 return SkPoint3(0, 0, 0); | 913 if (cosAngle >= fCosOuterConeAngle) { |
| 914 scale = SkScalarPow(cosAngle, fSpecularExponent); |
| 915 if (cosAngle < fCosInnerConeAngle) { |
| 916 scale = SkScalarMul(scale, cosAngle - fCosOuterConeAngle); |
| 917 scale *= fConeScale; |
| 918 } |
| 904 } | 919 } |
| 905 SkScalar scale = SkScalarPow(cosAngle, fSpecularExponent); | 920 return this->color().makeScale(scale); |
| 906 if (cosAngle < fCosInnerConeAngle) { | |
| 907 scale = SkScalarMul(scale, cosAngle - fCosOuterConeAngle); | |
| 908 return color() * SkScalarMul(scale, fConeScale); | |
| 909 } | |
| 910 return color() * scale; | |
| 911 } | 921 } |
| 912 GrGLLight* createGLLight() const override { | 922 GrGLLight* createGLLight() const override { |
| 913 #if SK_SUPPORT_GPU | 923 #if SK_SUPPORT_GPU |
| 914 return SkNEW(GrGLSpotLight); | 924 return SkNEW(GrGLSpotLight); |
| 915 #else | 925 #else |
| 916 SkDEBUGFAIL("Should not call in GPU-less build"); | 926 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 917 return NULL; | 927 return NULL; |
| 918 #endif | 928 #endif |
| 919 } | 929 } |
| 920 bool requiresFragmentPosition() const override { return true; } | 930 bool requiresFragmentPosition() const override { return true; } |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 this->ks(), this->shininess(), bound
aryMode); | 1389 this->ks(), this->shininess(), bound
aryMode); |
| 1380 } | 1390 } |
| 1381 #endif | 1391 #endif |
| 1382 | 1392 |
| 1383 /////////////////////////////////////////////////////////////////////////////// | 1393 /////////////////////////////////////////////////////////////////////////////// |
| 1384 | 1394 |
| 1385 #if SK_SUPPORT_GPU | 1395 #if SK_SUPPORT_GPU |
| 1386 | 1396 |
| 1387 namespace { | 1397 namespace { |
| 1388 SkPoint3 random_point3(SkRandom* random) { | 1398 SkPoint3 random_point3(SkRandom* random) { |
| 1389 return SkPoint3(SkScalarToFloat(random->nextSScalar1()), | 1399 return SkPoint3::Make(SkScalarToFloat(random->nextSScalar1()), |
| 1390 SkScalarToFloat(random->nextSScalar1()), | 1400 SkScalarToFloat(random->nextSScalar1()), |
| 1391 SkScalarToFloat(random->nextSScalar1())); | 1401 SkScalarToFloat(random->nextSScalar1())); |
| 1392 } | 1402 } |
| 1393 | 1403 |
| 1394 SkLight* create_random_light(SkRandom* random) { | 1404 SkLight* create_random_light(SkRandom* random) { |
| 1395 int type = random->nextULessThan(3); | 1405 int type = random->nextULessThan(3); |
| 1396 switch (type) { | 1406 switch (type) { |
| 1397 case 0: { | 1407 case 0: { |
| 1398 return SkNEW_ARGS(SkDistantLight, (random_point3(random), random->ne
xtU())); | 1408 return SkNEW_ARGS(SkDistantLight, (random_point3(random), random->ne
xtU())); |
| 1399 } | 1409 } |
| 1400 case 1: { | 1410 case 1: { |
| 1401 return SkNEW_ARGS(SkPointLight, (random_point3(random), random->next
U())); | 1411 return SkNEW_ARGS(SkPointLight, (random_point3(random), random->next
U())); |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1876 pdman.set1f(fShininessUni, spec.shininess()); | 1886 pdman.set1f(fShininessUni, spec.shininess()); |
| 1877 } | 1887 } |
| 1878 | 1888 |
| 1879 /////////////////////////////////////////////////////////////////////////////// | 1889 /////////////////////////////////////////////////////////////////////////////// |
| 1880 void GrGLLight::emitLightColorUniform(GrGLFPBuilder* builder) { | 1890 void GrGLLight::emitLightColorUniform(GrGLFPBuilder* builder) { |
| 1881 fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 1891 fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
| 1882 kVec3f_GrSLType, kDefault_GrSLPrecision, | 1892 kVec3f_GrSLType, kDefault_GrSLPrecision, |
| 1883 "LightColor"); | 1893 "LightColor"); |
| 1884 } | 1894 } |
| 1885 | 1895 |
| 1886 void GrGLLight::emitLightColor(GrGLFPBuilder* builder, | 1896 void GrGLLight::emitLightColor(GrGLFPBuilder* builder, const char *surfaceToLigh
t) { |
| 1887 const char *surfaceToLight) { | |
| 1888 builder->getFragmentShaderBuilder()->codeAppend(builder->getUniformCStr(this
->lightColorUni())); | 1897 builder->getFragmentShaderBuilder()->codeAppend(builder->getUniformCStr(this
->lightColorUni())); |
| 1889 } | 1898 } |
| 1890 | 1899 |
| 1891 void GrGLLight::setData(const GrGLProgramDataManager& pdman, | 1900 void GrGLLight::setData(const GrGLProgramDataManager& pdman, const SkLight* ligh
t) const { |
| 1892 const SkLight* light) const { | 1901 setUniformPoint3(pdman, fColorUni, |
| 1893 setUniformPoint3(pdman, fColorUni, light->color() * SkScalarInvert(SkIntToSc
alar(255))); | 1902 light->color().makeScale(SkScalarInvert(SkIntToScalar(255))
)); |
| 1894 } | 1903 } |
| 1895 | 1904 |
| 1896 /////////////////////////////////////////////////////////////////////////////// | 1905 /////////////////////////////////////////////////////////////////////////////// |
| 1897 | 1906 |
| 1898 void GrGLDistantLight::setData(const GrGLProgramDataManager& pdman, | 1907 void GrGLDistantLight::setData(const GrGLProgramDataManager& pdman, |
| 1899 const SkLight* light) const { | 1908 const SkLight* light) const { |
| 1900 INHERITED::setData(pdman, light); | 1909 INHERITED::setData(pdman, light); |
| 1901 SkASSERT(light->type() == SkLight::kDistant_LightType); | 1910 SkASSERT(light->type() == SkLight::kDistant_LightType); |
| 1902 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh
t); | 1911 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh
t); |
| 1903 setUniformNormal3(pdman, fDirectionUni, distantLight->direction()); | 1912 setUniformNormal3(pdman, fDirectionUni, distantLight->direction()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2006 | 2015 |
| 2007 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2016 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
| 2008 } | 2017 } |
| 2009 | 2018 |
| 2010 #endif | 2019 #endif |
| 2011 | 2020 |
| 2012 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2021 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
| 2013 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2022 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
| 2014 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2023 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
| 2015 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2024 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |