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

Side by Side Diff: samplecode/SampleShadowing.cpp

Issue 2287553002: Moved ambient lights out of SkLight's light array (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: made req changes Created 4 years, 3 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
OLDNEW
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 "SkPictureRecorder.h" 9 #include "SkPictureRecorder.h"
10 #include "SkShadowPaintFilterCanvas.h" 10 #include "SkShadowPaintFilterCanvas.h"
11 #include "SkShadowShader.h" 11 #include "SkShadowShader.h"
12 #include "SkSurface.h" 12 #include "SkSurface.h"
13 13
14 #ifdef SK_EXPERIMENTAL_SHADOWING 14 #ifdef SK_EXPERIMENTAL_SHADOWING
15 15
16 class ShadowingView : public SampleView { 16 class ShadowingView : public SampleView {
17 public: 17 public:
18 ShadowingView() 18 ShadowingView()
19 : fSceneChanged(true) 19 : fSceneChanged(true)
20 , fLightsChanged(true) 20 , fLightsChanged(true)
21 , fMoveLight(false) 21 , fMoveLight(false)
22 , fClearShadowMaps(false) 22 , fClearShadowMaps(false)
23 , fSelectedRectID(-1) 23 , fSelectedRectID(-1)
24 , fSelectedSliderID(-1) 24 , fSelectedSliderID(-1)
25 , fLightDepth(300.0f) { 25 , fLightDepth(300.0f) {
26 this->setBGColor(0xFFCCCCCC); 26 this->setBGColor(0xFFCCCCCC);
27 27
robertphillips 2016/08/26 17:31:28 ??
28 this->updateLights(200, 200); 28 this->setBGColor(0xFFCCCCCC);
29 SkLights::Builder builder;
30 builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.2f, 0.3f, 0.4f),
31 SkVector3::Make(0.2f, 0.05f , 1.0f)));
32 builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.4f, 0.3f, 0.2f),
33 SkVector3::Make(0.05f, 0.2f , 1.0f)));
34 builder.setAmbientLightColor(SkColor3f::Make(0.4f, 0.4f, 0.4f));
35 fLights = builder.finish();
29 36
30 fTestRects[0].fColor = 0xFFEE8888; 37 fTestRects[0].fColor = 0xFFEE8888;
31 fTestRects[0].fDepth = 80; 38 fTestRects[0].fDepth = 80;
32 fTestRects[0].fGeometry = SkRect::MakeLTRB(200,150,350,300); 39 fTestRects[0].fGeometry = SkRect::MakeLTRB(200,150,350,300);
33 40
34 fTestRects[1].fColor = 0xFF88EE88; 41 fTestRects[1].fColor = 0xFF88EE88;
35 fTestRects[1].fDepth = 160; 42 fTestRects[1].fDepth = 160;
36 fTestRects[1].fGeometry = SkRect::MakeLTRB(150,200,300,350); 43 fTestRects[1].fGeometry = SkRect::MakeLTRB(150,200,300,350);
37 44
38 fTestRects[2].fColor = 0xFF8888EE; 45 fTestRects[2].fColor = 0xFF8888EE;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 204 }
198 205
199 bool onClick(Click *click) override { 206 bool onClick(Click *click) override {
200 SkScalar x = click->fCurr.fX; 207 SkScalar x = click->fCurr.fX;
201 SkScalar y = click->fCurr.fY; 208 SkScalar y = click->fCurr.fY;
202 209
203 SkScalar dx = x - click->fPrev.fX; 210 SkScalar dx = x - click->fPrev.fX;
204 SkScalar dy = y - click->fPrev.fY; 211 SkScalar dy = y - click->fPrev.fY;
205 212
206 if (fMoveLight) { 213 if (fMoveLight) {
207 if (dx != 0 || dy != 0) { 214 if (dx != 0 || dy != 0) {
robertphillips 2016/08/26 17:31:28 ??
208 this->updateLights(x, y); 215 float recipX = 1.0f / kWidth;
216 float recipY = 1.0f / kHeight;
217
218 SkLights::Builder builder;
219 builder.add(SkLights::Light::MakeDirectional(
220 SkColor3f::Make(0.2f, 0.3f, 0.4f),
221 SkVector3::Make(0.2f + (200.0f - x) * recipX,
222 0.05f + (200.0f - y) * recipY,
223 1.0f)));
224 builder.add(SkLights::Light::MakeDirectional(
225 SkColor3f::Make(0.4f, 0.3f, 0.2f),
226 SkVector3::Make(0.05f + (200.0f - x) * recipX,
227 0.2f + (200.0f - y) * recipY,
228 1.0f)));
229 builder.setAmbientLightColor(SkColor3f::Make(0.4f, 0.4f, 0.4f));
230 fLights = builder.finish();
231
209 fLightsChanged = true; 232 fLightsChanged = true;
210 this->inval(nullptr); 233 this->inval(nullptr);
211 } 234 }
212 return true; 235 return true;
213 } 236 }
214 237
215 if (click->fState == Click::State::kUp_State) { 238 if (click->fState == Click::State::kUp_State) {
216 fSelectedRectID = -1; 239 fSelectedRectID = -1;
217 fSelectedSliderID = -1; 240 fSelectedSliderID = -1;
218 return true; 241 return true;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 sk_sp<SkLights> fLights; 321 sk_sp<SkLights> fLights;
299 322
300 typedef SampleView INHERITED; 323 typedef SampleView INHERITED;
301 }; 324 };
302 325
303 ////////////////////////////////////////////////////////////////////////////// 326 //////////////////////////////////////////////////////////////////////////////
304 static SkView* MyFactory() { return new ShadowingView; } 327 static SkView* MyFactory() { return new ShadowingView; }
305 static SkViewRegister reg(MyFactory); 328 static SkViewRegister reg(MyFactory);
306 329
307 #endif 330 #endif
OLDNEW
« no previous file with comments | « samplecode/SampleLitAtlas.cpp ('k') | src/core/SkCanvas.cpp » ('j') | src/core/SkShadowShader.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698