| OLD | NEW |
| 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 13 matching lines...) Expand all Loading... |
| 24 enum LightType { | 24 enum LightType { |
| 25 kDirectional_LightType, | 25 kDirectional_LightType, |
| 26 kPoint_LightType | 26 kPoint_LightType |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 Light(const Light& other) | 29 Light(const Light& other) |
| 30 : fType(other.fType) | 30 : fType(other.fType) |
| 31 , fColor(other.fColor) | 31 , fColor(other.fColor) |
| 32 , fDirOrPos(other.fDirOrPos) | 32 , fDirOrPos(other.fDirOrPos) |
| 33 , fIntensity(other.fIntensity) | 33 , fIntensity(other.fIntensity) |
| 34 , fShadowMap(other.fShadowMap) { | 34 , fShadowMap(other.fShadowMap) |
| 35 , fIsRadial(other.fIsRadial) { |
| 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 , fDirOrPos(other.fDirOrPos) | 41 , fDirOrPos(other.fDirOrPos) |
| 41 , fIntensity(other.fIntensity) | 42 , fIntensity(other.fIntensity) |
| 42 , fShadowMap(std::move(other.fShadowMap)) { | 43 , fShadowMap(std::move(other.fShadowMap)) |
| 44 , fIsRadial(other.fIsRadial) { |
| 43 } | 45 } |
| 44 | 46 |
| 45 static Light MakeDirectional(const SkColor3f& color, const SkVector3& di
r) { | 47 static Light MakeDirectional(const SkColor3f& color, const SkVector3& di
r, |
| 46 Light light(kDirectional_LightType, color, dir); | 48 bool isRadial = false) { |
| 49 Light light(kDirectional_LightType, color, dir, isRadial); |
| 47 if (!light.fDirOrPos.normalize()) { | 50 if (!light.fDirOrPos.normalize()) { |
| 48 light.fDirOrPos.set(0.0f, 0.0f, 1.0f); | 51 light.fDirOrPos.set(0.0f, 0.0f, 1.0f); |
| 49 } | 52 } |
| 50 return light; | 53 return light; |
| 51 } | 54 } |
| 52 | 55 |
| 53 static Light MakePoint(const SkColor3f& color, const SkPoint3& pos, SkSc
alar intensity) { | 56 static Light MakePoint(const SkColor3f& color, const SkPoint3& pos, SkSc
alar intensity, |
| 54 return Light(kPoint_LightType, color, pos, intensity); | 57 bool isRadial = false) { |
| 58 return Light(kPoint_LightType, color, pos, intensity, isRadial); |
| 55 } | 59 } |
| 56 | 60 |
| 57 LightType type() const { return fType; } | 61 LightType type() const { return fType; } |
| 58 const SkColor3f& color() const { return fColor; } | 62 const SkColor3f& color() const { return fColor; } |
| 59 const SkVector3& dir() const { | 63 const SkVector3& dir() const { |
| 60 SkASSERT(kDirectional_LightType == fType); | 64 SkASSERT(kDirectional_LightType == fType); |
| 61 return fDirOrPos; | 65 return fDirOrPos; |
| 62 } | 66 } |
| 63 const SkPoint3& pos() const { | 67 const SkPoint3& pos() const { |
| 64 SkASSERT(kPoint_LightType == fType); | 68 SkASSERT(kPoint_LightType == fType); |
| 65 return fDirOrPos; | 69 return fDirOrPos; |
| 66 } | 70 } |
| 67 SkScalar intensity() const { | 71 SkScalar intensity() const { |
| 68 SkASSERT(kPoint_LightType == fType); | 72 SkASSERT(kPoint_LightType == fType); |
| 69 return fIntensity; | 73 return fIntensity; |
| 70 } | 74 } |
| 71 | 75 |
| 72 void setShadowMap(sk_sp<SkImage> shadowMap) { | 76 void setShadowMap(sk_sp<SkImage> shadowMap) { |
| 73 fShadowMap = std::move(shadowMap); | 77 fShadowMap = std::move(shadowMap); |
| 74 } | 78 } |
| 75 | 79 |
| 76 SkImage* getShadowMap() const { | 80 SkImage* getShadowMap() const { |
| 77 return fShadowMap.get(); | 81 return fShadowMap.get(); |
| 78 } | 82 } |
| 79 | 83 |
| 84 bool isRadial() const { return fIsRadial; } |
| 85 |
| 80 Light& operator= (const Light& b) { | 86 Light& operator= (const Light& b) { |
| 81 if (this == &b) { | 87 if (this == &b) { |
| 82 return *this; | 88 return *this; |
| 83 } | 89 } |
| 84 | 90 |
| 85 fColor = b.fColor; | 91 fColor = b.fColor; |
| 86 fType = b.fType; | 92 fType = b.fType; |
| 87 fDirOrPos = b.fDirOrPos; | 93 fDirOrPos = b.fDirOrPos; |
| 88 fIntensity = b.fIntensity; | 94 fIntensity = b.fIntensity; |
| 89 fShadowMap = b.fShadowMap; | 95 fShadowMap = b.fShadowMap; |
| 96 fIsRadial = b.fIsRadial; |
| 90 return *this; | 97 return *this; |
| 91 } | 98 } |
| 92 | 99 |
| 93 bool operator== (const Light& b) { | 100 bool operator== (const Light& b) { |
| 94 if (this == &b) { | 101 if (this == &b) { |
| 95 return true; | 102 return true; |
| 96 } | 103 } |
| 97 | 104 |
| 98 return (fColor == b.fColor) && | 105 return (fColor == b.fColor) && |
| 99 (fType == b.fType) && | 106 (fType == b.fType) && |
| 100 (fDirOrPos == b.fDirOrPos) && | 107 (fDirOrPos == b.fDirOrPos) && |
| 101 (fShadowMap == b.fShadowMap) && | 108 (fShadowMap == b.fShadowMap) && |
| 102 (fIntensity == b.fIntensity); | 109 (fIntensity == b.fIntensity) && |
| 110 (fIsRadial == b.fIsRadial); |
| 103 } | 111 } |
| 104 | 112 |
| 105 bool operator!= (const Light& b) { return !(this->operator==(b)); } | 113 bool operator!= (const Light& b) { return !(this->operator==(b)); } |
| 106 | 114 |
| 107 private: | 115 private: |
| 108 LightType fType; | 116 LightType fType; |
| 109 SkColor3f fColor; // linear (unpremul) color. Range is 0..1
in each channel. | 117 SkColor3f fColor; // linear (unpremul) color. Range is 0..1
in each channel. |
| 110 | 118 |
| 111 SkVector3 fDirOrPos; // For directional lights, holds the direc
tion towards the | 119 SkVector3 fDirOrPos; // For directional lights, holds the direc
tion towards the |
| 112 // light (+Z is out of the screen). | 120 // light (+Z is out of the screen). |
| 113 // If degenerate, it will be replaced with
(0, 0, 1). | 121 // If degenerate, it will be replaced with
(0, 0, 1). |
| 114 // For point lights, holds location of poi
nt light | 122 // For point lights, holds location of poi
nt light |
| 115 | 123 |
| 116 SkScalar fIntensity; // For point lights, dictates the light in
tensity. | 124 SkScalar fIntensity; // For point lights, dictates the light in
tensity. |
| 117 // Simply a multiplier to the final light
output value. | 125 // Simply a multiplier to the final light
output value. |
| 118 sk_sp<SkImage> fShadowMap; | 126 sk_sp<SkImage> fShadowMap; |
| 127 bool fIsRadial; // Whether the light is radial or not. Rad
ial lights will |
| 128 // cast shadows and lights radially outwar
ds. |
| 119 | 129 |
| 120 Light(LightType type, const SkColor3f& color, | 130 Light(LightType type, const SkColor3f& color, const SkVector3& dirOrPos, |
| 121 const SkVector3& dirOrPos, SkScalar intensity = 0.0f) { | 131 SkScalar intensity = 0.0f, bool isRadial = false) { |
| 122 fType = type; | 132 fType = type; |
| 123 fColor = color; | 133 fColor = color; |
| 124 fDirOrPos = dirOrPos; | 134 fDirOrPos = dirOrPos; |
| 125 fIntensity = intensity; | 135 fIntensity = intensity; |
| 136 fIsRadial = isRadial; |
| 126 } | 137 } |
| 127 }; | 138 }; |
| 128 | 139 |
| 129 class Builder { | 140 class Builder { |
| 130 public: | 141 public: |
| 131 Builder() : fLights(new SkLights) {} | 142 Builder() : fLights(new SkLights) {} |
| 132 | 143 |
| 133 void add(const Light& light) { | 144 void add(const Light& light) { |
| 134 if (fLights) { | 145 if (fLights) { |
| 135 fLights->fLights.push_back(light); | 146 fLights->fLights.push_back(light); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 private: | 190 private: |
| 180 SkLights() { | 191 SkLights() { |
| 181 fAmbientLightColor.set(0.0f, 0.0f, 0.0f); | 192 fAmbientLightColor.set(0.0f, 0.0f, 0.0f); |
| 182 } | 193 } |
| 183 SkTArray<Light> fLights; | 194 SkTArray<Light> fLights; |
| 184 SkColor3f fAmbientLightColor; | 195 SkColor3f fAmbientLightColor; |
| 185 typedef SkRefCnt INHERITED; | 196 typedef SkRefCnt INHERITED; |
| 186 }; | 197 }; |
| 187 | 198 |
| 188 #endif | 199 #endif |
| OLD | NEW |