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

Unified Diff: samplecode/SampleLighting.cpp

Issue 1261433009: Refugee from Dead Machine 11: Add SkCanvas::drawLitAtlas call Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update Created 4 years, 8 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/utils/SkMatrix44.h ('k') | samplecode/SampleLitAtlas.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleLighting.cpp
diff --git a/samplecode/SampleLighting.cpp b/samplecode/SampleLighting.cpp
index 5b4f2e0931b1c43ca3892d7cb15ebdd7cc96e210..4be894a210753ef6563a0cfce1bbab0c772f8f61 100755
--- a/samplecode/SampleLighting.cpp
+++ b/samplecode/SampleLighting.cpp
@@ -11,6 +11,22 @@
#include "SkCanvas.h"
#include "SkImageDecoder.h"
#include "SkLightingShader.h"
+#include "SkPoint3.h"
+#include "SkRSXform.h"
+
+static const SkLightingShader::Lights* create_lights(SkScalar angle, SkScalar blue) {
+
+ const SkVector3 dir = SkVector3::Make(SkScalarSin(angle)*SkScalarSin(SK_ScalarPI*0.25f),
+ SkScalarCos(angle)*SkScalarSin(SK_ScalarPI*0.25f),
+ SkScalarCos(SK_ScalarPI*0.25f));
+
+ SkLightingShader::Lights::Builder builder;
+
+ builder.add(SkLight(SkColor3f::Make(1.0f, 1.0f, blue), dir));
+ builder.add(SkLight(SkColor3f::Make(0.1f, 0.1f, 0.1f)));
+
+ return builder.finish();
+}
////////////////////////////////////////////////////////////////////////////
@@ -21,7 +37,6 @@ public:
SkBitmap fNormalBitmap;
SkScalar fLightAngle;
SkScalar fColorFactor;
- SkColor3f fAmbientColor;
LightingView() {
SkString diffusePath = GetResourcePath("brickwork-texture.jpg");
@@ -32,16 +47,13 @@ public:
fLightAngle = 0.0f;
fColorFactor = 0.0f;
- SkLightingShader::Light light;
- light.fColor = SkColor3f::Make(1.0f, 1.0f, 1.0f);
- light.fDirection.fX = SkScalarSin(fLightAngle)*SkScalarSin(SK_ScalarPI*0.25f);
- light.fDirection.fY = SkScalarCos(fLightAngle)*SkScalarSin(SK_ScalarPI*0.25f);
- light.fDirection.fZ = SkScalarCos(SK_ScalarPI*0.25f);
+ SkAutoTUnref<const SkLightingShader::Lights> lights(create_lights(fLightAngle, 1.0f));
- fAmbientColor = SkColor3f::Make(0.1f, 0.1f, 0.1f);
+ SkRSXform xform;
+ xform.setIdentity();
fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap,
- light, fAmbientColor, nullptr));
+ lights, xform, nullptr, nullptr));
}
virtual ~LightingView() {}
@@ -63,14 +75,14 @@ protected:
fColorFactor = 0.0f;
}
- SkLightingShader::Light light;
- light.fColor = SkColor3f::Make(1.0f, 1.0f, fColorFactor);
- light.fDirection.fX = SkScalarSin(fLightAngle)*SkScalarSin(SK_ScalarPI*0.25f);
- light.fDirection.fY = SkScalarCos(fLightAngle)*SkScalarSin(SK_ScalarPI*0.25f);
- light.fDirection.fZ = SkScalarCos(SK_ScalarPI*0.25f);
+ SkAutoTUnref<const SkLightingShader::Lights> lights(create_lights(fLightAngle,
+ fColorFactor));
+
+ SkRSXform xform;
+ xform.setIdentity();
fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap,
- light, fAmbientColor, nullptr));
+ lights, xform, nullptr, nullptr));
SkPaint paint;
paint.setShader(fShader);
« no previous file with comments | « include/utils/SkMatrix44.h ('k') | samplecode/SampleLitAtlas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698