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

Unified Diff: gm/lightingshader2.cpp

Issue 2239933004: LightingFP now supports multiple directional lights (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Resolved rebase conflicts 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 | « no previous file | include/core/SkLights.h » ('j') | src/core/SkLightingShader.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/lightingshader2.cpp
diff --git a/gm/lightingshader2.cpp b/gm/lightingshader2.cpp
index 70c9e29f69cae5ba5b00b603e1fcd7fb83a9ed71..5afe2558b906b9594698699677772b33f9631bfb 100644
--- a/gm/lightingshader2.cpp
+++ b/gm/lightingshader2.cpp
@@ -23,7 +23,7 @@ static SkBitmap make_frustum_normalmap(int texSize) {
namespace skiagm {
// This GM exercises lighting shaders. Specifically, nullptr arguments, scaling when using
-// normal maps, and paint transparency.
+// normal maps, paint transparency, zero directional lights, multiple directional lights.
class LightingShader2GM : public GM {
public:
LightingShader2GM() {
@@ -40,14 +40,30 @@ protected:
}
void onOnceBeforeDraw() override {
- SkLights::Builder builder;
const SkVector3 kLightFromUpperRight = SkVector3::Make(0.788f, 0.394f, 0.473f);
+ const SkVector3 kLightFromUpperLeft = SkVector3::Make(-0.788f, 0.394f, 0.473f);
+ // Standard set of lights
+ SkLights::Builder builder;
builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(1.0f, 1.0f, 1.0f),
kLightFromUpperRight));
builder.add(SkLights::Light::MakeAmbient(SkColor3f::Make(0.2f, 0.2f, 0.2f)));
fLights = builder.finish();
+ // No directional lights
+ SkLights::Builder builderNoDir;
+ builderNoDir.add(SkLights::Light::MakeAmbient(SkColor3f::Make(0.2f, 0.2f, 0.2f)));
+ fLightsNoDir = builderNoDir.finish();
+
+ // Two directional lights
+ SkLights::Builder builderTwoDir;
+ builderTwoDir.add(SkLights::Light::MakeDirectional(SkColor3f::Make(1.0f, 0.0f, 1.0f),
+ kLightFromUpperRight));
+ builderTwoDir.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.0f, 1.0f, 1.0f),
+ kLightFromUpperLeft));
+ builderTwoDir.add(SkLights::Light::MakeAmbient(SkColor3f::Make(0.2f, 0.2f, 0.2f)));
+ fLightsTwoDir = builderTwoDir.finish();
+
fRect = SkRect::MakeIWH(kTexSize, kTexSize);
SkMatrix matrix;
SkRect bitmapBounds = SkRect::MakeIWH(kTexSize, kTexSize);
@@ -87,7 +103,7 @@ protected:
static constexpr int NUM_BOOLEAN_PARAMS = 4;
void drawRect(SkCanvas* canvas, SkScalar scaleX, SkScalar scaleY,
SkScalar rotate, bool useNormalSource, bool useDiffuseShader,
- bool useTranslucentPaint, bool useTranslucentShader) {
+ bool useTranslucentPaint, bool useTranslucentShader, sk_sp<SkLights> lights) {
canvas->save();
this->positionCTM(canvas, scaleX, scaleY, rotate);
@@ -113,7 +129,7 @@ protected:
}
paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::move(normalSource),
- fLights));
+ std::move(lights)));
canvas->drawRect(fRect, paint);
canvas->restore();
@@ -147,7 +163,7 @@ protected:
canvas->translate(xPos, yPos);
this->drawRect(canvas, 1.0f, 1.0f, 0.f, useNormalSource, useDiffuseShader,
- useTranslucentPaint, useTranslucentShader);
+ useTranslucentPaint, useTranslucentShader, fLights);
// Drawing labels
canvas->translate(0.0f, SkIntToScalar(kTexSize));
{
@@ -191,7 +207,7 @@ protected:
canvas->save();
canvas->translate(xPos, yPos);
- this->drawRect(canvas, 0.6f, 0.6f, 45.0f, true, true, true, true);
+ this->drawRect(canvas, 0.6f, 0.6f, 45.0f, true, true, true, true, fLights);
canvas->restore();
gridNum++;
@@ -204,7 +220,33 @@ protected:
canvas->save();
canvas->translate(xPos, yPos);
- this->drawRect(canvas, 0.6f, 0.4f, 30.0f, true, true, true, true);
+ this->drawRect(canvas, 0.6f, 0.4f, 30.0f, true, true, true, true, fLights);
+ canvas->restore();
+
+ gridNum++;
+ }
+
+ // No directional lights test
+ {
+ SkScalar xPos = (gridNum % GRID_COLUMN_NUM) * GRID_CELL_WIDTH;
+ SkScalar yPos = (gridNum / GRID_COLUMN_NUM) * GRID_CELL_WIDTH;
+
+ canvas->save();
+ canvas->translate(xPos, yPos);
+ this->drawRect(canvas, 1.0f, 1.0f, 0.0f, true, true, false, false, fLightsNoDir);
+ canvas->restore();
+
+ gridNum++;
+ }
+
+ // Two directional lights test
+ {
+ SkScalar xPos = (gridNum % GRID_COLUMN_NUM) * GRID_CELL_WIDTH;
+ SkScalar yPos = (gridNum / GRID_COLUMN_NUM) * GRID_CELL_WIDTH;
+
+ canvas->save();
+ canvas->translate(xPos, yPos);
+ this->drawRect(canvas, 1.0f, 1.0f, 0.0f, true, true, false, false, fLightsTwoDir);
canvas->restore();
gridNum++;
@@ -220,6 +262,8 @@ private:
SkRect fRect;
sk_sp<SkLights> fLights;
+ sk_sp<SkLights> fLightsNoDir;
+ sk_sp<SkLights> fLightsTwoDir;
typedef GM INHERITED;
};
« no previous file with comments | « no previous file | include/core/SkLights.h » ('j') | src/core/SkLightingShader.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698