Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: src/core/SkShadowShader.cpp

Issue 2297693002: made raster shadows variance shadows (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: made req changes Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
742 } 744 }
743 745
744 if (pvDepth >= shDepth) { 746 SkScalar lightProb = 1.0f;
745 // assume object normals are pointing straight up 747 if (pvDepth < shDepth) {
746 totalLight.fX += light.dir().fZ * light.color().fX; 748 if (lightShader.fShadowParams.fType ==
747 totalLight.fY += light.dir().fZ * light.color().fY; 749 SkShadowParams::ShadowType::kVariance_ShadowType) {
748 totalLight.fZ += light.dir().fZ * light.color().fZ; 750 int variance = SkMaxScalar(shDepthsq - shDepth * shD epth,
751 lightShader.fShadowParams .fMinVariance);
752 int d = pvDepth - shDepth;
753
754 lightProb = (SkScalar) variance / ((SkScalar) (varia nce + d * d));
755
756 SkScalar bias = lightShader.fShadowParams.fBiasingCo nstant;
757
758 lightProb = SkMaxScalar((lightProb - bias) / (1.0f - bias), 0.0f);
759 } else {
760 lightProb = 0.0f;
761 }
749 } 762 }
763
764 // assume object normals are pointing straight up
765 totalLight.fX += light.dir().fZ * light.color().fX * lightPr ob;
766 totalLight.fY += light.dir().fZ * light.color().fY * lightPr ob;
767 totalLight.fZ += light.dir().fZ * light.color().fZ * lightPr ob;
750 } else { 768 } else {
751 totalLight += light.color(); 769 totalLight += light.color();
752 } 770 }
753 } 771 }
754 772
755 SkColor3f totalColor = SkColor3f::Make(SkColorGetR(diffColor) * tota lLight.fX, 773 SkColor3f totalColor = SkColor3f::Make(SkColorGetR(diffColor) * tota lLight.fX,
756 SkColorGetG(diffColor) * tota lLight.fY, 774 SkColorGetG(diffColor) * tota lLight.fY,
757 SkColorGetB(diffColor) * tota lLight.fZ); 775 SkColorGetB(diffColor) * tota lLight.fZ);
758 776
759 result[i] = convert(totalColor, SkColorGetA(diffColor)); 777 result[i] = convert(totalColor, SkColorGetA(diffColor));
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 890
873 /////////////////////////////////////////////////////////////////////////////// 891 ///////////////////////////////////////////////////////////////////////////////
874 892
875 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) 893 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader)
876 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) 894 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl)
877 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 895 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
878 896
879 /////////////////////////////////////////////////////////////////////////////// 897 ///////////////////////////////////////////////////////////////////////////////
880 898
881 #endif 899 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698