| Index: samplecode/SampleShadowing.cpp
|
| diff --git a/samplecode/SampleShadowing.cpp b/samplecode/SampleShadowing.cpp
|
| index d0b37fb15ab7921f259a93f2ed2c236f3fb124cf..b2d24e182bde6d2c10b3773c7e3a1f2a7f7510ba 100644
|
| --- a/samplecode/SampleShadowing.cpp
|
| +++ b/samplecode/SampleShadowing.cpp
|
| @@ -15,16 +15,16 @@
|
|
|
| class ShadowingView : public SampleView {
|
| public:
|
| - ShadowingView() {
|
| -
|
| + ShadowingView()
|
| + : fSceneChanged(true)
|
| + , fLightsChanged(true)
|
| + , fMoveLight(false)
|
| + , fClearShadowMaps(false)
|
| + , fSelectedRectID(-1)
|
| + , fLightDepth(300.0f) {
|
| this->setBGColor(0xFFCCCCCC);
|
| - SkLights::Builder builder;
|
| - builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.2f, 0.3f, 0.4f),
|
| - SkVector3::Make(0.2f, 0.05f, 1.0f)));
|
| - builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.4f, 0.3f, 0.2f),
|
| - SkVector3::Make(0.05f, 0.2f, 1.0f)));
|
| - builder.add(SkLights::Light::MakeAmbient(SkColor3f::Make(0.4f, 0.4f, 0.4f)));
|
| - fLights = builder.finish();
|
| +
|
| + this->updateLights(200, 200);
|
|
|
| fTestRects[0].fColor = 0xFFEE8888;
|
| fTestRects[0].fDepth = 80;
|
| @@ -37,14 +37,6 @@ public:
|
| fTestRects[2].fColor = 0xFF8888EE;
|
| fTestRects[2].fDepth = 240;
|
| fTestRects[2].fGeometry = SkRect::MakeLTRB(100,100,250,250);
|
| -
|
| - fSceneChanged = true;
|
| - fLightsChanged = true;
|
| -
|
| - fSelectedRect = -1;
|
| - fMoveLight = false;
|
| -
|
| - fClearShadowMaps = false;
|
| }
|
|
|
| protected:
|
| @@ -67,6 +59,14 @@ protected:
|
| // the shadow maps will be re-generated according to the new backend.
|
| fClearShadowMaps = true;
|
| break;
|
| + case 'q':
|
| + fLightDepth += 5.0f;
|
| + fMoveLight = true;
|
| + break;
|
| + case 'w':
|
| + fLightDepth -= 5.0f;
|
| + fMoveLight = true;
|
| + break;
|
| default:
|
| break;
|
| }
|
| @@ -117,15 +117,31 @@ protected:
|
| fLightsChanged = false;
|
| fClearShadowMaps = false;
|
|
|
| - canvas->setLights(fLights);
|
| - canvas->drawShadowedPicture(fPicture, nullptr, nullptr);
|
| }
|
| + canvas->setLights(fLights);
|
| + canvas->drawShadowedPicture(fPicture, nullptr, nullptr);
|
| }
|
|
|
| SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
|
| return new SkView::Click(this);
|
| }
|
|
|
| + void updateLights(int x, int y) {
|
| + SkLights::Builder builder;
|
| + builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.3f, 0.5f, 0.7f),
|
| + SkVector3::Make(x - 50,
|
| + 350 - y,
|
| + fLightDepth),
|
| + 1024));
|
| +
|
| + builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.7f, 0.5f, 0.3f),
|
| + SkVector3::Make(x + 50,
|
| + 450 - y,
|
| + fLightDepth),
|
| + 1024));
|
| + fLights = builder.finish();
|
| + }
|
| +
|
| bool onClick(Click *click) override {
|
| SkScalar x = click->fCurr.fX;
|
| SkScalar y = click->fCurr.fY;
|
| @@ -135,24 +151,7 @@ protected:
|
|
|
| if (fMoveLight) {
|
| if (dx != 0 || dy != 0) {
|
| - float recipX = 1.0f / kWidth;
|
| - float recipY = 1.0f / kHeight;
|
| -
|
| - SkLights::Builder builder;
|
| - builder.add(SkLights::Light::MakeDirectional(
|
| - SkColor3f::Make(0.2f, 0.3f, 0.4f),
|
| - SkVector3::Make(0.2f + (200.0f - x) * recipX,
|
| - 0.05f + (200.0f - y) * recipY,
|
| - 1.0f)));
|
| - builder.add(SkLights::Light::MakeDirectional(
|
| - SkColor3f::Make(0.4f, 0.3f, 0.2f),
|
| - SkVector3::Make(0.05f + (200.0f - x) * recipX,
|
| - 0.2f + (200.0f - y) * recipY,
|
| - 1.0f)));
|
| - builder.add(SkLights::Light::MakeAmbient(
|
| - SkColor3f::Make(0.4f, 0.4f, 0.4f)));
|
| - fLights = builder.finish();
|
| -
|
| + this->updateLights(x, y);
|
| fLightsChanged = true;
|
| this->inval(nullptr);
|
| }
|
| @@ -160,12 +159,12 @@ protected:
|
| }
|
|
|
| if (click->fState == Click::State::kUp_State) {
|
| - fSelectedRect = -1;
|
| + fSelectedRectID = -1;
|
| return true;
|
| }
|
|
|
| - if (fSelectedRect > -1) {
|
| - fTestRects[fSelectedRect].fGeometry.offset(dx, dy);
|
| + if (fSelectedRectID > -1) {
|
| + fTestRects[fSelectedRectID].fGeometry.offset(dx, dy);
|
|
|
| fSceneChanged = true;
|
| this->inval(nullptr);
|
| @@ -175,7 +174,7 @@ protected:
|
| // assume last elements are highest
|
| for (int i = kNumTestRects - 1; i >= 0; i--) {
|
| if (fTestRects[i].fGeometry.contains(SkRect::MakeXYWH(x, y, 1, 1))) {
|
| - fSelectedRect = i;
|
| + fSelectedRectID = i;
|
| fTestRects[i].fGeometry.offset(dx, dy);
|
|
|
| fSceneChanged = true;
|
| @@ -192,6 +191,10 @@ private:
|
|
|
| static const int kWidth = 400;
|
| static const int kHeight = 400;
|
| +
|
| + bool fSceneChanged;
|
| + bool fLightsChanged;
|
| + bool fMoveLight;
|
| bool fClearShadowMaps;
|
|
|
| struct {
|
| @@ -200,14 +203,11 @@ private:
|
| SkColor fColor;
|
| } fTestRects[kNumTestRects];
|
|
|
| - int fSelectedRect;
|
| - bool fMoveLight;
|
| + int fSelectedRectID;
|
| + SkScalar fLightDepth;
|
|
|
| sk_sp<SkPicture> fPicture;
|
|
|
| - bool fSceneChanged;
|
| - bool fLightsChanged;
|
| -
|
| sk_sp<SkLights> fLights;
|
|
|
| typedef SampleView INHERITED;
|
|
|