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

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

Issue 2287553002: Moved ambient lights out of SkLight's light array (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
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 // fuse all ambient lights into a single one 114 fAmbientColor = lights->ambientLightColor();
115 fAmbientColor.set(0.0f, 0.0f, 0.0f);
116 115
117 fNumNonAmbLights = 0; // count of non-ambient lights 116 fNumNonAmbLights = 0; // count of non-ambient lights
118 for (int i = 0; i < lights->numLights(); ++i) { 117 for (int i = 0; i < lights->numLights(); ++i) {
119 if (SkLights::Light::kAmbient_LightType == lights->light(i).type()) { 118 if (fNumNonAmbLights < SkShadowShader::kMaxNonAmbientLights) {
120 fAmbientColor += lights->light(i).color();
121 } else if (fNumNonAmbLights < SkShadowShader::kMaxNonAmbientLights) {
122 fLightColor[fNumNonAmbLights] = lights->light(i).color(); 119 fLightColor[fNumNonAmbLights] = lights->light(i).color();
123 if (lights->light(i).type() == SkLights::Light::kPoint_LightType ) { 120
121 if (SkLights::Light::kDirectional_LightType == lights->light(i). type()) {
122 fLightDirOrPos[fNumNonAmbLights] = lights->light(i).dir();
123 } else if (SkLights::Light::kPoint_LightType == lights->light(i) .type()) {
124 fLightDirOrPos[fNumNonAmbLights] = lights->light(i).pos(); 124 fLightDirOrPos[fNumNonAmbLights] = lights->light(i).pos();
125 fLightIntensity[fNumNonAmbLights] = lights->light(i).intensi ty();
126 } else {
127 fLightDirOrPos[fNumNonAmbLights] = lights->light(i).dir();
128 fLightIntensity[fNumNonAmbLights] = 0.0f;
129 } 125 }
robertphillips 2016/08/26 19:16:02 It looks like this is still used, why did you remo
vjiaoblack 2016/08/26 19:25:17 Done.
130 fIsPointLight[fNumNonAmbLights] =
131 SkLights::Light::kPoint_LightType == lights->light(i).t ype();
132 126
133 SkImage_Base* shadowMap = ((SkImage_Base*)lights->light(i).getSh adowMap()); 127 SkImage_Base* shadowMap = ((SkImage_Base*)lights->light(i).getSh adowMap());
134 128
135 // gets deleted when the ShadowFP is destroyed, and frees the Gr Texture* 129 // gets deleted when the ShadowFP is destroyed, and frees the Gr Texture*
136 fTexture[fNumNonAmbLights] = sk_sp<GrTexture>(shadowMap->asTextu reRef(context, 130 fTexture[fNumNonAmbLights] = sk_sp<GrTexture>(shadowMap->asTextu reRef(context,
137 GrTextureParams::Clam pNoFilter(), 131 GrTextureParams::Clam pNoFilter(),
138 SkSourceGammaTreatmen t::kIgnore)); 132 SkSourceGammaTreatmen t::kIgnore));
139 fDepthMapAccess[fNumNonAmbLights].reset(fTexture[fNumNonAmbLight s].get()); 133 fDepthMapAccess[fNumNonAmbLights].reset(fTexture[fNumNonAmbLight s].get());
140 this->addTextureAccess(&fDepthMapAccess[fNumNonAmbLights]); 134 this->addTextureAccess(&fDepthMapAccess[fNumNonAmbLights]);
141 135
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 684
691 fPovDepthContext->shadeSpan(x, y, diffuse, n); 685 fPovDepthContext->shadeSpan(x, y, diffuse, n);
692 fDiffuseContext->shadeSpan(x, y, diffuse, n); 686 fDiffuseContext->shadeSpan(x, y, diffuse, n);
693 687
694 for (int i = 0; i < n; ++i) { 688 for (int i = 0; i < n; ++i) {
695 689
696 SkColor diffColor = SkUnPreMultiply::PMColorToColor(diffuse[i]); 690 SkColor diffColor = SkUnPreMultiply::PMColorToColor(diffuse[i]);
697 691
698 SkColor3f accum = SkColor3f::Make(0.0f, 0.0f, 0.0f); 692 SkColor3f accum = SkColor3f::Make(0.0f, 0.0f, 0.0f);
699 // This is all done in linear unpremul color space (each component 0 ..255.0f though) 693 // This is all done in linear unpremul color space (each component 0 ..255.0f though)
694
695 accum.fX += lightShader.fLights->ambientLightColor().fX * SkColorGet R(diffColor);
696 accum.fY += lightShader.fLights->ambientLightColor().fY * SkColorGet G(diffColor);
697 accum.fZ += lightShader.fLights->ambientLightColor().fZ * SkColorGet B(diffColor);
698
700 for (int l = 0; l < lightShader.fLights->numLights(); ++l) { 699 for (int l = 0; l < lightShader.fLights->numLights(); ++l) {
701 const SkLights::Light& light = lightShader.fLights->light(l); 700 const SkLights::Light& light = lightShader.fLights->light(l);
702 701
703 if (SkLights::Light::kAmbient_LightType == light.type()) { 702 if (SkLights::Light::kDirectional_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 703 // scaling by fZ accounts for lighting direction
709 accum.fX += light.color().makeScale(light.dir().fZ).fX * 704 accum.fX += light.color().makeScale(light.dir().fZ).fX *
710 SkColorGetR(diffColor); 705 SkColorGetR(diffColor);
711 accum.fY += light.color().makeScale(light.dir().fZ).fY * 706 accum.fY += light.color().makeScale(light.dir().fZ).fY *
712 SkColorGetG(diffColor); 707 SkColorGetG(diffColor);
713 accum.fZ += light.color().makeScale(light.dir().fZ).fZ * 708 accum.fZ += light.color().makeScale(light.dir().fZ).fZ *
714 SkColorGetB(diffColor); 709 SkColorGetB(diffColor);
715 } else { 710 } else {
716 // TODO: do point lights for raster, currently treated like ambient
717 accum.fX += light.color().fX * SkColorGetR(diffColor); 711 accum.fX += light.color().fX * SkColorGetR(diffColor);
718 accum.fY += light.color().fY * SkColorGetG(diffColor); 712 accum.fY += light.color().fY * SkColorGetG(diffColor);
719 accum.fZ += light.color().fZ * SkColorGetB(diffColor); 713 accum.fZ += light.color().fZ * SkColorGetB(diffColor);
720 } 714 }
715
721 } 716 }
722 717
723 result[i] = convert(accum, SkColorGetA(diffColor)); 718 result[i] = convert(accum, SkColorGetA(diffColor));
724 } 719 }
725 720
726 result += n; 721 result += n;
727 x += n; 722 x += n;
728 count -= n; 723 count -= n;
729 } while (count > 0); 724 } while (count > 0);
730 } 725 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 831
837 /////////////////////////////////////////////////////////////////////////////// 832 ///////////////////////////////////////////////////////////////////////////////
838 833
839 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) 834 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader)
840 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) 835 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl)
841 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 836 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
842 837
843 /////////////////////////////////////////////////////////////////////////////// 838 ///////////////////////////////////////////////////////////////////////////////
844 839
845 #endif 840 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698