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

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

Issue 2291663002: Revert of Moved ambient lights out of SkLight's light array (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: 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 | « src/core/SkLights.cpp ('k') | src/utils/SkShadowPaintFilterCanvas.cpp » ('j') | 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 class ShadowFP : public GrFragmentProcessor { 105 class ShadowFP : public GrFragmentProcessor {
106 public: 106 public:
107 ShadowFP(sk_sp<GrFragmentProcessor> povDepth, 107 ShadowFP(sk_sp<GrFragmentProcessor> povDepth,
108 sk_sp<GrFragmentProcessor> diffuse, 108 sk_sp<GrFragmentProcessor> diffuse,
109 sk_sp<SkLights> lights, 109 sk_sp<SkLights> lights,
110 int diffuseWidth, int diffuseHeight, 110 int diffuseWidth, int diffuseHeight,
111 const SkShadowParams& params, 111 const SkShadowParams& params,
112 GrContext* context) { 112 GrContext* context) {
113 113
114 fAmbientColor = lights->ambientLightColor(); 114 // fuse all ambient lights into a single one
115 fAmbientColor.set(0.0f, 0.0f, 0.0f);
115 116
116 fNumNonAmbLights = 0; // count of non-ambient lights 117 fNumNonAmbLights = 0; // count of non-ambient lights
117 for (int i = 0; i < lights->numLights(); ++i) { 118 for (int i = 0; i < lights->numLights(); ++i) {
118 if (fNumNonAmbLights < SkShadowShader::kMaxNonAmbientLights) { 119 if (SkLights::Light::kAmbient_LightType == lights->light(i).type()) {
120 fAmbientColor += lights->light(i).color();
121 } else if (fNumNonAmbLights < SkShadowShader::kMaxNonAmbientLights) {
119 fLightColor[fNumNonAmbLights] = lights->light(i).color(); 122 fLightColor[fNumNonAmbLights] = lights->light(i).color();
120 123 if (lights->light(i).type() == SkLights::Light::kPoint_LightType ) {
121 if (SkLights::Light::kDirectional_LightType == lights->light(i). type()) { 124 fLightDirOrPos[fNumNonAmbLights] = lights->light(i).pos();
125 fLightIntensity[fNumNonAmbLights] = lights->light(i).intensi ty();
126 } else {
122 fLightDirOrPos[fNumNonAmbLights] = lights->light(i).dir(); 127 fLightDirOrPos[fNumNonAmbLights] = lights->light(i).dir();
123 fLightIntensity[fNumNonAmbLights] = 0.0f; 128 fLightIntensity[fNumNonAmbLights] = 0.0f;
124 } else if (SkLights::Light::kPoint_LightType == lights->light(i) .type()) {
125 fLightDirOrPos[fNumNonAmbLights] = lights->light(i).pos();
126 fLightIntensity[fNumNonAmbLights] = lights->light(i).intensi ty();
127 } 129 }
128
129 fIsPointLight[fNumNonAmbLights] = 130 fIsPointLight[fNumNonAmbLights] =
130 SkLights::Light::kPoint_LightType == lights->light(i).ty pe(); 131 SkLights::Light::kPoint_LightType == lights->light(i).t ype();
131 132
132 SkImage_Base* shadowMap = ((SkImage_Base*)lights->light(i).getSh adowMap()); 133 SkImage_Base* shadowMap = ((SkImage_Base*)lights->light(i).getSh adowMap());
133 134
134 // gets deleted when the ShadowFP is destroyed, and frees the Gr Texture* 135 // gets deleted when the ShadowFP is destroyed, and frees the Gr Texture*
135 fTexture[fNumNonAmbLights] = sk_sp<GrTexture>(shadowMap->asTextu reRef(context, 136 fTexture[fNumNonAmbLights] = sk_sp<GrTexture>(shadowMap->asTextu reRef(context,
136 GrTextureParams::Clam pNoFilter(), 137 GrTextureParams::Clam pNoFilter(),
137 SkSourceGammaTreatmen t::kIgnore)); 138 SkSourceGammaTreatmen t::kIgnore));
138 fDepthMapAccess[fNumNonAmbLights].reset(fTexture[fNumNonAmbLight s].get()); 139 fDepthMapAccess[fNumNonAmbLights].reset(fTexture[fNumNonAmbLight s].get());
139 this->addTextureAccess(&fDepthMapAccess[fNumNonAmbLights]); 140 this->addTextureAccess(&fDepthMapAccess[fNumNonAmbLights]);
140 141
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 690
690 fPovDepthContext->shadeSpan(x, y, diffuse, n); 691 fPovDepthContext->shadeSpan(x, y, diffuse, n);
691 fDiffuseContext->shadeSpan(x, y, diffuse, n); 692 fDiffuseContext->shadeSpan(x, y, diffuse, n);
692 693
693 for (int i = 0; i < n; ++i) { 694 for (int i = 0; i < n; ++i) {
694 695
695 SkColor diffColor = SkUnPreMultiply::PMColorToColor(diffuse[i]); 696 SkColor diffColor = SkUnPreMultiply::PMColorToColor(diffuse[i]);
696 697
697 SkColor3f accum = SkColor3f::Make(0.0f, 0.0f, 0.0f); 698 SkColor3f accum = SkColor3f::Make(0.0f, 0.0f, 0.0f);
698 // This is all done in linear unpremul color space (each component 0 ..255.0f though) 699 // This is all done in linear unpremul color space (each component 0 ..255.0f though)
699
700 accum.fX += lightShader.fLights->ambientLightColor().fX * SkColorGet R(diffColor);
701 accum.fY += lightShader.fLights->ambientLightColor().fY * SkColorGet G(diffColor);
702 accum.fZ += lightShader.fLights->ambientLightColor().fZ * SkColorGet B(diffColor);
703
704 for (int l = 0; l < lightShader.fLights->numLights(); ++l) { 700 for (int l = 0; l < lightShader.fLights->numLights(); ++l) {
705 const SkLights::Light& light = lightShader.fLights->light(l); 701 const SkLights::Light& light = lightShader.fLights->light(l);
706 702
707 if (SkLights::Light::kDirectional_LightType == light.type()) { 703 if (SkLights::Light::kAmbient_LightType == light.type()) {
704 accum.fX += light.color().fX * SkColorGetR(diffColor);
705 accum.fY += light.color().fY * SkColorGetG(diffColor);
706 accum.fZ += light.color().fZ * SkColorGetB(diffColor);
707 } else if (SkLights::Light::kDirectional_LightType == light.type ()) {
708 // scaling by fZ accounts for lighting direction 708 // scaling by fZ accounts for lighting direction
709 accum.fX += light.color().makeScale(light.dir().fZ).fX * 709 accum.fX += light.color().makeScale(light.dir().fZ).fX *
710 SkColorGetR(diffColor); 710 SkColorGetR(diffColor);
711 accum.fY += light.color().makeScale(light.dir().fZ).fY * 711 accum.fY += light.color().makeScale(light.dir().fZ).fY *
712 SkColorGetG(diffColor); 712 SkColorGetG(diffColor);
713 accum.fZ += light.color().makeScale(light.dir().fZ).fZ * 713 accum.fZ += light.color().makeScale(light.dir().fZ).fZ *
714 SkColorGetB(diffColor); 714 SkColorGetB(diffColor);
715 } else { 715 } else {
716 // TODO: do point lights for raster, currently treated like ambient
716 accum.fX += light.color().fX * SkColorGetR(diffColor); 717 accum.fX += light.color().fX * SkColorGetR(diffColor);
717 accum.fY += light.color().fY * SkColorGetG(diffColor); 718 accum.fY += light.color().fY * SkColorGetG(diffColor);
718 accum.fZ += light.color().fZ * SkColorGetB(diffColor); 719 accum.fZ += light.color().fZ * SkColorGetB(diffColor);
719 } 720 }
720
721 } 721 }
722 722
723 result[i] = convert(accum, SkColorGetA(diffColor)); 723 result[i] = convert(accum, SkColorGetA(diffColor));
724 } 724 }
725 725
726 result += n; 726 result += n;
727 x += n; 727 x += n;
728 count -= n; 728 count -= n;
729 } while (count > 0); 729 } while (count > 0);
730 } 730 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 836
837 /////////////////////////////////////////////////////////////////////////////// 837 ///////////////////////////////////////////////////////////////////////////////
838 838
839 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) 839 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader)
840 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) 840 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl)
841 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 841 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
842 842
843 /////////////////////////////////////////////////////////////////////////////// 843 ///////////////////////////////////////////////////////////////////////////////
844 844
845 #endif 845 #endif
OLDNEW
« no previous file with comments | « src/core/SkLights.cpp ('k') | src/utils/SkShadowPaintFilterCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698