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

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; removed the unused isPointLight uni 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..d89b21afe3658e52cec49ca5189e6098d6a1ffff 100644
--- a/include/core/SkLights.h
+++ b/include/core/SkLights.h
@@ -30,14 +30,16 @@ public:
Light(const Light& other)
: fType(other.fType)
, fColor(other.fColor)
- , fDirection(other.fDirection)
+ , fDirOrPos(other.fDirOrPos)
+ , fIntensity(other.fIntensity)
, fShadowMap(other.fShadowMap) {
}
Light(Light&& other)
: fType(other.fType)
, fColor(other.fColor)
- , fDirection(other.fDirection)
+ , fDirOrPos(other.fDirOrPos)
+ , fIntensity(other.fIntensity)
, fShadowMap(std::move(other.fShadowMap)) {
}
@@ -47,25 +49,31 @@ public:
static Light MakeDirectional(const SkColor3f& color, const SkVector3& dir) {
Light light(kDirectional_LightType, color, dir);
- if (!light.fDirection.normalize()) {
- light.fDirection.set(0.0f, 0.0f, 1.0f);
+ if (!light.fDirOrPos.normalize()) {
+ light.fDirOrPos.set(0.0f, 0.0f, 1.0f);
}
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) {
robertphillips 2016/08/18 17:12:59 Add intensity as last param to the unifying ctor a
vjiaoblack 2016/08/18 18:05:33 Done.
+ Light light(kPoint_LightType, color, pos);
+ light.fIntensity = intensity;
+ return light;
}
LightType type() const { return fType; }
const SkColor3f& color() const { return fColor; }
const SkVector3& dir() const {
SkASSERT(kDirectional_LightType == fType);
- return fDirection;
+ return fDirOrPos;
}
const SkPoint3& pos() const {
SkASSERT(kPoint_LightType == fType);
- return fDirection;
+ return fDirOrPos;
+ }
+ SkScalar intensity() const {
+ SkASSERT(kPoint_LightType == fType);
+ return fIntensity;
}
void setShadowMap(sk_sp<SkImage> shadowMap) {
@@ -83,23 +91,28 @@ public:
fColor = b.fColor;
fType = b.fType;
- fDirection = b.fDirection;
+ fDirOrPos = b.fDirOrPos;
robertphillips 2016/08/18 17:12:59 copy fIntensity too ?
vjiaoblack 2016/08/18 18:05:33 Done.
fShadowMap = b.fShadowMap;
return *this;
}
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
+
+ SkVector3 fDirOrPos; // For directional lights, holds the direction towards the
// 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
+
robertphillips 2016/08/18 17:12:59 Now, why can't we just make the light's color dimm
vjiaoblack 2016/08/18 18:05:33 We can. But we can't make the light's color brigh
+ SkScalar fIntensity; // For point lights, dictates the light intensity.
+ // Simply a multiplier to the final light output value.
sk_sp<SkImage> fShadowMap;
Light(LightType type, const SkColor3f& color, const SkVector3& dir) {
fType = type;
fColor = color;
- fDirection = dir;
+ fDirOrPos = dir;
+ fIntensity = 0.0f;
}
};

Powered by Google App Engine
This is Rietveld 408576698