OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
10 #include "SkView.h" | 10 #include "SkBitmapProcShader.h" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkDrawable.h" | 12 #include "SkDrawable.h" |
13 #include "SkLightingShader.h" | 13 #include "SkLightingShader.h" |
14 #include "SkLights.h" | 14 #include "SkLights.h" |
| 15 #include "SkNormalSource.h" |
15 #include "SkRandom.h" | 16 #include "SkRandom.h" |
16 #include "SkRSXform.h" | 17 #include "SkRSXform.h" |
| 18 #include "SkView.h" |
17 | 19 |
18 #include "sk_tool_utils.h" | 20 #include "sk_tool_utils.h" |
19 | 21 |
20 class DrawLitAtlasDrawable : public SkDrawable { | 22 class DrawLitAtlasDrawable : public SkDrawable { |
21 public: | 23 public: |
22 DrawLitAtlasDrawable(const SkRect& r) | 24 DrawLitAtlasDrawable(const SkRect& r) |
23 : fBounds(r) | 25 : fBounds(r) |
24 , fUseColors(false) | 26 , fUseColors(false) |
25 , fLightDir(SkVector3::Make(1.0f, 0.0f, 0.0f)) { | 27 , fLightDir(SkVector3::Make(1.0f, 0.0f, 0.0f)) { |
26 fAtlas = MakeAtlas(); | 28 fAtlas = MakeAtlas(); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 123 |
122 SkRect r = fDiffTex[i]; | 124 SkRect r = fDiffTex[i]; |
123 r.offsetTo(0, 0); | 125 r.offsetTo(0, 0); |
124 | 126 |
125 diffMat.setRectToRect(fDiffTex[i], r, SkMatrix::kFill_ScaleToFit); | 127 diffMat.setRectToRect(fDiffTex[i], r, SkMatrix::kFill_ScaleToFit); |
126 normalMat.setRectToRect(fNormTex[i], r, SkMatrix::kFill_ScaleToFit); | 128 normalMat.setRectToRect(fNormTex[i], r, SkMatrix::kFill_ScaleToFit); |
127 | 129 |
128 SkMatrix m; | 130 SkMatrix m; |
129 m.setRSXform(xforms[i]); | 131 m.setRSXform(xforms[i]); |
130 | 132 |
131 // TODO: correctly pull out the pure rotation | 133 sk_sp<SkShader> normalMap = SkMakeBitmapShader(fAtlas, SkShader::kCl
amp_TileMode, |
132 SkVector invNormRotation = { m[SkMatrix::kMScaleX], m[SkMatrix::kMSk
ewY] }; | 134 SkShader::kClamp_TileMode, &normalMat, nullptr); |
133 SkASSERT(SkScalarNearlyEqual(invNormRotation.lengthSqd(), SK_Scalar1
)); | 135 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeFromNormalM
ap( |
134 | 136 std::move(normalMap), m); |
135 paint.setShader(SkLightingShader::Make(fAtlas, fAtlas, fLights, | 137 paint.setShader(SkLightingShader::Make(fAtlas, fLights, &diffMat, |
136 invNormRotation, &diffMat, &n
ormalMat)); | 138 std::move(normalSource))); |
137 | 139 |
138 canvas->save(); | 140 canvas->save(); |
139 canvas->setMatrix(m); | 141 canvas->setMatrix(m); |
140 canvas->drawRect(r, paint); | 142 canvas->drawRect(r, paint); |
141 canvas->restore(); | 143 canvas->restore(); |
142 } | 144 } |
143 #endif | 145 #endif |
144 | 146 |
145 #ifdef SK_DEBUG | 147 #ifdef SK_DEBUG |
146 { | 148 { |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 private: | 505 private: |
504 SkAutoTUnref<DrawLitAtlasDrawable> fDrawable; | 506 SkAutoTUnref<DrawLitAtlasDrawable> fDrawable; |
505 | 507 |
506 typedef SampleView INHERITED; | 508 typedef SampleView INHERITED; |
507 }; | 509 }; |
508 | 510 |
509 ////////////////////////////////////////////////////////////////////////////// | 511 ////////////////////////////////////////////////////////////////////////////// |
510 | 512 |
511 static SkView* MyFactory() { return new DrawLitAtlasView; } | 513 static SkView* MyFactory() { return new DrawLitAtlasView; } |
512 static SkViewRegister reg(MyFactory); | 514 static SkViewRegister reg(MyFactory); |
OLD | NEW |