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

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: Cleaned up code 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 d0b37fb15ab7921f259a93f2ed2c236f3fb124cf..59f954109432a7b6c31d0fec123c2377f6ff6f65 100644
--- a/samplecode/SampleShadowing.cpp
+++ b/samplecode/SampleShadowing.cpp
@@ -19,11 +19,10 @@ public:
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)));
+ builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.3f, 0.5f, 0.7f),
+ SkVector3::Make(150.0f, 150.0f, 300.0f)));
+ builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.7f, 0.5f, 0.3f),
+ SkVector3::Make(250.0f, 250.0f, 300.0f)));
fLights = builder.finish();
fTestRects[0].fColor = 0xFFEE8888;
@@ -44,6 +43,7 @@ public:
fSelectedRect = -1;
fMoveLight = false;
+ fLightDepth = 300.0f;
fClearShadowMaps = false;
}
@@ -67,6 +67,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,9 +125,9 @@ 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 {
@@ -135,22 +143,16 @@ 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)));
+ builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.3f, 0.5f, 0.7f),
+ SkVector3::Make(x - 50,
+ 350 - y,
+ fLightDepth)));
+
+ builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.7f, 0.5f, 0.3f),
+ SkVector3::Make(x + 50,
+ 450 - y,
+ fLightDepth)));
fLights = builder.finish();
fLightsChanged = true;
@@ -208,6 +210,8 @@ private:
bool fSceneChanged;
bool fLightsChanged;
+ SkScalar fLightDepth;
+
sk_sp<SkLights> fLights;
typedef SampleView INHERITED;

Powered by Google App Engine
This is Rietveld 408576698