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

Unified 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: Made req changes- made light intensity a light attribute 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 side-by-side diff with in-line comments
Download patch
Index: include/core/SkLights.h
diff --git a/include/core/SkLights.h b/include/core/SkLights.h
index d9ec65b9aafe59f8766fcad3bda7f4ef9683b37e..597dd201cf1820e71ae4cf8fd661ce85b03983e9 100644
--- a/include/core/SkLights.h
+++ b/include/core/SkLights.h
@@ -31,6 +31,7 @@ public:
: fType(other.fType)
, fColor(other.fColor)
, fDirection(other.fDirection)
+ , fIntensity(other.fIntensity)
, fShadowMap(other.fShadowMap) {
}
@@ -38,6 +39,7 @@ public:
: fType(other.fType)
, fColor(other.fColor)
, fDirection(other.fDirection)
+ , fIntensity(other.fIntensity)
, fShadowMap(std::move(other.fShadowMap)) {
}
@@ -53,8 +55,10 @@ public:
return light;
}
- static Light MakePoint(const SkColor3f& color, const SkPoint3& pos) {
- return Light(kPoint_LightType, color, pos);
+ static Light MakePoint(const SkColor3f& color, const SkPoint3& pos, SkScalar intensity) {
+ Light light(kPoint_LightType, color, pos);
+ light.fIntensity = intensity;
+ return light;
}
LightType type() const { return fType; }
@@ -67,6 +71,10 @@ public:
SkASSERT(kPoint_LightType == fType);
return fDirection;
}
+ SkScalar intensity() const {
+ SkASSERT(kPoint_LightType == fType);
+ return fIntensity;
+ }
void setShadowMap(sk_sp<SkImage> shadowMap) {
fShadowMap = std::move(shadowMap);
@@ -90,16 +98,21 @@ public:
private:
LightType fType;
SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel.
+
SkVector3 fDirection; // For directional lights, holds the direction towards the
jvanverth1 2016/08/17 19:59:02 Reusing the name fDirection for point lights seems
vjiaoblack 2016/08/18 14:52:18 Done.
// light (+Z is out of the screen).
// If degenerate, it will be replaced with (0, 0, 1).
// For point lights, holds location of point light
+
+ SkScalar fIntensity; // Dictates the light intensity. Basically this divides
jvanverth1 2016/08/17 19:59:02 You need to mention that this is only used for poi
vjiaoblack 2016/08/18 14:52:18 That equation would also provide a slightly incorr
+ // the dist^2 attenuation variable to increase brightness.
sk_sp<SkImage> fShadowMap;
Light(LightType type, const SkColor3f& color, const SkVector3& dir) {
fType = type;
fColor = color;
fDirection = dir;
+ fIntensity = 0.0f;
jvanverth1 2016/08/17 19:59:02 SK_ScalarZero
vjiaoblack 2016/08/18 14:52:18 This does not exist. SK_ScalarNearlyZero exists, b
}
};

Powered by Google App Engine
This is Rietveld 408576698