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

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: 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 fNumDirLights = 0; // refers to directional lights. 116 fNumDirLights = 0; // refers to directional 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 (fNumDirLights < SkShadowShader::kMaxNonAmbientLights) {
120 fAmbientColor += lights->light(i).color();
121 } else if (fNumDirLights < SkShadowShader::kMaxNonAmbientLights) {
122 fLightColor[fNumDirLights] = lights->light(i).color(); 119 fLightColor[fNumDirLights] = lights->light(i).color();
123 fLightDir[fNumDirLights] = lights->light(i).dir(); 120 fLightDir[fNumDirLights] = lights->light(i).dir();
124 SkImage_Base* shadowMap = ((SkImage_Base*)lights->light(i).getSh adowMap()); 121 SkImage_Base* shadowMap = ((SkImage_Base*)lights->light(i).getSh adowMap());
125 122
126 // gets deleted when the ShadowFP is destroyed, and frees the Gr Texture* 123 // gets deleted when the ShadowFP is destroyed, and frees the Gr Texture*
127 fTexture[fNumDirLights] = sk_sp<GrTexture>(shadowMap->asTextureR ef(context, 124 fTexture[fNumDirLights] = sk_sp<GrTexture>(shadowMap->asTextureR ef(context,
128 GrTextureParams::Clam pNoFilter(), 125 GrTextureParams::Clam pNoFilter(),
129 SkSourceGammaTreatmen t::kIgnore)); 126 SkSourceGammaTreatmen t::kIgnore));
130 fDepthMapAccess[fNumDirLights].reset(fTexture[fNumDirLights].get ()); 127 fDepthMapAccess[fNumDirLights].reset(fTexture[fNumDirLights].get ());
131 this->addTextureAccess(&fDepthMapAccess[fNumDirLights]); 128 this->addTextureAccess(&fDepthMapAccess[fNumDirLights]);
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 610
614 do { 611 do {
615 int n = SkTMin(count, BUFFER_MAX); 612 int n = SkTMin(count, BUFFER_MAX);
616 613
617 fPovDepthContext->shadeSpan(x, y, diffuse, n); 614 fPovDepthContext->shadeSpan(x, y, diffuse, n);
618 fDiffuseContext->shadeSpan(x, y, diffuse, n); 615 fDiffuseContext->shadeSpan(x, y, diffuse, n);
619 616
620 for (int i = 0; i < n; ++i) { 617 for (int i = 0; i < n; ++i) {
621 618
622 SkColor diffColor = SkUnPreMultiply::PMColorToColor(diffuse[i]); 619 SkColor diffColor = SkUnPreMultiply::PMColorToColor(diffuse[i]);
623 620
robertphillips 2016/08/26 16:08:05 set accum to the ambient light color now ?
624 SkColor3f accum = SkColor3f::Make(0.0f, 0.0f, 0.0f); 621 SkColor3f accum = SkColor3f::Make(0.0f, 0.0f, 0.0f);
625 // This is all done in linear unpremul color space (each component 0 ..255.0f though) 622 // This is all done in linear unpremul color space (each component 0 ..255.0f though)
623
624 accum.fX += lightShader.fLights->ambientLightColor().fX * SkColorGet R(diffColor);
625 accum.fY += lightShader.fLights->ambientLightColor().fY * SkColorGet G(diffColor);
626 accum.fZ += lightShader.fLights->ambientLightColor().fZ * SkColorGet B(diffColor);
627
626 for (int l = 0; l < lightShader.fLights->numLights(); ++l) { 628 for (int l = 0; l < lightShader.fLights->numLights(); ++l) {
627 const SkLights::Light& light = lightShader.fLights->light(l); 629 const SkLights::Light& light = lightShader.fLights->light(l);
628 630
629 if (SkLights::Light::kAmbient_LightType == light.type()) { 631 // scaling by fZ accounts for lighting direction
630 accum.fX += light.color().fX * SkColorGetR(diffColor); 632 accum.fX += light.color().makeScale(light.dir().fZ).fX * SkColor GetR(diffColor);
631 accum.fY += light.color().fY * SkColorGetG(diffColor); 633 accum.fY += light.color().makeScale(light.dir().fZ).fY * SkColor GetG(diffColor);
632 accum.fZ += light.color().fZ * SkColorGetB(diffColor); 634 accum.fZ += light.color().makeScale(light.dir().fZ).fZ * SkColor GetB(diffColor);
633 } else {
634 // scaling by fZ accounts for lighting direction
635 accum.fX += light.color().makeScale(light.dir().fZ).fX * SkC olorGetR(diffColor);
636 accum.fY += light.color().makeScale(light.dir().fZ).fY * SkC olorGetG(diffColor);
637 accum.fZ += light.color().makeScale(light.dir().fZ).fZ * SkC olorGetB(diffColor);
638 }
639 } 635 }
640 636
641 result[i] = convert(accum, SkColorGetA(diffColor)); 637 result[i] = convert(accum, SkColorGetA(diffColor));
642 } 638 }
643 639
644 result += n; 640 result += n;
645 x += n; 641 x += n;
646 count -= n; 642 count -= n;
647 } while (count > 0); 643 } while (count > 0);
648 } 644 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 750
755 /////////////////////////////////////////////////////////////////////////////// 751 ///////////////////////////////////////////////////////////////////////////////
756 752
757 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) 753 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader)
758 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) 754 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl)
759 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 755 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
760 756
761 /////////////////////////////////////////////////////////////////////////////// 757 ///////////////////////////////////////////////////////////////////////////////
762 758
763 #endif 759 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698