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

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

Powered by Google App Engine
This is Rietveld 408576698