Chromium Code Reviews| Index: samplecode/SampleShadowing.cpp |
| diff --git a/samplecode/SampleShadowing.cpp b/samplecode/SampleShadowing.cpp |
| index 3907db30cc1a5ea6ac26fd9af7769adb1de02bd4..beb7c600ba42fdc3c8293205880233bd2223ae36 100644 |
| --- a/samplecode/SampleShadowing.cpp |
| +++ b/samplecode/SampleShadowing.cpp |
| @@ -13,22 +13,6 @@ |
| #ifdef SK_EXPERIMENTAL_SHADOWING |
| -static sk_sp<SkShader> make_shadow_shader(sk_sp<SkImage> povDepth, |
| - sk_sp<SkImage> diffuse, |
| - sk_sp<SkLights> lights) { |
| - |
| - sk_sp<SkShader> povDepthShader = povDepth->makeShader(SkShader::kClamp_TileMode, |
| - SkShader::kClamp_TileMode); |
| - |
| - sk_sp<SkShader> diffuseShader = diffuse->makeShader(SkShader::kClamp_TileMode, |
| - SkShader::kClamp_TileMode); |
| - |
| - return SkShadowShader::Make(std::move(povDepthShader), |
| - std::move(diffuseShader), |
| - std::move(lights), |
| - diffuse->width(), diffuse->height()); |
| -} |
| - |
| class ShadowingView : public SampleView { |
| public: |
| ShadowingView() { |
| @@ -74,6 +58,9 @@ protected: |
| case 'L': |
| fMoveLight = !fMoveLight; |
| break; |
|
robertphillips
2016/08/08 14:18:31
// Comment about why you need this here ?
vjiaoblack
2016/08/08 15:48:31
Done.
|
| + case 'd': |
| + fClearShadowMaps = true; |
|
jvanverth1
2016/08/08 14:15:47
Should this be a toggle? How do you set it to fals
vjiaoblack
2016/08/08 15:48:31
When the if (fClearShadowMaps) triggers, I edited
|
| + break; |
| default: |
| break; |
| } |
| @@ -111,103 +98,22 @@ protected: |
| return recorder.finishRecordingAsPicture(); |
| } |
| - void updateDepthMaps(SkCanvas *canvas) { |
| - for (int i = 0; i < fLights->numLights(); ++i) { |
| - // skip over ambient lights; they don't cast shadows |
| - if (SkLights::Light::kAmbient_LightType == fLights->light(i).type()) { |
| - continue; |
| - } |
| - |
| - // TODO: maybe add a kDepth_8_SkColorType when vertices have depth |
| - // assume max depth is 255. |
| - // TODO: find actual max depth of picture |
| - SkISize shMapSize = SkShadowPaintFilterCanvas:: |
| - ComputeDepthMapSize(fLights->light(i), 255, kWidth, kHeight); |
| - |
| - SkImageInfo info = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight, |
| - kBGRA_8888_SkColorType, |
| - kOpaque_SkAlphaType); |
| - |
| - // Create a new surface (that matches the backend of canvas) |
| - // for each shadow map |
| - sk_sp<SkSurface> surf(canvas->makeSurface(info)); |
| - |
| - // Wrap another SPFCanvas around the surface |
| - sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = |
| - sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); |
| - |
| - // set the depth map canvas to have the light we're drawing. |
| - SkLights::Builder builder; |
| - builder.add(fLights->light(i)); |
| - sk_sp<SkLights> curLight = builder.finish(); |
| - |
| - depthMapCanvas->setLights(std::move(curLight)); |
| - depthMapCanvas->drawPicture(fPicture); |
| - |
| - fLights->light(i).setShadowMap(surf->makeImageSnapshot()); |
| - } |
| - } |
| - |
| - void updatePovDepthMap(SkCanvas* canvas) { |
| - // TODO: pass the depth to the shader in vertices, or uniforms |
| - // so we don't have to render depth and color separately |
| - |
| - SkLights::Builder builder; |
| - builder.add(SkLights::Light(SkColor3f::Make(1.0f, 1.0f, 1.0f), |
| - SkVector3::Make(0.0f, 0.0f, 1.0f))); |
| - sk_sp<SkLights> povLight = builder.finish(); |
| - |
| - SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, |
| - kBGRA_8888_SkColorType, |
| - kOpaque_SkAlphaType); |
| - |
| - // Create a new surface (that matches the backend of canvas) |
| - // to create the povDepthMap |
| - sk_sp<SkSurface> surf(canvas->makeSurface(info)); |
| - |
| - // Wrap another SPFCanvas around the surface |
| - sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas = |
| - sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas()); |
| - |
| - // set the depth map canvas to have the light as the user's POV |
| - depthMapCanvas->setLights(std::move(povLight)); |
| - |
| - depthMapCanvas->drawPicture(fPicture); |
| - |
| - fPovDepthMap = surf->makeImageSnapshot(); |
| - } |
| - |
| - void updateDiffuseMap(SkCanvas* canvas) { |
| - SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, |
| - kBGRA_8888_SkColorType, |
| - kOpaque_SkAlphaType); |
| - |
| - sk_sp<SkSurface> surf(canvas->makeSurface(info)); |
| - surf->getCanvas()->drawPicture(fPicture); |
| - |
| - fDiffuseMap = surf->makeImageSnapshot(); |
| - } |
| - |
| void onDrawContent(SkCanvas *canvas) override { |
| if (fSceneChanged || !fPovDepthMap) { |
| fPicture = this->makeTestPicture(kWidth, kHeight); |
| - this->updateDepthMaps(canvas); |
| - this->updatePovDepthMap(canvas); |
| - this->updateDiffuseMap(canvas); |
| - } |
| - |
| - if (fLightsChanged) { |
| - this->updateDepthMaps(canvas); |
|
jvanverth1
2016/08/08 14:15:47
Any thoughts on how you'd manage this caching with
vjiaoblack
2016/08/08 15:48:31
yeah, we just only cache when there is no change a
|
| } |
| if (fSceneChanged || fLightsChanged || !fShadowShader) { |
| - fShadowShader = make_shadow_shader(fPovDepthMap, fDiffuseMap, fLights); |
| - } |
| - |
| - SkPaint paint; |
| - paint.setShader(fShadowShader); |
| + if (fClearShadowMaps) { |
| + for (int i = 0; i < fLights->numLights(); i++) { |
| + fLights->light(i).setShadowMap(nullptr); |
| + } |
| + } |
| - canvas->drawRect(SkRect::MakeIWH(kWidth, kHeight), paint); |
| + canvas->setLights(fLights); |
|
robertphillips
2016/08/08 14:18:31
pass in nullptr for paint argument ?
vjiaoblack
2016/08/08 15:48:31
Done.
|
| + SkPaint paint; |
| + canvas->drawShadowedPicture(fPicture, nullptr, &paint); |
| + } |
| } |
| SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override { |
| @@ -277,6 +183,7 @@ private: |
| static const int kWidth = 400; |
| static const int kHeight = 400; |
| + bool fClearShadowMaps; |
|
jvanverth1
2016/08/08 14:15:47
This is never initialized.
vjiaoblack
2016/08/08 15:48:31
Done.
|
| struct { |
| SkRect fGeometry; |