OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "gm.h" | 8 #include "gm.h" |
9 | 9 |
| 10 #include "SkBitmapProcShader.h" |
10 #include "SkLightingShader.h" | 11 #include "SkLightingShader.h" |
11 #include "SkNormalSource.h" | 12 #include "SkNormalSource.h" |
12 #include "SkPoint3.h" | 13 #include "SkPoint3.h" |
13 #include "SkShader.h" | 14 #include "SkShader.h" |
14 | 15 |
15 // Create a hemispherical normal map | 16 // Create a hemispherical normal map |
16 static SkBitmap make_hemi_normalmap(int texSize) { | 17 static SkBitmap make_hemi_normalmap(int texSize) { |
17 SkBitmap hemi; | 18 SkBitmap hemi; |
18 hemi.allocN32Pixels(texSize, texSize); | 19 hemi.allocN32Pixels(texSize, texSize); |
19 | 20 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 94 |
94 SkMatrix matrix; | 95 SkMatrix matrix; |
95 matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit); | 96 matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit); |
96 | 97 |
97 const SkMatrix& ctm = canvas->getTotalMatrix(); | 98 const SkMatrix& ctm = canvas->getTotalMatrix(); |
98 | 99 |
99 // TODO: correctly pull out the pure rotation | 100 // TODO: correctly pull out the pure rotation |
100 SkVector invNormRotation = { ctm[SkMatrix::kMScaleX], ctm[SkMatrix::kMSk
ewY] }; | 101 SkVector invNormRotation = { ctm[SkMatrix::kMScaleX], ctm[SkMatrix::kMSk
ewY] }; |
101 | 102 |
102 SkPaint paint; | 103 SkPaint paint; |
| 104 sk_sp<SkShader> diffuseShader = SkBitmapProcShader::MakeBitmapShader(fDi
ffuse, |
| 105 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &matrix); |
103 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeMap(fNormalMaps
[mapType], | 106 sk_sp<SkNormalSource> normalSource = SkNormalSource::MakeMap(fNormalMaps
[mapType], |
104 invNormRota
tion, &matrix); | 107 invNormRota
tion, &matrix); |
105 paint.setShader(SkLightingShader::Make(fDiffuse, fLights, &matrix, | 108 paint.setShader(SkLightingShader::Make(std::move(diffuseShader), std::mo
ve(normalSource), |
106 std::move(normalSource))); | 109 fLights)); |
107 | 110 |
108 canvas->drawRect(r, paint); | 111 canvas->drawRect(r, paint); |
109 } | 112 } |
110 | 113 |
111 void onDraw(SkCanvas* canvas) override { | 114 void onDraw(SkCanvas* canvas) override { |
112 SkMatrix m; | 115 SkMatrix m; |
113 SkRect r; | 116 SkRect r; |
114 | 117 |
115 { | 118 { |
116 r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize))
; | 119 r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize))
; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 173 |
171 sk_sp<SkLights> fLights; | 174 sk_sp<SkLights> fLights; |
172 | 175 |
173 typedef GM INHERITED; | 176 typedef GM INHERITED; |
174 }; | 177 }; |
175 | 178 |
176 ////////////////////////////////////////////////////////////////////////////// | 179 ////////////////////////////////////////////////////////////////////////////// |
177 | 180 |
178 DEF_GM(return new LightingShaderGM;) | 181 DEF_GM(return new LightingShaderGM;) |
179 } | 182 } |
OLD | NEW |