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

Unified Diff: samplecode/SampleLighting.cpp

Issue 1265983003: Address some SkLightingShader TODOs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix type Created 5 years, 5 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/effects/SkPoint3.h ('k') | src/effects/SkLightingShader.h » ('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 3cda0c6a5692b826341e58b6bff1302fcec47e24..5b4f2e0931b1c43ca3892d7cb15ebdd7cc96e210 100755
--- a/samplecode/SampleLighting.cpp
+++ b/samplecode/SampleLighting.cpp
@@ -20,8 +20,8 @@ public:
SkBitmap fDiffuseBitmap;
SkBitmap fNormalBitmap;
SkScalar fLightAngle;
- int fColorFactor;
- SkColor fAmbientColor;
+ SkScalar fColorFactor;
+ SkColor3f fAmbientColor;
LightingView() {
SkString diffusePath = GetResourcePath("brickwork-texture.jpg");
@@ -30,15 +30,15 @@ public:
SkImageDecoder::DecodeFile(normalPath.c_str(), &fNormalBitmap);
fLightAngle = 0.0f;
- fColorFactor = 0;
+ fColorFactor = 0.0f;
SkLightingShader::Light light;
- light.fColor = SkColorSetRGB(0xff, 0xff, 0xff);
+ 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);
- fAmbientColor = SkColorSetRGB(0x1f, 0x1f, 0x1f);
+ fAmbientColor = SkColor3f::Make(0.1f, 0.1f, 0.1f);
fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap,
light, fAmbientColor, nullptr));
@@ -58,10 +58,13 @@ protected:
void onDrawContent(SkCanvas* canvas) override {
fLightAngle += 0.015f;
- fColorFactor++;
+ fColorFactor += 0.01f;
+ if (fColorFactor > 1.0f) {
+ fColorFactor = 0.0f;
+ }
SkLightingShader::Light light;
- light.fColor = SkColorSetRGB(0xff, 0xff, (fColorFactor >> 1) & 0xff);
+ 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);
« no previous file with comments | « include/effects/SkPoint3.h ('k') | src/effects/SkLightingShader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698