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

Side by Side Diff: gm/lightingshader.cpp

Issue 1304673002: Revert "Update SkLightingShader to support rotation" (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | gyp/SampleApp.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkLightingShader.h" 10 #include "SkLightingShader.h"
11 #include "SkPoint3.h" 11 #include "SkPoint3.h"
12 #include "SkShader.h" 12 #include "SkShader.h"
13 13
14 static SkBitmap make_checkerboard(int texSize) { 14 static SkBitmap make_checkerboard(int texSize) {
15 SkBitmap bitmap; 15 SkBitmap bitmap;
16 bitmap.allocN32Pixels(texSize, texSize); 16 bitmap.allocN32Pixels(texSize, texSize);
17 17
18 SkCanvas canvas(bitmap); 18 SkCanvas canvas(bitmap);
19 sk_tool_utils::draw_checkerboard(&canvas, 19 sk_tool_utils::draw_checkerboard(&canvas,
20 sk_tool_utils::color_to_565(0x0), 20 sk_tool_utils::color_to_565(0x0),
21 sk_tool_utils::color_to_565(0xFF804020), 21 sk_tool_utils::color_to_565(0xFF804020),
22 8); 22 2);
23 return bitmap; 23 return bitmap;
24 } 24 }
25 25
26 // Create a hemispherical normal map 26 // Create a hemispherical normal map
27 static SkBitmap make_hemi_normalmap(int texSize) { 27 static SkBitmap make_hemi_normalmap(int texSize) {
28 SkBitmap hemi; 28 SkBitmap hemi;
29 hemi.allocN32Pixels(texSize, texSize); 29 hemi.allocN32Pixels(texSize, texSize);
30 30
31 sk_tool_utils::create_hemi_normal_map(&hemi, SkIRect::MakeWH(texSize, texSiz e)); 31 sk_tool_utils::create_hemi_normal_map(&hemi, SkIRect::MakeWH(texSize, texSiz e));
32 return hemi; 32 return hemi;
(...skipping 18 matching lines...) Expand all
51 } 51 }
52 52
53 namespace skiagm { 53 namespace skiagm {
54 54
55 // This GM exercises lighting shaders. 55 // This GM exercises lighting shaders.
56 class LightingShaderGM : public GM { 56 class LightingShaderGM : public GM {
57 public: 57 public:
58 LightingShaderGM() { 58 LightingShaderGM() {
59 this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); 59 this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC));
60 60
61 SkLightingShader::Lights::Builder builder; 61 fLight.fColor = SkColor3f::Make(1.0f, 1.0f, 1.0f);
62 fLight.fDirection = SkVector3::Make(0.0f, 0.0f, 1.0f);
62 63
63 builder.add(SkLight(SkColor3f::Make(1.0f, 1.0f, 1.0f), 64 fAmbient = SkColor3f::Make(0.1f, 0.1f, 0.1f);
64 SkVector3::Make(1.0f, 0.0f, 0.0f)));
65 builder.add(SkLight(SkColor3f::Make(0.2f, 0.2f, 0.2f)));
66
67 fLights.reset(builder.finish());
68 } 65 }
69 66
70 protected: 67 protected:
71 enum NormalMap { 68 enum NormalMap {
72 kHemi_NormalMap, 69 kHemi_NormalMap,
73 kFrustum_NormalMap, 70 kFrustum_NormalMap,
74 kTetra_NormalMap, 71 kTetra_NormalMap,
75 72
76 kLast_NormalMap = kTetra_NormalMap 73 kLast_NormalMap = kTetra_NormalMap
77 }; 74 };
(...skipping 16 matching lines...) Expand all
94 fNormalMaps[kTetra_NormalMap] = make_tetra_normalmap(kTexSize); 91 fNormalMaps[kTetra_NormalMap] = make_tetra_normalmap(kTexSize);
95 } 92 }
96 93
97 void drawRect(SkCanvas* canvas, const SkRect& r, NormalMap mapType) { 94 void drawRect(SkCanvas* canvas, const SkRect& r, NormalMap mapType) {
98 95
99 SkRect bitmapBounds = SkRect::MakeIWH(fDiffuse.width(), fDiffuse.height( )); 96 SkRect bitmapBounds = SkRect::MakeIWH(fDiffuse.width(), fDiffuse.height( ));
100 97
101 SkMatrix matrix; 98 SkMatrix matrix;
102 matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit); 99 matrix.setRectToRect(bitmapBounds, r, SkMatrix::kFill_ScaleToFit);
103 100
104 const SkMatrix& ctm = canvas->getTotalMatrix();
105
106 // TODO: correctly pull out the pure rotation
107 SkVector invNormRotation = { ctm[SkMatrix::kMScaleX], ctm[SkMatrix::kMSk ewY] };
108
109 SkAutoTUnref<SkShader> fShader(SkLightingShader::Create( 101 SkAutoTUnref<SkShader> fShader(SkLightingShader::Create(
110 fDiffuse, 102 fDiffuse,
111 fNormalMaps[mapType], 103 fNormalMaps[mapType],
112 fLights, 104 fLight, fAmbient,
113 invNormRotation, &matrix , &matrix)); 105 &matrix));
114 106
115 SkPaint paint; 107 SkPaint paint;
116 paint.setShader(fShader); 108 paint.setShader(fShader);
117 109
118 canvas->drawRect(r, paint); 110 canvas->drawRect(r, paint);
119 } 111 }
120 112
121 void onDraw(SkCanvas* canvas) override { 113 void onDraw(SkCanvas* canvas) override {
122 SkMatrix m; 114 SkRect r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSiz e));
123 SkRect r; 115 this->drawRect(canvas, r, kHemi_NormalMap);
124 116
125 { 117 r.offset(kGMSize - kTexSize, 0);
126 r = SkRect::MakeWH(SkIntToScalar(kTexSize), SkIntToScalar(kTexSize)) ; 118 this->drawRect(canvas, r, kFrustum_NormalMap);
127 this->drawRect(canvas, r, kHemi_NormalMap);
128 119
129 canvas->save(); 120 r.offset(0, kGMSize - kTexSize);
130 m.setRotate(45.0f, r.centerX(), r.centerY()); 121 this->drawRect(canvas, r, kTetra_NormalMap);
131 m.postTranslate(kGMSize/2.0f - kTexSize/2.0f, 0.0f);
132 canvas->setMatrix(m);
133 this->drawRect(canvas, r, kHemi_NormalMap);
134 canvas->restore();
135 }
136 122
137 { 123 r.offset(kTexSize - kGMSize, 0);
138 r.offset(kGMSize - kTexSize, 0); 124 this->drawRect(canvas, r, kHemi_NormalMap);
139 this->drawRect(canvas, r, kFrustum_NormalMap);
140
141 canvas->save();
142 m.setRotate(45.0f, r.centerX(), r.centerY());
143 m.postTranslate(0.0f, kGMSize/2.0f - kTexSize/2.0f);
144 canvas->setMatrix(m);
145 this->drawRect(canvas, r, kFrustum_NormalMap);
146 canvas->restore();
147 }
148
149 {
150 r.offset(0, kGMSize - kTexSize);
151 this->drawRect(canvas, r, kTetra_NormalMap);
152
153 canvas->save();
154 m.setRotate(45.0f, r.centerX(), r.centerY());
155 m.postTranslate(-kGMSize/2.0f + kTexSize/2.0f, 0.0f);
156 canvas->setMatrix(m);
157 this->drawRect(canvas, r, kTetra_NormalMap);
158 canvas->restore();
159 }
160
161 {
162 r.offset(kTexSize - kGMSize, 0);
163 this->drawRect(canvas, r, kHemi_NormalMap);
164
165 canvas->save();
166 m.setRotate(45.0f, r.centerX(), r.centerY());
167 m.postTranslate(0.0f, -kGMSize/2.0f + kTexSize/2.0f);
168 canvas->setMatrix(m);
169 this->drawRect(canvas, r, kHemi_NormalMap);
170 canvas->restore();
171 }
172 } 125 }
173 126
174 private: 127 private:
175 static const int kTexSize = 128; 128 static const int kTexSize = 128;
176 static const int kGMSize = 512; 129 static const int kGMSize = 512;
177 130
178 SkBitmap fDiffuse; 131 SkBitmap fDiffuse;
179 SkBitmap fNormalMaps[kNormalMapCount]; 132 SkBitmap fNormalMaps[kNormalMapCount];
180 133
181 SkAutoTUnref<const SkLightingShader::Lights> fLights; 134 SkLightingShader::Light fLight;
135 SkColor3f fAmbient;
182 136
183 typedef GM INHERITED; 137 typedef GM INHERITED;
184 }; 138 };
185 139
186 ////////////////////////////////////////////////////////////////////////////// 140 //////////////////////////////////////////////////////////////////////////////
187 141
188 DEF_GM( return SkNEW(LightingShaderGM); ) 142 DEF_GM( return SkNEW(LightingShaderGM); )
189 143
190 } 144 }
OLDNEW
« no previous file with comments | « no previous file | gyp/SampleApp.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698