API change to allow for NormalSource selection at the user level.
This CL's base is the CL for CPU handling: https://codereview.chromium.org/2050773002/
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2063793002
Review-Url: https://codereview.chromium.org/2063793002
diff --git a/samplecode/SampleLighting.cpp b/samplecode/SampleLighting.cpp
index a27aa9d..5949f49 100755
--- a/samplecode/SampleLighting.cpp
+++ b/samplecode/SampleLighting.cpp
@@ -8,8 +8,10 @@
#include "SampleCode.h"
#include "Resources.h"
+#include "SkBitmapProcShader.h"
#include "SkCanvas.h"
#include "SkLightingShader.h"
+#include "SkNormalSource.h"
#include "SkPoint3.h"
static sk_sp<SkLights> create_lights(SkScalar angle, SkScalar blue) {
@@ -64,9 +66,12 @@
sk_sp<SkLights> lights(create_lights(fLightAngle, fColorFactor));
SkPaint paint;
- paint.setShader(SkLightingShader::Make(fDiffuseBitmap, fNormalBitmap,
- std::move(lights), SkVector::Make(1.0f, 0.0f),
- nullptr, nullptr));
+ sk_sp<SkShader> normalMap = SkMakeBitmapShader(fNormalBitmap,
+ SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, nullptr, nullptr);
+ sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(
+ std::move(normalMap), SkMatrix::I());
+ paint.setShader(SkLightingShader::Make(fDiffuseBitmap, std::move(lights), nullptr,
+ std::move(normalSource)));
paint.setColor(SK_ColorBLACK);
SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(),
diff --git a/samplecode/SampleLitAtlas.cpp b/samplecode/SampleLitAtlas.cpp
index f1d67e5..ba42ed8 100644
--- a/samplecode/SampleLitAtlas.cpp
+++ b/samplecode/SampleLitAtlas.cpp
@@ -7,13 +7,15 @@
#include "SampleCode.h"
#include "SkAnimTimer.h"
-#include "SkView.h"
+#include "SkBitmapProcShader.h"
#include "SkCanvas.h"
#include "SkDrawable.h"
#include "SkLightingShader.h"
#include "SkLights.h"
+#include "SkNormalSource.h"
#include "SkRandom.h"
#include "SkRSXform.h"
+#include "SkView.h"
#include "sk_tool_utils.h"
@@ -128,12 +130,12 @@
SkMatrix m;
m.setRSXform(xforms[i]);
- // TODO: correctly pull out the pure rotation
- SkVector invNormRotation = { m[SkMatrix::kMScaleX], m[SkMatrix::kMSkewY] };
- SkASSERT(SkScalarNearlyEqual(invNormRotation.lengthSqd(), SK_Scalar1));
-
- paint.setShader(SkLightingShader::Make(fAtlas, fAtlas, fLights,
- invNormRotation, &diffMat, &normalMat));
+ sk_sp<SkShader> normalMap = SkMakeBitmapShader(fAtlas, SkShader::kClamp_TileMode,
+ SkShader::kClamp_TileMode, &normalMat, nullptr);
+ sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalMap(
+ std::move(normalMap), m);
+ paint.setShader(SkLightingShader::Make(fAtlas, fLights, &diffMat,
+ std::move(normalSource)));
canvas->save();
canvas->setMatrix(m);