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

Side by Side Diff: samplecode/SampleLighting.cpp

Issue 1253223003: Update SkLightingShader to take a localMatrix (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix serialization bug 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 | « gm/lightingshader.cpp ('k') | src/effects/SkLightingShader.h » ('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 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "Resources.h" 9 #include "Resources.h"
10 10
(...skipping 23 matching lines...) Expand all
34 34
35 SkLightingShader::Light light; 35 SkLightingShader::Light light;
36 light.fColor = SkColorSetRGB(0xff, 0xff, 0xff); 36 light.fColor = SkColorSetRGB(0xff, 0xff, 0xff);
37 light.fDirection.fX = SkScalarSin(fLightAngle)*SkScalarSin(SK_ScalarPI*0 .25f); 37 light.fDirection.fX = SkScalarSin(fLightAngle)*SkScalarSin(SK_ScalarPI*0 .25f);
38 light.fDirection.fY = SkScalarCos(fLightAngle)*SkScalarSin(SK_ScalarPI*0 .25f); 38 light.fDirection.fY = SkScalarCos(fLightAngle)*SkScalarSin(SK_ScalarPI*0 .25f);
39 light.fDirection.fZ = SkScalarCos(SK_ScalarPI*0.25f); 39 light.fDirection.fZ = SkScalarCos(SK_ScalarPI*0.25f);
40 40
41 fAmbientColor = SkColorSetRGB(0x1f, 0x1f, 0x1f); 41 fAmbientColor = SkColorSetRGB(0x1f, 0x1f, 0x1f);
42 42
43 fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap, 43 fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap,
44 light, fAmbientColor)); 44 light, fAmbientColor, nullptr));
45 } 45 }
46 46
47 virtual ~LightingView() {} 47 virtual ~LightingView() {}
48 48
49 protected: 49 protected:
50 // overrides from SkEventSink 50 // overrides from SkEventSink
51 bool onQuery(SkEvent* evt) override { 51 bool onQuery(SkEvent* evt) override {
52 if (SampleCode::TitleQ(*evt)) { 52 if (SampleCode::TitleQ(*evt)) {
53 SampleCode::TitleR(evt, "Lighting"); 53 SampleCode::TitleR(evt, "Lighting");
54 return true; 54 return true;
55 } 55 }
56 return this->INHERITED::onQuery(evt); 56 return this->INHERITED::onQuery(evt);
57 } 57 }
58 58
59 void onDrawContent(SkCanvas* canvas) override { 59 void onDrawContent(SkCanvas* canvas) override {
60 fLightAngle += 0.015f; 60 fLightAngle += 0.015f;
61 fColorFactor++; 61 fColorFactor++;
62 62
63 SkLightingShader::Light light; 63 SkLightingShader::Light light;
64 light.fColor = SkColorSetRGB(0xff, 0xff, (fColorFactor >> 1) & 0xff); 64 light.fColor = SkColorSetRGB(0xff, 0xff, (fColorFactor >> 1) & 0xff);
65 light.fDirection.fX = SkScalarSin(fLightAngle)*SkScalarSin(SK_ScalarPI*0 .25f); 65 light.fDirection.fX = SkScalarSin(fLightAngle)*SkScalarSin(SK_ScalarPI*0 .25f);
66 light.fDirection.fY = SkScalarCos(fLightAngle)*SkScalarSin(SK_ScalarPI*0 .25f); 66 light.fDirection.fY = SkScalarCos(fLightAngle)*SkScalarSin(SK_ScalarPI*0 .25f);
67 light.fDirection.fZ = SkScalarCos(SK_ScalarPI*0.25f); 67 light.fDirection.fZ = SkScalarCos(SK_ScalarPI*0.25f);
68 68
69 fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap, 69 fShader.reset(SkLightingShader::Create(fDiffuseBitmap, fNormalBitmap,
70 light, fAmbientColor)); 70 light, fAmbientColor, nullptr));
71 71
72 SkPaint paint; 72 SkPaint paint;
73 paint.setShader(fShader); 73 paint.setShader(fShader);
74 paint.setColor(SK_ColorBLACK); 74 paint.setColor(SK_ColorBLACK);
75 75
76 SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(), 76 SkRect r = SkRect::MakeWH((SkScalar)fDiffuseBitmap.width(),
77 (SkScalar)fDiffuseBitmap.height()); 77 (SkScalar)fDiffuseBitmap.height());
78 canvas->drawRect(r, paint); 78 canvas->drawRect(r, paint);
79 79
80 // so we're constantly updating 80 // so we're constantly updating
81 this->inval(NULL); 81 this->inval(NULL);
82 } 82 }
83 83
84 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride { 84 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride {
85 this->inval(NULL); 85 this->inval(NULL);
86 return this->INHERITED::onFindClickHandler(x, y, modi); 86 return this->INHERITED::onFindClickHandler(x, y, modi);
87 } 87 }
88 88
89 private: 89 private:
90 typedef SampleView INHERITED; 90 typedef SampleView INHERITED;
91 }; 91 };
92 92
93 ////////////////////////////////////////////////////////////////////////////// 93 //////////////////////////////////////////////////////////////////////////////
94 94
95 static SkView* MyFactory() { return new LightingView; } 95 static SkView* MyFactory() { return new LightingView; }
96 static SkViewRegister reg(MyFactory); 96 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « gm/lightingshader.cpp ('k') | src/effects/SkLightingShader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698