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

Unified Diff: samplecode/SampleShadowing.cpp

Issue 2246463004: Added distance attenuation and diffuse shading to PointLights (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: rebased off of master (with variance shadow mapping) 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
Index: samplecode/SampleShadowing.cpp
diff --git a/samplecode/SampleShadowing.cpp b/samplecode/SampleShadowing.cpp
index e27b4cff328d1a1b0059d5c3e610849c56f8bdd7..96623b69bda422b25cafd376b16d8b137e5c5a9f 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;
@@ -53,13 +53,14 @@ public:
fSceneChanged = true;
fLightsChanged = true;
robertphillips 2016/08/25 17:41:43 this too
vjiaoblack 2016/08/26 12:37:22 Done.
- fSelectedRect = -1;
+ fSelectedRectID = -1;
fSelectedSlider = -1;
robertphillips 2016/08/25 17:41:43 this too
vjiaoblack 2016/08/26 12:37:22 Done.
fMoveLight = false;
robertphillips 2016/08/25 17:41:43 these too
vjiaoblack 2016/08/26 12:37:22 Done.
+ fLightDepth = 300.0f;
fClearShadowMaps = false;
- fShadowParams.fShadowRadius = 2.0f;
+ fShadowParams.fShadowRadius = 4.0f;
fShadowParams.fBiasingConstant = 0.3f;
fShadowParams.fMinVariance = 1024;
fShadowParams.fType = SkShadowParams::kVariance_ShadowType;
@@ -85,6 +86,9 @@ protected:
// the shadow maps will be re-generated according to the new backend.
fClearShadowMaps = true;
break;
+ case 'q':
+ fLightDepth += 5.0f;
+ fMoveLight = true;
case 'B':
if (SkShadowParams::kVariance_ShadowType == fShadowParams.fType) {
fShadowParams.fType = SkShadowParams::kNoBlur_ShadowType;
@@ -94,6 +98,10 @@ protected:
}
fLightsChanged = true;
break;
+ case 'w':
+ fLightDepth -= 5.0f;
+ fMoveLight = true;
+ break;
default:
break;
}
@@ -154,12 +162,32 @@ protected:
paint.setColor(SK_ColorBLACK);
canvas->drawRect(fSliders[i].fGeometry, paint);
}
robertphillips 2016/08/25 17:41:43 ?? we're doing this above
vjiaoblack 2016/08/26 12:37:22 Done.
vjiaoblack 2016/08/26 12:37:22 Done.
+ canvas->setLights(fLights);
+ canvas->drawShadowedPicture(fPicture, nullptr, nullptr, fShadowParams);
}
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.2f, 0.4f, 0.6f),
+ SkVector3::Make(x - 50,
+ 350 - y,
+ fLightDepth),
+ 1024));
+
+ builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.6f, 0.4f, 0.2f),
+ SkVector3::Make(x + 50,
+ 450 - y,
+ fLightDepth),
+ 1024));
+ builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.2f, 0.2f, 0.2f),
+ SkVector3::Make(0.2f, 0.2f, 1.0f)));
+ fLights = builder.finish();
+ }
+
void updateFromSelectedSlider() {
SkScalar newValue = fSliders[fSelectedSlider].fGeometry.fLeft *
fSliders[fSelectedSlider].fScale +
@@ -189,24 +217,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);
}
@@ -214,13 +225,13 @@ protected:
}
if (click->fState == Click::State::kUp_State) {
- fSelectedRect = -1;
+ fSelectedRectID = -1;
fSelectedSlider = -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);
@@ -240,7 +251,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;
@@ -273,12 +284,17 @@ private:
static const int kWidth = 400;
static const int kHeight = 400;
+ bool fSceneChanged;
+ bool fLightsChanged;
+ bool fMoveLight;
+ bool fClearShadowMaps;
+
struct {
SkRect fGeometry;
int fDepth;
SkColor fColor;
} fTestRects[kNumTestRects];
- int fSelectedRect;
+ int fSelectedRectID;
struct {
SkRect fGeometry;
@@ -287,10 +303,7 @@ private:
} fSliders[kNumSliders];
int fSelectedSlider;
- bool fClearShadowMaps;
- bool fMoveLight;
- bool fSceneChanged;
- bool fLightsChanged;
+ SkScalar fLightDepth;
sk_sp<SkPicture> fPicture;
SkShadowParams fShadowParams;
« no previous file with comments | « include/core/SkLights.h ('k') | src/core/SkLights.cpp » ('j') | src/core/SkShadowShader.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698