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

Unified Diff: samplecode/SampleShadowing.cpp

Issue 2224163005: Made shadows blurry (thru implementing variance mapping) (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Trying different include path Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/private/SkShadowParams.h ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleShadowing.cpp
diff --git a/samplecode/SampleShadowing.cpp b/samplecode/SampleShadowing.cpp
index 37eec18ba43a120f591b20d6863f01480b453e7d..e27b4cff328d1a1b0059d5c3e610849c56f8bdd7 100644
--- a/samplecode/SampleShadowing.cpp
+++ b/samplecode/SampleShadowing.cpp
@@ -38,13 +38,31 @@ public:
fTestRects[2].fDepth = 240;
fTestRects[2].fGeometry = SkRect::MakeLTRB(100,100,250,250);
+ fSliders[0].fGeometry = SkRect::MakeLTRB(20, 400, 30, 420);
+ fSliders[0].fOffset = 0.0f;
+ fSliders[0].fScale = 0.1f;
+
+ fSliders[1].fGeometry = SkRect::MakeLTRB(100, 420, 110, 440);
+ fSliders[1].fOffset = 0.0f;
+ fSliders[1].fScale = 10.0f;
+
+ fSliders[2].fGeometry = SkRect::MakeLTRB(0, 440, 10, 460);
+ fSliders[2].fOffset = 0.0f;
+ fSliders[2].fScale = 0.0025f;
+
fSceneChanged = true;
fLightsChanged = true;
fSelectedRect = -1;
+ fSelectedSlider = -1;
fMoveLight = false;
fClearShadowMaps = false;
+
+ fShadowParams.fShadowRadius = 2.0f;
+ fShadowParams.fBiasingConstant = 0.3f;
+ fShadowParams.fMinVariance = 1024;
+ fShadowParams.fType = SkShadowParams::kVariance_ShadowType;
}
protected:
@@ -67,6 +85,15 @@ protected:
// the shadow maps will be re-generated according to the new backend.
fClearShadowMaps = true;
break;
+ case 'B':
+ if (SkShadowParams::kVariance_ShadowType == fShadowParams.fType) {
+ fShadowParams.fType = SkShadowParams::kNoBlur_ShadowType;
+ } else if (SkShadowParams::kNoBlur_ShadowType ==
+ fShadowParams.fType) {
+ fShadowParams.fType = SkShadowParams::kVariance_ShadowType;
+ }
+ fLightsChanged = true;
+ break;
default:
break;
}
@@ -113,19 +140,46 @@ protected:
for (int i = 0; i < fLights->numLights(); i++) {
fLights->light(i).setShadowMap(nullptr);
}
+
fSceneChanged = false;
fLightsChanged = false;
fClearShadowMaps = false;
}
canvas->setLights(fLights);
- canvas->drawShadowedPicture(fPicture, nullptr, nullptr);
+ canvas->drawShadowedPicture(fPicture, nullptr, nullptr, fShadowParams);
+
+ for (int i = 0; i < kNumSliders; i++) {
+ SkPaint paint;
+ paint.setColor(SK_ColorBLACK);
+ canvas->drawRect(fSliders[i].fGeometry, paint);
+ }
}
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
return new SkView::Click(this);
}
+ void updateFromSelectedSlider() {
+ SkScalar newValue = fSliders[fSelectedSlider].fGeometry.fLeft *
+ fSliders[fSelectedSlider].fScale +
+ fSliders[fSelectedSlider].fOffset;
+
+ switch (fSelectedSlider) {
+ case 0:
+ fShadowParams.fShadowRadius = newValue;
+ break;
+ case 1:
+ fShadowParams.fMinVariance = newValue;
+ break;
+ case 2:
+ fShadowParams.fBiasingConstant = newValue;
+ break;
+ default:
+ break;
+ }
+ }
+
bool onClick(Click *click) override {
SkScalar x = click->fCurr.fX;
SkScalar y = click->fCurr.fY;
@@ -161,6 +215,7 @@ protected:
if (click->fState == Click::State::kUp_State) {
fSelectedRect = -1;
+ fSelectedSlider = -1;
return true;
}
@@ -172,6 +227,16 @@ protected:
return true;
}
+ if (fSelectedSlider > -1) {
+ fSliders[fSelectedSlider].fGeometry.offset(dx, 0);
+
+ this->updateFromSelectedSlider();
+
+ fLightsChanged = true;
+ this->inval(nullptr);
+ return true;
+ }
+
// assume last elements are highest
for (int i = kNumTestRects - 1; i >= 0; i--) {
if (fTestRects[i].fGeometry.contains(SkRect::MakeXYWH(x, y, 1, 1))) {
@@ -184,30 +249,51 @@ protected:
}
}
+ for (int i = 0; i <= kNumSliders; i++) {
+ if (fSliders[i].fGeometry.contains(SkRect::MakeXYWH(x, y, 1, 1))) {
+ fSelectedSlider = i;
+ fSliders[i].fGeometry.offset(dx, 0);
+
+ this->updateFromSelectedSlider();
+
+ fLightsChanged = true;
+
+ this->inval(nullptr);
+ break;
+ }
+ }
+
return true;
}
private:
static constexpr int kNumTestRects = 3;
+ static constexpr int kNumSliders = 3;
static const int kWidth = 400;
static const int kHeight = 400;
- bool fClearShadowMaps;
struct {
SkRect fGeometry;
int fDepth;
SkColor fColor;
} fTestRects[kNumTestRects];
-
int fSelectedRect;
- bool fMoveLight;
- sk_sp<SkPicture> fPicture;
+ struct {
+ SkRect fGeometry;
+ SkScalar fOffset;
+ SkScalar fScale;
+ } fSliders[kNumSliders];
+ int fSelectedSlider;
+ bool fClearShadowMaps;
+ bool fMoveLight;
bool fSceneChanged;
bool fLightsChanged;
+ sk_sp<SkPicture> fPicture;
+ SkShadowParams fShadowParams;
sk_sp<SkLights> fLights;
typedef SampleView INHERITED;
« no previous file with comments | « include/private/SkShadowParams.h ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698