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

Side by Side Diff: include/core/SkLights.h

Issue 2237493002: Added PointLights to SkLights::Light (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: changed a vec3 to a point3 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
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 8
9 #ifndef SkLights_DEFINED 9 #ifndef SkLights_DEFINED
10 #define SkLights_DEFINED 10 #define SkLights_DEFINED
11 11
12 #include "SkPoint3.h" 12 #include "SkPoint3.h"
13 #include "SkRefCnt.h" 13 #include "SkRefCnt.h"
14 #include "../private/SkTArray.h" 14 #include "../private/SkTArray.h"
15 #include "SkImage.h" 15 #include "SkImage.h"
16 16
17 class SK_API SkLights : public SkRefCnt { 17 class SK_API SkLights : public SkRefCnt {
18 public: 18 public:
19 class Light { 19 class Light {
20 public: 20 public:
21 enum LightType { 21 enum LightType {
22 kAmbient_LightType, // only 'fColor' is used 22 kAmbient_LightType, // only 'fColor' is used
23 kDirectional_LightType 23 kDirectional_LightType,
24 kPoint_LightType
24 }; 25 };
25 26
26 Light(const Light& other) 27 Light(const Light& other)
27 : fType(other.fType) 28 : fType(other.fType)
28 , fColor(other.fColor) 29 , fColor(other.fColor)
29 , fDirection(other.fDirection) 30 , fDirection(other.fDirection)
30 , fShadowMap(other.fShadowMap) { 31 , fShadowMap(other.fShadowMap) {
31 } 32 }
32 33
33 Light(Light&& other) 34 Light(Light&& other)
34 : fType(other.fType) 35 : fType(other.fType)
35 , fColor(other.fColor) 36 , fColor(other.fColor)
36 , fDirection(other.fDirection) 37 , fDirection(other.fDirection)
37 , fShadowMap(std::move(other.fShadowMap)) { 38 , fShadowMap(std::move(other.fShadowMap)) {
38 } 39 }
39 40
40 Light(const SkColor3f& color) 41 static Light MakeAmbient(const SkColor3f& color) {
robertphillips 2016/08/10 17:48:39 just "return Light(...);" no need for the temporar
vjiaoblack 2016/08/11 14:27:23 Done.
41 : fType(kAmbient_LightType) 42 Light light(kAmbient_LightType, color, SkVector3::Make(0.0f, 0.0f, 1 .0f));
42 , fColor(color) { 43 return light;
43 fDirection.set(0.0f, 0.0f, 1.0f);
44 } 44 }
45 45
46 Light(const SkColor3f& color, const SkVector3& dir) 46 static Light MakeDirectional(const SkColor3f& color, const SkVector3& di r) {
47 : fType(kDirectional_LightType) 47 Light light(kDirectional_LightType, color, dir);
48 , fColor(color) 48 if (!light.fDirection.normalize()) {
49 , fDirection(dir) { 49 light.fDirection.set(0.0f, 0.0f, 1.0f);
50 if (!fDirection.normalize()) {
51 fDirection.set(0.0f, 0.0f, 1.0f);
52 } 50 }
51 return light;
52 }
53
54 static Light MakePoint(const SkColor3f& color, const SkPoint3& pos) {
robertphillips 2016/08/10 17:48:39 Same here
vjiaoblack 2016/08/11 14:27:23 Done.
55 Light light(kPoint_LightType, color, pos);
56 return light;
53 } 57 }
54 58
55 LightType type() const { return fType; } 59 LightType type() const { return fType; }
56 const SkColor3f& color() const { return fColor; } 60 const SkColor3f& color() const { return fColor; }
57 const SkVector3& dir() const { 61 const SkVector3& dir() const {
58 SkASSERT(kAmbient_LightType != fType); 62 SkASSERT(kDirectional_LightType == fType);
59 return fDirection; 63 return fDirection;
60 } 64 }
65 const SkPoint3& pos() const {
66 SkASSERT(kPoint_LightType == fType);
67 return fDirection;
68 }
61 69
62 void setShadowMap(sk_sp<SkImage> shadowMap) { 70 void setShadowMap(sk_sp<SkImage> shadowMap) {
63 fShadowMap = std::move(shadowMap); 71 fShadowMap = std::move(shadowMap);
64 } 72 }
65 73
66 SkImage* getShadowMap() const { 74 SkImage* getShadowMap() const {
67 return fShadowMap.get(); 75 return fShadowMap.get();
68 } 76 }
69 77
70 Light& operator= (const Light& b) { 78 Light& operator= (const Light& b) {
71 if (this == &b) { 79 if (this == &b) {
72 return *this; 80 return *this;
73 } 81 }
74 82
75 fColor = b.fColor; 83 fColor = b.fColor;
76 fType = b.fType; 84 fType = b.fType;
77 fDirection = b.fDirection; 85 fDirection = b.fDirection;
78 fShadowMap = b.fShadowMap; 86 fShadowMap = b.fShadowMap;
79 return *this; 87 return *this;
80 } 88 }
81 89
82 private: 90 private:
83 LightType fType; 91 LightType fType;
84 SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel. 92 SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel.
robertphillips 2016/08/10 17:48:39 Fix comment
vjiaoblack 2016/08/11 14:27:23 Done.
85 SkVector3 fDirection; // direction towards the light (+Z is out of the screen). 93 SkVector3 fDirection; // direction towards the light (+Z is out of the screen).
86 // If degenerate, it will be replaced with (0, 0, 1). 94 // If degenerate, it will be replaced with (0, 0, 1).
87 sk_sp<SkImage> fShadowMap; 95 sk_sp<SkImage> fShadowMap;
96
97 Light(LightType type, const SkColor3f color, const SkVector3 dir) {
robertphillips 2016/08/10 17:48:39 Don't need "this->" on member variables
vjiaoblack 2016/08/11 14:27:23 Done.
98 this->fType = type;
99 this->fColor = color;
100 this->fDirection = dir;
101 }
88 }; 102 };
89 103
90 class Builder { 104 class Builder {
91 public: 105 public:
92 Builder() : fLights(new SkLights) { } 106 Builder() : fLights(new SkLights) { }
93 107
94 void add(const Light& light) { 108 void add(const Light& light) {
95 if (fLights) { 109 if (fLights) {
96 fLights->fLights.push_back(light); 110 fLights->fLights.push_back(light);
97 } 111 }
(...skipping 27 matching lines...) Expand all
125 139
126 private: 140 private:
127 SkLights() {} 141 SkLights() {}
128 142
129 SkTArray<Light> fLights; 143 SkTArray<Light> fLights;
130 144
131 typedef SkRefCnt INHERITED; 145 typedef SkRefCnt INHERITED;
132 }; 146 };
133 147
134 #endif 148 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698