Add ability to rotate light direction in drawLitAtlas Sample slide

As requested by Greg.

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2032263004

Review-Url: https://codereview.chromium.org/2032263004
diff --git a/samplecode/SampleLitAtlas.cpp b/samplecode/SampleLitAtlas.cpp
index 4f989af..f1d67e5 100644
--- a/samplecode/SampleLitAtlas.cpp
+++ b/samplecode/SampleLitAtlas.cpp
@@ -21,7 +21,8 @@
 public:
     DrawLitAtlasDrawable(const SkRect& r)
         : fBounds(r)
-        , fUseColors(false) {
+        , fUseColors(false)
+        , fLightDir(SkVector3::Make(1.0f, 0.0f, 0.0f)) {
         fAtlas = MakeAtlas();
 
         SkRandom rand;
@@ -31,19 +32,25 @@
 
         fShip.initShip(fBounds, &fDiffTex[kNumAsteroids], &fNormTex[kNumAsteroids]);
 
-        SkLights::Builder builder;
-
-        builder.add(SkLights::Light(SkColor3f::Make(1.0f, 1.0f, 1.0f),
-                                    SkVector3::Make(1.0f, 0.0f, 0.0f)));
-        builder.add(SkLights::Light(SkColor3f::Make(0.2f, 0.2f, 0.2f)));
-
-        fLights = builder.finish();
+        this->updateLights();
     }
 
     void toggleUseColors() {
         fUseColors = !fUseColors;
     }
 
+    void rotateLight() {
+        SkScalar c;
+        SkScalar s = SkScalarSinCos(SK_ScalarPI/6.0f, &c);
+
+        SkScalar newX = c * fLightDir.fX - s * fLightDir.fY;
+        SkScalar newY = s * fLightDir.fX + c * fLightDir.fY;
+
+        fLightDir.set(newX, newY, 0.0f);
+
+        this->updateLights();
+    }
+
     void left() {
         SkScalar newRot = SkScalarMod(fShip.rot() + (2*SK_ScalarPI - SK_ScalarPI/32.0f),
                                       2 * SK_ScalarPI);
@@ -91,7 +98,9 @@
 
 #ifdef SK_DEBUG
         canvas->drawBitmap(fAtlas, 0, 0); // just to see the atlas
-#endif        
+
+        this->drawLightDir(canvas, fBounds.centerX(), fBounds.centerY());
+#endif
 
 #if 0
         // TODO: revitalize when drawLitAtlas API lands
@@ -121,6 +130,7 @@
 
             // 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));
@@ -165,6 +175,36 @@
 
     static const int kObjTypeCount = kLast_ObjType + 1;
 
+    void updateLights() {        
+        SkLights::Builder builder;
+
+        builder.add(SkLights::Light(SkColor3f::Make(1.0f, 1.0f, 1.0f), fLightDir));
+        builder.add(SkLights::Light(SkColor3f::Make(0.2f, 0.2f, 0.2f)));
+
+        fLights = builder.finish();
+    }
+
+#ifdef SK_DEBUG
+    // Draw a vector to the light
+    void drawLightDir(SkCanvas* canvas, SkScalar centerX, SkScalar centerY) {
+        static const int kBgLen = 30;
+        static const int kSmLen = 5;
+
+        // TODO: change the lighting coordinate system to be right handed
+        SkPoint p1 = SkPoint::Make(centerX + kBgLen * fLightDir.fX,
+                                   centerY - kBgLen * fLightDir.fY);
+        SkPoint p2 = SkPoint::Make(centerX + (kBgLen-kSmLen) * fLightDir.fX,
+                                   centerY - (kBgLen-kSmLen) * fLightDir.fY);
+
+        SkPaint p;
+        canvas->drawLine(centerX, centerY, p1.fX, p1.fY, p);
+        canvas->drawLine(p1.fX, p1.fY,
+                         p2.fX - kSmLen * fLightDir.fY, p2.fY - kSmLen * fLightDir.fX, p);
+        canvas->drawLine(p1.fX, p1.fY,
+                         p2.fX + kSmLen * fLightDir.fY, p2.fY + kSmLen * fLightDir.fX, p);
+    }
+#endif
+
     // Create the mixed diffuse & normal atlas
     // 
     //    big color circle  |  big normal hemi
@@ -398,6 +438,7 @@
     SkRect          fNormTex[kNumAsteroids+kNumShips];
     SkRect          fBounds;
     bool            fUseColors;
+    SkVector3       fLightDir;
     sk_sp<SkLights> fLights;
 
     typedef SkDrawable INHERITED;
@@ -434,6 +475,10 @@
                     fDrawable->right();
                     this->inval(NULL); 
                     return true;
+                case 'o':
+                    fDrawable->rotateLight();
+                    this->inval(NULL); 
+                    return true;
                 default:
                     break;
             }
diff --git a/src/core/SkLightingShader.cpp b/src/core/SkLightingShader.cpp
index cb25944..d011712f 100644
--- a/src/core/SkLightingShader.cpp
+++ b/src/core/SkLightingShader.cpp
@@ -510,8 +510,8 @@
 
             xformedNorm.fX = lightShader.fInvNormRotation.fX * norm.fX +
                              lightShader.fInvNormRotation.fY * norm.fY;
-            xformedNorm.fY = lightShader.fInvNormRotation.fX * norm.fX -
-                             lightShader.fInvNormRotation.fY * norm.fY;
+            xformedNorm.fY = -lightShader.fInvNormRotation.fY * norm.fX +
+                             lightShader.fInvNormRotation.fX * norm.fY;
             xformedNorm.fZ = norm.fZ;
 
             SkColor diffColor = SkUnPreMultiply::PMColorToColor(tmpColor2[i]);