Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 |
|
robertphillips
2016/08/26 17:31:28
the old name was more descriptive of what is going
vjiaoblack
2016/08/26 18:10:38
Done.
| |
| 117 fNumNonAmbLights = 0; // count of non-ambient lights | 116 fNumLights = 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 (fNumLights < SkShadowShader::kMaxLights) { |
| 120 fAmbientColor += lights->light(i).color(); | 119 fLightColor[fNumLights] = lights->light(i).color(); |
|
robertphillips
2016/08/26 17:31:29
Won't this fail an assert ?
vjiaoblack
2016/08/26 18:10:38
Done.
| |
| 121 } else if (fNumNonAmbLights < SkShadowShader::kMaxNonAmbientLights) { | 120 fLightDirOrPos[fNumLights] = lights->light(i).dir(); |
| 122 fLightColor[fNumNonAmbLights] = lights->light(i).color(); | |
| 123 if (lights->light(i).type() == SkLights::Light::kPoint_LightType ) { | |
| 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 } | |
| 130 fIsPointLight[fNumNonAmbLights] = | |
| 131 SkLights::Light::kPoint_LightType == lights->light(i).t ype(); | |
| 132 | |
| 133 SkImage_Base* shadowMap = ((SkImage_Base*)lights->light(i).getSh adowMap()); | 121 SkImage_Base* shadowMap = ((SkImage_Base*)lights->light(i).getSh adowMap()); |
| 134 | 122 |
| 135 // 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* |
| 136 fTexture[fNumNonAmbLights] = sk_sp<GrTexture>(shadowMap->asTextu reRef(context, | 124 fTexture[fNumLights] = sk_sp<GrTexture>(shadowMap->asTextureRef( context, |
| 137 GrTextureParams::Clam pNoFilter(), | 125 GrTextureParams::Clam pNoFilter(), |
| 138 SkSourceGammaTreatmen t::kIgnore)); | 126 SkSourceGammaTreatmen t::kIgnore)); |
| 139 fDepthMapAccess[fNumNonAmbLights].reset(fTexture[fNumNonAmbLight s].get()); | 127 fDepthMapAccess[fNumLights].reset(fTexture[fNumLights].get()); |
| 140 this->addTextureAccess(&fDepthMapAccess[fNumNonAmbLights]); | 128 this->addTextureAccess(&fDepthMapAccess[fNumLights]); |
| 141 | 129 |
| 142 fDepthMapHeight[fNumNonAmbLights] = shadowMap->height(); | 130 fDepthMapHeight[fNumLights] = shadowMap->height(); |
| 143 fDepthMapWidth[fNumNonAmbLights] = shadowMap->width(); | 131 fDepthMapWidth[fNumLights] = shadowMap->width(); |
| 144 | 132 |
| 145 fNumNonAmbLights++; | 133 fNumLights++; |
| 146 } | 134 } |
| 147 } | 135 } |
| 148 | 136 |
| 149 fWidth = diffuseWidth; | 137 fWidth = diffuseWidth; |
| 150 fHeight = diffuseHeight; | 138 fHeight = diffuseHeight; |
| 151 | 139 |
| 152 fShadowParams = params; | 140 fShadowParams = params; |
| 153 | 141 |
| 154 this->registerChildProcessor(std::move(povDepth)); | 142 this->registerChildProcessor(std::move(povDepth)); |
| 155 this->registerChildProcessor(std::move(diffuse)); | 143 this->registerChildProcessor(std::move(diffuse)); |
| 156 this->initClassID<ShadowFP>(); | 144 this->initClassID<ShadowFP>(); |
| 157 } | 145 } |
| 158 | 146 |
| 159 class GLSLShadowFP : public GrGLSLFragmentProcessor { | 147 class GLSLShadowFP : public GrGLSLFragmentProcessor { |
| 160 public: | 148 public: |
| 161 GLSLShadowFP() { } | 149 GLSLShadowFP() { } |
| 162 | 150 |
| 163 void emitCode(EmitArgs& args) override { | 151 void emitCode(EmitArgs& args) override { |
| 164 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; | 152 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 165 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; | 153 GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
| 166 const ShadowFP& shadowFP = args.fFp.cast<ShadowFP>(); | 154 const ShadowFP& shadowFP = args.fFp.cast<ShadowFP>(); |
| 167 | 155 |
| 168 SkASSERT(shadowFP.fNumNonAmbLights <= SkShadowShader::kMaxNonAmbient Lights); | 156 SkASSERT(shadowFP.fNumLights <= SkShadowShader::kMaxLights); |
| 169 | 157 |
| 170 // add uniforms | 158 // add uniforms |
| 171 int32_t numLights = shadowFP.fNumNonAmbLights; | 159 int32_t numLights = shadowFP.fNumLights; |
| 172 SkASSERT(numLights <= SkShadowShader::kMaxNonAmbientLights); | 160 SkASSERT(numLights <= SkShadowShader::kMaxLights); |
| 173 | 161 |
| 174 int blurAlgorithm = shadowFP.fShadowParams.fType; | 162 int blurAlgorithm = shadowFP.fShadowParams.fType; |
| 175 | 163 |
| 176 const char* lightDirOrPosUniName[SkShadowShader::kMaxNonAmbientLight s] = {nullptr}; | 164 const char* lightDirOrPosUniName[SkShadowShader::kMaxLights] = {null ptr}; |
| 177 const char* lightColorUniName[SkShadowShader::kMaxNonAmbientLights] = {nullptr}; | 165 const char* lightColorUniName[SkShadowShader::kMaxLights] = {nullptr }; |
| 178 const char* lightIntensityUniName[SkShadowShader::kMaxNonAmbientLigh ts] = {nullptr}; | 166 const char* lightIntensityUniName[SkShadowShader::kMaxLights] = {nul lptr}; |
| 179 | 167 |
| 180 const char* depthMapWidthUniName[SkShadowShader::kMaxNonAmbientLight s] = {nullptr}; | 168 const char* depthMapWidthUniName[SkShadowShader::kMaxLights] = {null ptr}; |
| 181 const char* depthMapHeightUniName[SkShadowShader::kMaxNonAmbientLigh ts] = {nullptr}; | 169 const char* depthMapHeightUniName[SkShadowShader::kMaxLights] = {nul lptr}; |
| 182 | 170 |
| 183 for (int i = 0; i < shadowFP.fNumNonAmbLights; i++) { | 171 for (int i = 0; i < shadowFP.fNumLights; i++) { |
| 184 SkString lightDirOrPosUniNameStr("lightDir"); | 172 SkString lightDirOrPosUniNameStr("lightDir"); |
| 185 lightDirOrPosUniNameStr.appendf("%d", i); | 173 lightDirOrPosUniNameStr.appendf("%d", i); |
| 186 SkString lightColorUniNameStr("lightColor"); | 174 SkString lightColorUniNameStr("lightColor"); |
| 187 lightColorUniNameStr.appendf("%d", i); | 175 lightColorUniNameStr.appendf("%d", i); |
| 188 SkString lightIntensityUniNameStr("lightIntensity"); | 176 SkString lightIntensityUniNameStr("lightIntensity"); |
| 189 lightIntensityUniNameStr.appendf("%d", i); | 177 lightIntensityUniNameStr.appendf("%d", i); |
| 190 | 178 |
| 191 SkString depthMapWidthUniNameStr("dmapWidth"); | 179 SkString depthMapWidthUniNameStr("dmapWidth"); |
| 192 depthMapWidthUniNameStr.appendf("%d", i); | 180 depthMapWidthUniNameStr.appendf("%d", i); |
| 193 SkString depthMapHeightUniNameStr("dmapHeight"); | 181 SkString depthMapHeightUniNameStr("dmapHeight"); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 kInt_GrSLType, | 233 kInt_GrSLType, |
| 246 kDefault_GrSLPrecision, | 234 kDefault_GrSLPrecision, |
| 247 "height", &heightUniName); | 235 "height", &heightUniName); |
| 248 | 236 |
| 249 SkString povDepth("povDepth"); | 237 SkString povDepth("povDepth"); |
| 250 this->emitChild(0, nullptr, &povDepth, args); | 238 this->emitChild(0, nullptr, &povDepth, args); |
| 251 | 239 |
| 252 SkString diffuseColor("inDiffuseColor"); | 240 SkString diffuseColor("inDiffuseColor"); |
| 253 this->emitChild(1, nullptr, &diffuseColor, args); | 241 this->emitChild(1, nullptr, &diffuseColor, args); |
| 254 | 242 |
| 255 SkString depthMaps[SkShadowShader::kMaxNonAmbientLights]; | 243 SkString depthMaps[SkShadowShader::kMaxLights]; |
| 256 | 244 |
| 257 // Multiply by 255 to transform from sampler coordinates to world | 245 // Multiply by 255 to transform from sampler coordinates to world |
| 258 // coordinates (since 1 channel is 0xFF) | 246 // coordinates (since 1 channel is 0xFF) |
| 259 fragBuilder->codeAppendf("vec3 worldCor = vec3(vMatrixCoord_0_1_Stag e0 * " | 247 fragBuilder->codeAppendf("vec3 worldCor = vec3(vMatrixCoord_0_1_Stag e0 * " |
| 260 "vec2(%s, %s), %s.b * 255); ", | 248 "vec2(%s, %s), %s.b * 255); ", |
| 261 widthUniName, heightUniName, povDepth.c_str ()); | 249 widthUniName, heightUniName, povDepth.c_str ()); |
| 262 | 250 |
| 263 // Applies the offset indexing that goes from our view space into th e light's space. | 251 // Applies the offset indexing that goes from our view space into th e light's space. |
| 264 for (int i = 0; i < shadowFP.fNumNonAmbLights; i++) { | 252 for (int i = 0; i < shadowFP.fNumLights; i++) { |
| 265 SkString povCoord("povCoord"); | 253 SkString povCoord("povCoord"); |
| 266 povCoord.appendf("%d", i); | 254 povCoord.appendf("%d", i); |
| 267 | 255 |
| 268 // vMatrixCoord_0_1_Stage0 is the texture sampler coordinates. | 256 // vMatrixCoord_0_1_Stage0 is the texture sampler coordinates. |
| 269 // povDepth.b * 255 scales it to 0 - 255, bringing it to world s pace, | 257 // povDepth.b * 255 scales it to 0 - 255, bringing it to world s pace, |
| 270 // and the / vec2(width, height) brings it back to a sampler coo rdinate | 258 // and the / vec2(width, height) brings it back to a sampler coo rdinate |
| 271 SkString offset("offset"); | 259 SkString offset("offset"); |
| 272 offset.appendf("%d", i); | 260 offset.appendf("%d", i); |
| 273 | 261 |
| 274 SkString scaleVec("scaleVec"); | 262 SkString scaleVec("scaleVec"); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 | 380 |
| 393 fragBuilder->codeAppendf("resultDiffuseColor *= vec4(%s, 1);", | 381 fragBuilder->codeAppendf("resultDiffuseColor *= vec4(%s, 1);", |
| 394 totalLightColor.c_str()); | 382 totalLightColor.c_str()); |
| 395 | 383 |
| 396 fragBuilder->codeAppendf("%s = resultDiffuseColor;", args.fOutputCol or); | 384 fragBuilder->codeAppendf("%s = resultDiffuseColor;", args.fOutputCol or); |
| 397 } | 385 } |
| 398 | 386 |
| 399 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | 387 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
| 400 GrProcessorKeyBuilder* b) { | 388 GrProcessorKeyBuilder* b) { |
| 401 const ShadowFP& shadowFP = proc.cast<ShadowFP>(); | 389 const ShadowFP& shadowFP = proc.cast<ShadowFP>(); |
| 402 b->add32(shadowFP.fNumNonAmbLights); | 390 b->add32(shadowFP.fNumLights); |
| 403 int isPL = 0; | 391 int isPL = 0; |
| 404 for (int i = 0; i < SkShadowShader::kMaxNonAmbientLights; i++) { | 392 for (int i = 0; i < SkShadowShader::kMaxLights; i++) { |
| 405 isPL = isPL | ((shadowFP.fIsPointLight[i] ? 1 : 0) << i); | 393 isPL = isPL | ((shadowFP.fIsPointLight[i] ? 1 : 0) << i); |
| 406 } | 394 } |
| 407 b->add32(isPL); | 395 b->add32(isPL); |
| 408 b->add32(shadowFP.fShadowParams.fType); | 396 b->add32(shadowFP.fShadowParams.fType); |
| 409 } | 397 } |
| 410 | 398 |
| 411 protected: | 399 protected: |
| 412 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override { | 400 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override { |
| 413 const ShadowFP &shadowFP = proc.cast<ShadowFP>(); | 401 const ShadowFP &shadowFP = proc.cast<ShadowFP>(); |
| 414 | 402 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 } | 455 } |
| 468 | 456 |
| 469 const SkColor3f& ambientColor = shadowFP.ambientColor(); | 457 const SkColor3f& ambientColor = shadowFP.ambientColor(); |
| 470 if (ambientColor != fAmbientColor) { | 458 if (ambientColor != fAmbientColor) { |
| 471 pdman.set3fv(fAmbientColorUni, 1, &ambientColor.fX); | 459 pdman.set3fv(fAmbientColorUni, 1, &ambientColor.fX); |
| 472 fAmbientColor = ambientColor; | 460 fAmbientColor = ambientColor; |
| 473 } | 461 } |
| 474 } | 462 } |
| 475 | 463 |
| 476 private: | 464 private: |
| 477 SkVector3 fLightDirOrPos[SkShadowShader::kMaxNonAmbientLights]; | 465 SkVector3 fLightDirOrPos[SkShadowShader::kMaxLights]; |
| 478 GrGLSLProgramDataManager::UniformHandle | 466 GrGLSLProgramDataManager::UniformHandle |
| 479 fLightDirOrPosUni[SkShadowShader::kMaxNonAmbientLights]; | 467 fLightDirOrPosUni[SkShadowShader::kMaxLights]; |
| 480 | 468 |
| 481 SkColor3f fLightColor[SkShadowShader::kMaxNonAmbientLights]; | 469 SkColor3f fLightColor[SkShadowShader::kMaxLights]; |
| 482 GrGLSLProgramDataManager::UniformHandle | 470 GrGLSLProgramDataManager::UniformHandle |
| 483 fLightColorUni[SkShadowShader::kMaxNonAmbientLights]; | 471 fLightColorUni[SkShadowShader::kMaxLights]; |
| 484 | 472 |
| 485 SkScalar fLightIntensity[SkShadowShader::kMaxNonAmbientLights]; | 473 SkScalar fLightIntensity[SkShadowShader::kMaxLights]; |
| 486 GrGLSLProgramDataManager::UniformHandle | 474 GrGLSLProgramDataManager::UniformHandle |
| 487 fLightIntensityUni[SkShadowShader::kMaxNonAmbientLights]; | 475 fLightIntensityUni[SkShadowShader::kMaxLights]; |
| 488 | 476 |
| 489 int fDepthMapWidth[SkShadowShader::kMaxNonAmbientLights]; | 477 int fDepthMapWidth[SkShadowShader::kMaxLights]; |
| 490 GrGLSLProgramDataManager::UniformHandle | 478 GrGLSLProgramDataManager::UniformHandle |
| 491 fDepthMapWidthUni[SkShadowShader::kMaxNonAmbientLights]; | 479 fDepthMapWidthUni[SkShadowShader::kMaxLights]; |
| 492 | 480 |
| 493 int fDepthMapHeight[SkShadowShader::kMaxNonAmbientLights]; | 481 int fDepthMapHeight[SkShadowShader::kMaxLights]; |
| 494 GrGLSLProgramDataManager::UniformHandle | 482 GrGLSLProgramDataManager::UniformHandle |
| 495 fDepthMapHeightUni[SkShadowShader::kMaxNonAmbientLights]; | 483 fDepthMapHeightUni[SkShadowShader::kMaxLights]; |
| 496 | 484 |
| 497 int fWidth; | 485 int fWidth; |
| 498 GrGLSLProgramDataManager::UniformHandle fWidthUni; | 486 GrGLSLProgramDataManager::UniformHandle fWidthUni; |
| 499 int fHeight; | 487 int fHeight; |
| 500 GrGLSLProgramDataManager::UniformHandle fHeightUni; | 488 GrGLSLProgramDataManager::UniformHandle fHeightUni; |
| 501 | 489 |
| 502 SkScalar fBiasingConstant; | 490 SkScalar fBiasingConstant; |
| 503 GrGLSLProgramDataManager::UniformHandle fBiasingConstantUni; | 491 GrGLSLProgramDataManager::UniformHandle fBiasingConstantUni; |
| 504 SkScalar fMinVariance; | 492 SkScalar fMinVariance; |
| 505 GrGLSLProgramDataManager::UniformHandle fMinVarianceUni; | 493 GrGLSLProgramDataManager::UniformHandle fMinVarianceUni; |
| 506 | 494 |
| 507 SkColor3f fAmbientColor; | 495 SkColor3f fAmbientColor; |
| 508 GrGLSLProgramDataManager::UniformHandle fAmbientColorUni; | 496 GrGLSLProgramDataManager::UniformHandle fAmbientColorUni; |
| 509 }; | 497 }; |
| 510 | 498 |
| 511 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { | 499 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { |
| 512 GLSLShadowFP::GenKey(*this, caps, b); | 500 GLSLShadowFP::GenKey(*this, caps, b); |
| 513 } | 501 } |
| 514 | 502 |
| 515 const char* name() const override { return "shadowFP"; } | 503 const char* name() const override { return "shadowFP"; } |
| 516 | 504 |
| 517 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 505 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 518 inout->mulByUnknownFourComponents(); | 506 inout->mulByUnknownFourComponents(); |
| 519 } | 507 } |
| 520 int32_t numLights() const { return fNumNonAmbLights; } | 508 int32_t numLights() const { return fNumLights; } |
| 521 const SkColor3f& ambientColor() const { return fAmbientColor; } | 509 const SkColor3f& ambientColor() const { return fAmbientColor; } |
| 522 bool isPointLight(int i) const { | 510 bool isPointLight(int i) const { |
| 523 SkASSERT(i < fNumNonAmbLights); | 511 SkASSERT(i < fNumLights); |
| 524 return fIsPointLight[i]; | 512 return fIsPointLight[i]; |
| 525 } | 513 } |
| 526 const SkVector3& lightDirOrPos(int i) const { | 514 const SkVector3& lightDirOrPos(int i) const { |
| 527 SkASSERT(i < fNumNonAmbLights); | 515 SkASSERT(i < fNumLights); |
| 528 return fLightDirOrPos[i]; | 516 return fLightDirOrPos[i]; |
| 529 } | 517 } |
| 530 const SkVector3& lightColor(int i) const { | 518 const SkVector3& lightColor(int i) const { |
| 531 SkASSERT(i < fNumNonAmbLights); | 519 SkASSERT(i < fNumLights); |
| 532 return fLightColor[i]; | 520 return fLightColor[i]; |
| 533 } | 521 } |
| 534 SkScalar lightIntensity(int i) const { | 522 SkScalar lightIntensity(int i) const { |
| 535 SkASSERT(i < fNumNonAmbLights); | 523 SkASSERT(i < fNumLights); |
| 536 return fLightIntensity[i]; | 524 return fLightIntensity[i]; |
| 537 } | 525 } |
| 538 | 526 |
| 539 int depthMapWidth(int i) const { | 527 int depthMapWidth(int i) const { |
| 540 SkASSERT(i < fNumNonAmbLights); | 528 SkASSERT(i < fNumLights); |
| 541 return fDepthMapWidth[i]; | 529 return fDepthMapWidth[i]; |
| 542 } | 530 } |
| 543 int depthMapHeight(int i) const { | 531 int depthMapHeight(int i) const { |
| 544 SkASSERT(i < fNumNonAmbLights); | 532 SkASSERT(i < fNumLights); |
| 545 return fDepthMapHeight[i]; | 533 return fDepthMapHeight[i]; |
| 546 } | 534 } |
| 547 int width() const {return fWidth; } | 535 int width() const {return fWidth; } |
| 548 int height() const {return fHeight; } | 536 int height() const {return fHeight; } |
| 549 | 537 |
| 550 const SkShadowParams& shadowParams() const {return fShadowParams; } | 538 const SkShadowParams& shadowParams() const {return fShadowParams; } |
| 551 | 539 |
| 552 private: | 540 private: |
| 553 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLShadowFP; } | 541 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return new GLSLShadowFP; } |
| 554 | 542 |
| 555 bool onIsEqual(const GrFragmentProcessor& proc) const override { | 543 bool onIsEqual(const GrFragmentProcessor& proc) const override { |
| 556 const ShadowFP& shadowFP = proc.cast<ShadowFP>(); | 544 const ShadowFP& shadowFP = proc.cast<ShadowFP>(); |
| 557 if (fAmbientColor != shadowFP.fAmbientColor || | 545 if (fAmbientColor != shadowFP.fAmbientColor || |
| 558 fNumNonAmbLights != shadowFP.fNumNonAmbLights) { | 546 fNumLights != shadowFP.fNumLights) { |
| 559 return false; | 547 return false; |
| 560 } | 548 } |
| 561 | 549 |
| 562 if (fWidth != shadowFP.fWidth || fHeight != shadowFP.fHeight) { | 550 if (fWidth != shadowFP.fWidth || fHeight != shadowFP.fHeight) { |
| 563 return false; | 551 return false; |
| 564 } | 552 } |
| 565 | 553 |
| 566 for (int i = 0; i < fNumNonAmbLights; i++) { | 554 for (int i = 0; i < fNumLights; i++) { |
| 567 if (fLightDirOrPos[i] != shadowFP.fLightDirOrPos[i] || | 555 if (fLightDirOrPos[i] != shadowFP.fLightDirOrPos[i] || |
| 568 fLightColor[i] != shadowFP.fLightColor[i] || | 556 fLightColor[i] != shadowFP.fLightColor[i] || |
| 569 fLightIntensity[i] != shadowFP.fLightIntensity[i] || | 557 fLightIntensity[i] != shadowFP.fLightIntensity[i] || |
| 570 fIsPointLight[i] != shadowFP.fIsPointLight[i]) { | 558 fIsPointLight[i] != shadowFP.fIsPointLight[i]) { |
| 571 return false; | 559 return false; |
| 572 } | 560 } |
| 573 | 561 |
| 574 if (fDepthMapWidth[i] != shadowFP.fDepthMapWidth[i] || | 562 if (fDepthMapWidth[i] != shadowFP.fDepthMapWidth[i] || |
| 575 fDepthMapHeight[i] != shadowFP.fDepthMapHeight[i]) { | 563 fDepthMapHeight[i] != shadowFP.fDepthMapHeight[i]) { |
| 576 return false; | 564 return false; |
| 577 } | 565 } |
| 578 } | 566 } |
| 579 | 567 |
| 580 return true; | 568 return true; |
| 581 } | 569 } |
| 582 | 570 |
| 583 int fNumNonAmbLights; | 571 int fNumLights; |
| 584 | 572 |
| 585 bool fIsPointLight[SkShadowShader::kMaxNonAmbientLights]; | 573 bool fIsPointLight[SkShadowShader::kMaxLights]; |
| 586 SkVector3 fLightDirOrPos[SkShadowShader::kMaxNonAmbientLights]; | 574 SkVector3 fLightDirOrPos[SkShadowShader::kMaxLights]; |
| 587 SkColor3f fLightColor[SkShadowShader::kMaxNonAmbientLights]; | 575 SkColor3f fLightColor[SkShadowShader::kMaxLights]; |
| 588 SkScalar fLightIntensity[SkShadowShader::kMaxNonAmbientLights]; | 576 SkScalar fLightIntensity[SkShadowShader::kMaxLights]; |
| 589 GrTextureAccess fDepthMapAccess[SkShadowShader::kMaxNonAmbientLights]; | 577 GrTextureAccess fDepthMapAccess[SkShadowShader::kMaxLights]; |
| 590 sk_sp<GrTexture> fTexture[SkShadowShader::kMaxNonAmbientLights]; | 578 sk_sp<GrTexture> fTexture[SkShadowShader::kMaxLights]; |
| 591 | 579 |
| 592 int fDepthMapWidth[SkShadowShader::kMaxNonAmbientLights]; | 580 int fDepthMapWidth[SkShadowShader::kMaxLights]; |
| 593 int fDepthMapHeight[SkShadowShader::kMaxNonAmbientLights]; | 581 int fDepthMapHeight[SkShadowShader::kMaxLights]; |
| 594 | 582 |
| 595 int fHeight; | 583 int fHeight; |
| 596 int fWidth; | 584 int fWidth; |
| 597 | 585 |
| 598 SkShadowParams fShadowParams; | 586 SkShadowParams fShadowParams; |
| 599 | 587 |
| 600 SkColor3f fAmbientColor; | 588 SkColor3f fAmbientColor; |
| 601 }; | 589 }; |
| 602 | 590 |
| 603 //////////////////////////////////////////////////////////////////////////// | 591 //////////////////////////////////////////////////////////////////////////// |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 | 675 |
| 688 do { | 676 do { |
| 689 int n = SkTMin(count, BUFFER_MAX); | 677 int n = SkTMin(count, BUFFER_MAX); |
| 690 | 678 |
| 691 fPovDepthContext->shadeSpan(x, y, diffuse, n); | 679 fPovDepthContext->shadeSpan(x, y, diffuse, n); |
| 692 fDiffuseContext->shadeSpan(x, y, diffuse, n); | 680 fDiffuseContext->shadeSpan(x, y, diffuse, n); |
| 693 | 681 |
| 694 for (int i = 0; i < n; ++i) { | 682 for (int i = 0; i < n; ++i) { |
| 695 | 683 |
| 696 SkColor diffColor = SkUnPreMultiply::PMColorToColor(diffuse[i]); | 684 SkColor diffColor = SkUnPreMultiply::PMColorToColor(diffuse[i]); |
| 697 | 685 |
|
robertphillips
2016/08/26 17:31:29
Again, where does the ambient contribution get add
vjiaoblack
2016/08/26 18:10:38
right at the beginning?
| |
| 698 SkColor3f accum = SkColor3f::Make(0.0f, 0.0f, 0.0f); | 686 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) | 687 // This is all done in linear unpremul color space (each component 0 ..255.0f though) |
| 688 | |
| 689 accum.fX += lightShader.fLights->ambientLightColor().fX * SkColorGet R(diffColor); | |
| 690 accum.fY += lightShader.fLights->ambientLightColor().fY * SkColorGet G(diffColor); | |
| 691 accum.fZ += lightShader.fLights->ambientLightColor().fZ * SkColorGet B(diffColor); | |
| 692 | |
| 700 for (int l = 0; l < lightShader.fLights->numLights(); ++l) { | 693 for (int l = 0; l < lightShader.fLights->numLights(); ++l) { |
| 701 const SkLights::Light& light = lightShader.fLights->light(l); | 694 const SkLights::Light& light = lightShader.fLights->light(l); |
| 702 | 695 |
| 703 if (SkLights::Light::kAmbient_LightType == light.type()) { | 696 // scaling by fZ accounts for lighting direction |
| 704 accum.fX += light.color().fX * SkColorGetR(diffColor); | 697 accum.fX += light.color().makeScale(light.dir().fZ).fX * SkColor GetR(diffColor); |
| 705 accum.fY += light.color().fY * SkColorGetG(diffColor); | 698 accum.fY += light.color().makeScale(light.dir().fZ).fY * SkColor GetG(diffColor); |
| 706 accum.fZ += light.color().fZ * SkColorGetB(diffColor); | 699 accum.fZ += light.color().makeScale(light.dir().fZ).fZ * SkColor GetB(diffColor); |
| 707 } else if (SkLights::Light::kDirectional_LightType == light.type ()) { | |
| 708 // scaling by fZ accounts for lighting direction | |
| 709 accum.fX += light.color().makeScale(light.dir().fZ).fX * | |
| 710 SkColorGetR(diffColor); | |
| 711 accum.fY += light.color().makeScale(light.dir().fZ).fY * | |
| 712 SkColorGetG(diffColor); | |
| 713 accum.fZ += light.color().makeScale(light.dir().fZ).fZ * | |
| 714 SkColorGetB(diffColor); | |
| 715 } else { | |
| 716 // TODO: do point lights for raster, currently treated like ambient | |
| 717 accum.fX += light.color().fX * SkColorGetR(diffColor); | |
| 718 accum.fY += light.color().fY * SkColorGetG(diffColor); | |
| 719 accum.fZ += light.color().fZ * SkColorGetB(diffColor); | |
| 720 } | |
| 721 } | 700 } |
| 722 | 701 |
| 723 result[i] = convert(accum, SkColorGetA(diffColor)); | 702 result[i] = convert(accum, SkColorGetA(diffColor)); |
| 724 } | 703 } |
| 725 | 704 |
| 726 result += n; | 705 result += n; |
| 727 x += n; | 706 x += n; |
| 728 count -= n; | 707 count -= n; |
| 729 } while (count > 0); | 708 } while (count > 0); |
| 730 } | 709 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 836 | 815 |
| 837 /////////////////////////////////////////////////////////////////////////////// | 816 /////////////////////////////////////////////////////////////////////////////// |
| 838 | 817 |
| 839 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) | 818 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkShadowShader) |
| 840 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) | 819 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkShadowShaderImpl) |
| 841 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 820 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| 842 | 821 |
| 843 /////////////////////////////////////////////////////////////////////////////// | 822 /////////////////////////////////////////////////////////////////////////////// |
| 844 | 823 |
| 845 #endif | 824 #endif |
| OLD | NEW |