OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
10 #include "SkShadowShader.h" | 10 #include "SkShadowShader.h" |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 if (light.type() == SkLights::Light::kDirectional_LightType) { | 722 if (light.type() == SkLights::Light::kDirectional_LightType) { |
723 int pvDepth = SkColorGetB(povDepthColor); // depth stored in blue channel | 723 int pvDepth = SkColorGetB(povDepthColor); // depth stored in blue channel |
724 | 724 |
725 int xOffset = SkScalarRoundToInt(light.dir().fX * pvDepth); | 725 int xOffset = SkScalarRoundToInt(light.dir().fX * pvDepth); |
726 int yOffset = SkScalarRoundToInt(light.dir().fY * pvDepth); | 726 int yOffset = SkScalarRoundToInt(light.dir().fY * pvDepth); |
727 | 727 |
728 int shX = SkClampMax(x + i + xOffset, light.getShadowMap()-> width() - 1); | 728 int shX = SkClampMax(x + i + xOffset, light.getShadowMap()-> width() - 1); |
729 int shY = SkClampMax(y + yOffset, light.getShadowMap()->heig ht() - 1); | 729 int shY = SkClampMax(y + yOffset, light.getShadowMap()->heig ht() - 1); |
730 | 730 |
731 int shDepth = 0; | 731 int shDepth = 0; |
732 int shDepthsq = 0; | |
732 | 733 |
733 // pixmaps that point to things have nonzero heights | 734 // pixmaps that point to things have nonzero heights |
734 if (fShadowMapPixels[l].height() > 0) { | 735 if (fShadowMapPixels[l].height() > 0) { |
735 uint32_t pix = *fShadowMapPixels[l].addr32(shX, shY); | 736 uint32_t pix = *fShadowMapPixels[l].addr32(shX, shY); |
736 SkColor shColor(pix); | 737 SkColor shColor(pix); |
737 | 738 |
738 shDepth = SkColorGetB(shColor); | 739 shDepth = SkColorGetB(shColor); |
740 shDepthsq = SkColorGetG(shColor) * 256; | |
739 } else { | 741 } else { |
740 // Make lights w/o a shadow map receive the full light c ontribution | 742 // Make lights w/o a shadow map receive the full light c ontribution |
741 shDepth = pvDepth; | 743 shDepth = pvDepth; |
robertphillips
2016/08/30 16:48:37
It seems like you don't have to compute the square
vjiaoblack
2016/08/30 17:01:26
Ah right. I guess it'll fail the next if case
| |
744 shDepthsq = shDepth * shDepth; | |
742 } | 745 } |
743 | 746 |
robertphillips
2016/08/30 16:48:37
I expect a "if (blurAlgorithm == SkShadowParams::k
vjiaoblack
2016/08/30 17:01:26
That doesn't need to be here.
If the shadow map i
robertphillips
2016/08/30 17:04:39
The variance path is far more expensive than the n
| |
744 if (pvDepth >= shDepth) { | 747 SkScalar lightProb = 1.0f; |
745 // assume object normals are pointing straight up | 748 if (pvDepth < shDepth) { |
746 totalLight.fX += light.dir().fZ * light.color().fX; | 749 int variance = SkTMax(shDepthsq - shDepth * shDepth, |
747 totalLight.fY += light.dir().fZ * light.color().fY; | 750 lightShader.fShadowParams.fMinVari ance); |
748 totalLight.fZ += light.dir().fZ * light.color().fZ; | 751 int d = pvDepth - shDepth; |
752 | |
753 lightProb = (SkScalar) variance / ((SkScalar) (variance + d * d)); | |
754 | |
robertphillips
2016/08/30 16:48:37
This formula is a bit hard to parse with the given
vjiaoblack
2016/08/30 17:01:26
Done.
| |
755 lightProb = SkMaxScalar((lightProb - | |
756 lightShader.fShadowParams.fBias ingConstant) / | |
757 (1.0f - | |
758 lightShader.fShadowParams.fBias ingConstant), | |
759 0.0f); | |
749 } | 760 } |
761 | |
762 // assume object normals are pointing straight up | |
763 totalLight.fX += light.dir().fZ * light.color().fX * lightPr ob; | |
764 totalLight.fY += light.dir().fZ * light.color().fY * lightPr ob; | |
765 totalLight.fZ += light.dir().fZ * light.color().fZ * lightPr ob; | |
750 } else { | 766 } else { |
751 totalLight += light.color(); | 767 totalLight += light.color(); |
752 } | 768 } |
753 } | 769 } |
754 | 770 |
755 SkColor3f totalColor = SkColor3f::Make(SkColorGetR(diffColor) * tota lLight.fX, | 771 SkColor3f totalColor = SkColor3f::Make(SkColorGetR(diffColor) * tota lLight.fX, |
756 SkColorGetG(diffColor) * tota lLight.fY, | 772 SkColorGetG(diffColor) * tota lLight.fY, |
757 SkColorGetB(diffColor) * tota lLight.fZ); | 773 SkColorGetB(diffColor) * tota lLight.fZ); |
758 | 774 |
759 result[i] = convert(totalColor, SkColorGetA(diffColor)); | 775 result[i] = convert(totalColor, SkColorGetA(diffColor)); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 | 888 |
873 /////////////////////////////////////////////////////////////////////////////// | 889 /////////////////////////////////////////////////////////////////////////////// |
874 | 890 |
875 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) | 891 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) |
876 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) | 892 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) |
877 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 893 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
878 | 894 |
879 /////////////////////////////////////////////////////////////////////////////// | 895 /////////////////////////////////////////////////////////////////////////////// |
880 | 896 |
881 #endif | 897 #endif |
OLD | NEW |