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 "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(600.0f) { | 25 , fLightDepth(400.0f) { |
26 this->setBGColor(0xFFCCCCCC); | 26 this->setBGColor(0xFFCCCCCC); |
27 | 27 |
28 this->updateLights(200, 200); | 28 this->updateLights(100, 100); |
29 | 29 |
30 fTestRects[0].fColor = 0xFFEE8888; | 30 fTestRects[0].fColor = 0xFFEE8888; |
31 fTestRects[0].fDepth = 80; | 31 fTestRects[0].fDepth = 80; |
32 fTestRects[0].fGeometry = SkRect::MakeLTRB(200,150,350,300); | 32 fTestRects[0].fGeometry = SkRect::MakeLTRB(200,150,350,300); |
33 | 33 |
34 fTestRects[1].fColor = 0xFF88EE88; | 34 fTestRects[1].fColor = 0xFF88EE88; |
35 fTestRects[1].fDepth = 160; | 35 fTestRects[1].fDepth = 160; |
36 fTestRects[1].fGeometry = SkRect::MakeLTRB(150,200,300,350); | 36 fTestRects[1].fGeometry = SkRect::MakeLTRB(150,200,300,350); |
37 | 37 |
38 fTestRects[2].fColor = 0xFF8888EE; | 38 fTestRects[2].fColor = 0xFF8888EE; |
39 fTestRects[2].fDepth = 240; | 39 fTestRects[2].fDepth = 240; |
40 fTestRects[2].fGeometry = SkRect::MakeLTRB(100,100,250,250); | 40 fTestRects[2].fGeometry = SkRect::MakeLTRB(100,100,250,250); |
41 | 41 |
42 fSliders[0].fGeometry = SkRect::MakeLTRB(20, 400, 30, 420); | 42 fSliders[0].fGeometry = SkRect::MakeLTRB(20, 400, 30, 420); |
43 fSliders[0].fOffset = 0.0f; | 43 fSliders[0].fOffset = 0.0f; |
44 fSliders[0].fScale = 0.1f; | 44 fSliders[0].fScale = 0.1f; |
45 | 45 |
46 fSliders[1].fGeometry = SkRect::MakeLTRB(100, 420, 110, 440); | 46 fSliders[1].fGeometry = SkRect::MakeLTRB(100, 420, 110, 440); |
47 fSliders[1].fOffset = 0.0f; | 47 fSliders[1].fOffset = 0.0f; |
48 fSliders[1].fScale = 10.0f; | 48 fSliders[1].fScale = 10.0f; |
49 | 49 |
50 fSliders[2].fGeometry = SkRect::MakeLTRB(0, 440, 10, 460); | 50 fSliders[2].fGeometry = SkRect::MakeLTRB(0, 440, 10, 460); |
51 fSliders[2].fOffset = 0.0f; | 51 fSliders[2].fOffset = 0.0f; |
52 fSliders[2].fScale = 0.0025f; | 52 fSliders[2].fScale = 0.0025f; |
53 | 53 |
54 fShadowParams.fShadowRadius = 4.0f; | 54 fShadowParams.fShadowRadius = 4.0f; |
55 fShadowParams.fBiasingConstant = 0.3f; | 55 fShadowParams.fBiasingConstant = 0.3f; |
56 fShadowParams.fMinVariance = 1024; | 56 fShadowParams.fMinVariance = 2048; // we need a higher min variance for
point lights |
57 fShadowParams.fType = SkShadowParams::kVariance_ShadowType; | 57 fShadowParams.fType = SkShadowParams::kVariance_ShadowType; |
58 } | 58 } |
59 | 59 |
60 protected: | 60 protected: |
61 bool onQuery(SkEvent *evt) override { | 61 bool onQuery(SkEvent *evt) override { |
62 if (SampleCode::TitleQ(*evt)) { | 62 if (SampleCode::TitleQ(*evt)) { |
63 SampleCode::TitleR(evt, "shadowing"); | 63 SampleCode::TitleR(evt, "shadowing"); |
64 return true; | 64 return true; |
65 } | 65 } |
66 | 66 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 canvas->drawRect(fSliders[i].fGeometry, paint); | 155 canvas->drawRect(fSliders[i].fGeometry, paint); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
159 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { | 159 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { |
160 return new SkView::Click(this); | 160 return new SkView::Click(this); |
161 } | 161 } |
162 | 162 |
163 void updateLights(int x, int y) { | 163 void updateLights(int x, int y) { |
164 SkLights::Builder builder; | 164 SkLights::Builder builder; |
| 165 builder.setAmbientLightColor(SkColor3f::Make(0.2f, 0.2f, 0.2f)); |
165 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.2f, 0.4f, 0.6f)
, | 166 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.2f, 0.4f, 0.6f)
, |
166 SkVector3::Make(x - 50, | 167 SkVector3::Make(x - 50, |
167 350 - y, | 168 350 - y, |
168 fLightDepth), | 169 fLightDepth), |
169 100000)); | 170 100000)); |
170 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.6f, 0.4f, 0.2f)
, | 171 builder.add(SkLights::Light::MakePoint(SkColor3f::Make(0.6f, 0.4f, 0.2f)
, |
171 SkVector3::Make(x + 50, | 172 SkVector3::Make(x + 50, |
172 450 - y, | 173 450 - y, |
173 fLightDepth), | 174 fLightDepth), |
174 100000)); | 175 100000)); |
175 builder.add(SkLights::Light::MakeDirectional(SkColor3f::Make(0.2f, 0.2f,
0.2f), | |
176 SkVector3::Make(0.2f, 0.2f,
1.0f))); | |
177 fLights = builder.finish(); | 176 fLights = builder.finish(); |
178 } | 177 } |
179 | 178 |
180 void updateFromSelectedSlider() { | 179 void updateFromSelectedSlider() { |
181 SkScalar newValue = fSliders[fSelectedSliderID].fGeometry.fLeft * | 180 SkScalar newValue = fSliders[fSelectedSliderID].fGeometry.fLeft * |
182 fSliders[fSelectedSliderID].fScale + | 181 fSliders[fSelectedSliderID].fScale + |
183 fSliders[fSelectedSliderID].fOffset; | 182 fSliders[fSelectedSliderID].fOffset; |
184 | 183 |
185 switch (fSelectedSliderID) { | 184 switch (fSelectedSliderID) { |
186 case 0: | 185 case 0: |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 sk_sp<SkLights> fLights; | 298 sk_sp<SkLights> fLights; |
300 | 299 |
301 typedef SampleView INHERITED; | 300 typedef SampleView INHERITED; |
302 }; | 301 }; |
303 | 302 |
304 ////////////////////////////////////////////////////////////////////////////// | 303 ////////////////////////////////////////////////////////////////////////////// |
305 static SkView* MyFactory() { return new ShadowingView; } | 304 static SkView* MyFactory() { return new ShadowingView; } |
306 static SkViewRegister reg(MyFactory); | 305 static SkViewRegister reg(MyFactory); |
307 | 306 |
308 #endif | 307 #endif |
OLD | NEW |