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

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

Issue 2246463004: Added distance attenuation and diffuse shading to PointLights (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: disabled shadows: 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
« no previous file with comments | « no previous file | samplecode/SampleShadowing.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 /* 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
(...skipping 12 matching lines...) Expand all
23 public: 23 public:
24 enum LightType { 24 enum LightType {
25 kAmbient_LightType, // only 'fColor' is used 25 kAmbient_LightType, // only 'fColor' is used
26 kDirectional_LightType, 26 kDirectional_LightType,
27 kPoint_LightType 27 kPoint_LightType
28 }; 28 };
29 29
30 Light(const Light& other) 30 Light(const Light& other)
31 : fType(other.fType) 31 : fType(other.fType)
32 , fColor(other.fColor) 32 , fColor(other.fColor)
33 , fDirection(other.fDirection) 33 , fDirOrPos(other.fDirOrPos)
34 , fIntensity(other.fIntensity)
34 , fShadowMap(other.fShadowMap) { 35 , fShadowMap(other.fShadowMap) {
35 } 36 }
36 37
37 Light(Light&& other) 38 Light(Light&& other)
38 : fType(other.fType) 39 : fType(other.fType)
39 , fColor(other.fColor) 40 , fColor(other.fColor)
40 , fDirection(other.fDirection) 41 , fDirOrPos(other.fDirOrPos)
42 , fIntensity(other.fIntensity)
41 , fShadowMap(std::move(other.fShadowMap)) { 43 , fShadowMap(std::move(other.fShadowMap)) {
42 } 44 }
43 45
44 static Light MakeAmbient(const SkColor3f& color) { 46 static Light MakeAmbient(const SkColor3f& color) {
45 return Light(kAmbient_LightType, color, SkVector3::Make(0.0f, 0.0f, 1.0f)); 47 return Light(kAmbient_LightType, color, SkVector3::Make(0.0f, 0.0f, 1.0f));
46 } 48 }
47 49
48 static Light MakeDirectional(const SkColor3f& color, const SkVector3& di r) { 50 static Light MakeDirectional(const SkColor3f& color, const SkVector3& di r) {
49 Light light(kDirectional_LightType, color, dir); 51 Light light(kDirectional_LightType, color, dir);
50 if (!light.fDirection.normalize()) { 52 if (!light.fDirOrPos.normalize()) {
51 light.fDirection.set(0.0f, 0.0f, 1.0f); 53 light.fDirOrPos.set(0.0f, 0.0f, 1.0f);
52 } 54 }
53 return light; 55 return light;
54 } 56 }
55 57
56 static Light MakePoint(const SkColor3f& color, const SkPoint3& pos) { 58 static Light MakePoint(const SkColor3f& color, const SkPoint3& pos, SkSc alar intensity) {
57 return Light(kPoint_LightType, color, pos); 59 return Light(kPoint_LightType, color, pos, intensity);
58 } 60 }
59 61
60 LightType type() const { return fType; } 62 LightType type() const { return fType; }
61 const SkColor3f& color() const { return fColor; } 63 const SkColor3f& color() const { return fColor; }
62 const SkVector3& dir() const { 64 const SkVector3& dir() const {
63 SkASSERT(kDirectional_LightType == fType); 65 SkASSERT(kDirectional_LightType == fType);
64 return fDirection; 66 return fDirOrPos;
65 } 67 }
66 const SkPoint3& pos() const { 68 const SkPoint3& pos() const {
67 SkASSERT(kPoint_LightType == fType); 69 SkASSERT(kPoint_LightType == fType);
68 return fDirection; 70 return fDirOrPos;
71 }
72 SkScalar intensity() const {
73 SkASSERT(kPoint_LightType == fType);
74 return fIntensity;
69 } 75 }
70 76
71 void setShadowMap(sk_sp<SkImage> shadowMap) { 77 void setShadowMap(sk_sp<SkImage> shadowMap) {
72 fShadowMap = std::move(shadowMap); 78 fShadowMap = std::move(shadowMap);
73 } 79 }
74 80
75 SkImage* getShadowMap() const { 81 SkImage* getShadowMap() const {
76 return fShadowMap.get(); 82 return fShadowMap.get();
77 } 83 }
78 84
79 Light& operator= (const Light& b) { 85 Light& operator= (const Light& b) {
80 if (this == &b) { 86 if (this == &b) {
81 return *this; 87 return *this;
82 } 88 }
83 89
84 fColor = b.fColor; 90 fColor = b.fColor;
85 fType = b.fType; 91 fType = b.fType;
86 fDirection = b.fDirection; 92 fDirOrPos = b.fDirOrPos;
93 fIntensity = b.fIntensity;
87 fShadowMap = b.fShadowMap; 94 fShadowMap = b.fShadowMap;
88 return *this; 95 return *this;
89 } 96 }
90 97
91 bool operator== (const Light& b) { 98 bool operator== (const Light& b) {
92 if (this == &b) { 99 if (this == &b) {
93 return true; 100 return true;
94 } 101 }
95 102
96 return (fColor == b.fColor) && 103 return (fColor == b.fColor) &&
97 (fType == b.fType) && 104 (fType == b.fType) &&
98 (fDirection == b.fDirection) && 105 (fDirOrPos == b.fDirOrPos) &&
99 (fShadowMap == b.fShadowMap); 106 (fShadowMap == b.fShadowMap) &&
107 (fIntensity == b.fIntensity);
100 } 108 }
101 109
102 bool operator!= (const Light& b) { return !(this->operator==(b)); } 110 bool operator!= (const Light& b) { return !(this->operator==(b)); }
103 111
104 private: 112 private:
105 LightType fType; 113 LightType fType;
106 SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel. 114 SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel.
107 SkVector3 fDirection; // For directional lights, holds the direc tion towards the 115
116 SkVector3 fDirOrPos; // For directional lights, holds the direc tion towards the
108 // light (+Z is out of the screen). 117 // light (+Z is out of the screen).
109 // If degenerate, it will be replaced with (0, 0, 1). 118 // If degenerate, it will be replaced with (0, 0, 1).
110 // For point lights, holds location of poi nt light 119 // For point lights, holds location of poi nt light
120
121 SkScalar fIntensity; // For point lights, dictates the light in tensity.
122 // Simply a multiplier to the final light output value.
111 sk_sp<SkImage> fShadowMap; 123 sk_sp<SkImage> fShadowMap;
112 124
113 Light(LightType type, const SkColor3f& color, const SkVector3& dir) { 125 Light(LightType type, const SkColor3f& color,
126 const SkVector3& dir, SkScalar intensity = 0.0f) {
114 fType = type; 127 fType = type;
115 fColor = color; 128 fColor = color;
116 fDirection = dir; 129 fDirOrPos = dir;
130 fIntensity = intensity;
117 } 131 }
118 }; 132 };
119 133
120 class Builder { 134 class Builder {
121 public: 135 public:
122 Builder() : fLights(new SkLights) { } 136 Builder() : fLights(new SkLights) { }
123 137
124 void add(const Light& light) { 138 void add(const Light& light) {
125 if (fLights) { 139 if (fLights) {
126 fLights->fLights.push_back(light); 140 fLights->fLights.push_back(light);
(...skipping 30 matching lines...) Expand all
157 171
158 void flatten(SkWriteBuffer& buf) const; 172 void flatten(SkWriteBuffer& buf) const;
159 173
160 private: 174 private:
161 SkLights() {} 175 SkLights() {}
162 SkTArray<Light> fLights; 176 SkTArray<Light> fLights;
163 typedef SkRefCnt INHERITED; 177 typedef SkRefCnt INHERITED;
164 }; 178 };
165 179
166 #endif 180 #endif
OLDNEW
« no previous file with comments | « no previous file | samplecode/SampleShadowing.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698