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

Side by Side Diff: samplecode/SampleShadowing.cpp

Issue 2237493002: Added PointLights to SkLights::Light (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: fixed serialization bug Created 4 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 | « samplecode/SampleLitAtlas.cpp ('k') | src/core/SkCanvas.cpp » ('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 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 19
20 this->setBGColor(0xFFCCCCCC); 20 this->setBGColor(0xFFCCCCCC);
21 SkLights::Builder builder; 21 SkLights::Builder builder;
22 builder.add(SkLights::Light(SkColor3f::Make(0.2f, 0.3f, 0.4f), 22 builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.2f, 0.3f, 0.4f),
23 SkVector3::Make(0.2f, 0.05f, 1.0f))); 23 SkVector3::Make(0.2f, 0.05f , 1.0f)));
24 builder.add(SkLights::Light(SkColor3f::Make(0.4f, 0.3f, 0.2f), 24 builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.4f, 0.3f, 0.2f),
25 SkVector3::Make(0.05f, 0.2f, 1.0f))); 25 SkVector3::Make(0.05f, 0.2f , 1.0f)));
26 builder.add(SkLights::Light(SkColor3f::Make(0.4f, 0.4f, 0.4f))); 26 builder.add(SkLights::Light::MakeAmbient(SkColor3f::Make(0.4f, 0.4f, 0.4 f)));
27 fLights = builder.finish(); 27 fLights = builder.finish();
28 28
29 fTestRects[0].fColor = 0xFFEE8888; 29 fTestRects[0].fColor = 0xFFEE8888;
30 fTestRects[0].fDepth = 80; 30 fTestRects[0].fDepth = 80;
31 fTestRects[0].fGeometry = SkRect::MakeLTRB(200,150,350,300); 31 fTestRects[0].fGeometry = SkRect::MakeLTRB(200,150,350,300);
32 32
33 fTestRects[1].fColor = 0xFF88EE88; 33 fTestRects[1].fColor = 0xFF88EE88;
34 fTestRects[1].fDepth = 160; 34 fTestRects[1].fDepth = 160;
35 fTestRects[1].fGeometry = SkRect::MakeLTRB(150,200,300,350); 35 fTestRects[1].fGeometry = SkRect::MakeLTRB(150,200,300,350);
36 36
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 132
133 SkScalar dx = x - click->fPrev.fX; 133 SkScalar dx = x - click->fPrev.fX;
134 SkScalar dy = y - click->fPrev.fY; 134 SkScalar dy = y - click->fPrev.fY;
135 135
136 if (fMoveLight) { 136 if (fMoveLight) {
137 if (dx != 0 || dy != 0) { 137 if (dx != 0 || dy != 0) {
138 float recipX = 1.0f / kWidth; 138 float recipX = 1.0f / kWidth;
139 float recipY = 1.0f / kHeight; 139 float recipY = 1.0f / kHeight;
140 140
141 SkLights::Builder builder; 141 SkLights::Builder builder;
142 builder.add(SkLights::Light(SkColor3f::Make(0.2f, 0.3f, 0.4f), 142 builder.add(SkLights::Light::MakeDirectional(
143 SkVector3::Make(0.2f + (200.0f - x) * recipX, 143 SkColor3f::Make(0.2f, 0.3f, 0.4f),
144 0.05f + (200.0f - y) * recipY, 144 SkVector3::Make(0.2f + (200.0f - x) * recipX,
145 1.0f))); 145 0.05f + (200.0f - y) * recipY,
146 builder.add(SkLights::Light(SkColor3f::Make(0.4f, 0.3f, 0.2f), 146 1.0f)));
147 SkVector3::Make(0.05f + (200.0f - x) * recipX, 147 builder.add(SkLights::Light::MakeDirectional(
148 0.2f + (200.0f - y) * recipY, 148 SkColor3f::Make(0.4f, 0.3f, 0.2f),
149 1.0f))); 149 SkVector3::Make(0.05f + (200.0f - x) * recipX,
150 builder.add(SkLights::Light(SkColor3f::Make(0.4f, 0.4f, 0.4f))); 150 0.2f + (200.0f - y) * recipY,
151 1.0f)));
152 builder.add(SkLights::Light::MakeAmbient(
153 SkColor3f::Make(0.4f, 0.4f, 0.4f)));
151 fLights = builder.finish(); 154 fLights = builder.finish();
152 155
153 fLightsChanged = true; 156 fLightsChanged = true;
154 this->inval(nullptr); 157 this->inval(nullptr);
155 } 158 }
156 return true; 159 return true;
157 } 160 }
158 161
159 if (click->fState == Click::State::kUp_State) { 162 if (click->fState == Click::State::kUp_State) {
160 fSelectedRect = -1; 163 fSelectedRect = -1;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 sk_sp<SkLights> fLights; 211 sk_sp<SkLights> fLights;
209 212
210 typedef SampleView INHERITED; 213 typedef SampleView INHERITED;
211 }; 214 };
212 215
213 ////////////////////////////////////////////////////////////////////////////// 216 //////////////////////////////////////////////////////////////////////////////
214 static SkView* MyFactory() { return new ShadowingView; } 217 static SkView* MyFactory() { return new ShadowingView; }
215 static SkViewRegister reg(MyFactory); 218 static SkViewRegister reg(MyFactory);
216 219
217 #endif 220 #endif
OLDNEW
« no previous file with comments | « samplecode/SampleLitAtlas.cpp ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698