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 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 if (other.type() != kPoint_LightType) { | 634 if (other.type() != kPoint_LightType) { |
635 return false; | 635 return false; |
636 } | 636 } |
637 const SkPointLight& o = static_cast<const SkPointLight&>(other); | 637 const SkPointLight& o = static_cast<const SkPointLight&>(other); |
638 return INHERITED::isEqual(other) && | 638 return INHERITED::isEqual(other) && |
639 fLocation == o.fLocation; | 639 fLocation == o.fLocation; |
640 } | 640 } |
641 virtual SkLight* transform(const SkMatrix& matrix) const { | 641 virtual SkLight* transform(const SkMatrix& matrix) const { |
642 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); | 642 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); |
643 matrix.mapPoints(&location2, 1); | 643 matrix.mapPoints(&location2, 1); |
644 SkPoint3 location(location2.fX, location2.fY, fLocation.fZ); | 644 // Use X scale and Y scale on Z and average the result |
| 645 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); |
| 646 matrix.mapVectors(&locationZ, 1); |
| 647 SkPoint3 location(location2.fX, location2.fY, SkScalarAve(locationZ.fX,
locationZ.fY)); |
645 return new SkPointLight(location, color()); | 648 return new SkPointLight(location, color()); |
646 } | 649 } |
647 | 650 |
648 SkPointLight(SkReadBuffer& buffer) : INHERITED(buffer) { | 651 SkPointLight(SkReadBuffer& buffer) : INHERITED(buffer) { |
649 fLocation = readPoint3(buffer); | 652 fLocation = readPoint3(buffer); |
650 } | 653 } |
651 | 654 |
652 protected: | 655 protected: |
653 SkPointLight(const SkPoint3& location, const SkPoint3& color) | 656 SkPointLight(const SkPoint3& location, const SkPoint3& color) |
654 : INHERITED(color), fLocation(location) {} | 657 : INHERITED(color), fLocation(location) {} |
(...skipping 20 matching lines...) Expand all Loading... |
675 fS.normalize(); | 678 fS.normalize(); |
676 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle)); | 679 fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle)); |
677 const SkScalar antiAliasThreshold = 0.016f; | 680 const SkScalar antiAliasThreshold = 0.016f; |
678 fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold; | 681 fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold; |
679 fConeScale = SkScalarInvert(antiAliasThreshold); | 682 fConeScale = SkScalarInvert(antiAliasThreshold); |
680 } | 683 } |
681 | 684 |
682 virtual SkLight* transform(const SkMatrix& matrix) const { | 685 virtual SkLight* transform(const SkMatrix& matrix) const { |
683 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); | 686 SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY); |
684 matrix.mapPoints(&location2, 1); | 687 matrix.mapPoints(&location2, 1); |
685 SkPoint3 location(location2.fX, location2.fY, fLocation.fZ); | 688 // Use X scale and Y scale on Z and average the result |
| 689 SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ); |
| 690 matrix.mapVectors(&locationZ, 1); |
| 691 SkPoint3 location(location2.fX, location2.fY, SkScalarAve(locationZ.fX,
locationZ.fY)); |
686 SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY); | 692 SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY); |
687 matrix.mapPoints(&target2, 1); | 693 matrix.mapPoints(&target2, 1); |
688 SkPoint3 target(target2.fX, target2.fY, fTarget.fZ); | 694 SkPoint targetZ = SkPoint::Make(fTarget.fZ, fTarget.fZ); |
689 return new SkSpotLight(location, target, fSpecularExponent, fCosOuterCon
eAngle, fCosInnerConeAngle, fConeScale, fS, color()); | 695 matrix.mapVectors(&targetZ, 1); |
| 696 SkPoint3 target(target2.fX, target2.fY, SkScalarAve(targetZ.fX, targetZ.
fY)); |
| 697 SkPoint3 s = target - location; |
| 698 s.normalize(); |
| 699 return new SkSpotLight(location, target, fSpecularExponent, fCosOuterCon
eAngle, fCosInnerConeAngle, fConeScale, s, color()); |
690 } | 700 } |
691 | 701 |
692 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { | 702 SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const { |
693 SkPoint3 direction(fLocation.fX - SkIntToScalar(x), | 703 SkPoint3 direction(fLocation.fX - SkIntToScalar(x), |
694 fLocation.fY - SkIntToScalar(y), | 704 fLocation.fY - SkIntToScalar(y), |
695 fLocation.fZ - SkScalarMul(SkIntToScalar(z), surfaceS
cale)); | 705 fLocation.fZ - SkScalarMul(SkIntToScalar(z), surfaceS
cale)); |
696 direction.normalize(); | 706 direction.normalize(); |
697 return direction; | 707 return direction; |
698 }; | 708 }; |
699 SkPoint3 lightColor(const SkPoint3& surfaceToLight) const { | 709 SkPoint3 lightColor(const SkPoint3& surfaceToLight) const { |
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 | 1618 |
1609 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1619 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1610 } | 1620 } |
1611 | 1621 |
1612 #endif | 1622 #endif |
1613 | 1623 |
1614 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1624 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1615 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1625 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1616 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1626 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1617 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1627 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |