1 
2 /*
3  * Copyright 2015 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 #ifndef SkLight_DEFINED
10 #define SkLight_DEFINED
11 
12 #include "SkPoint3.h"
13 
14 class SK_API SkLight {
15 public:
16     enum LightType {
17         kAmbient_LightType,       // only 'fColor' is used
18         kDirectional_LightType
19     };
20 
SkLight()21     SkLight() : fType(kAmbient_LightType) {
22         fColor.set(0.0f, 0.0f, 0.0f);
23         fDirection.set(0.0f, 0.0f, 1.0f);
24     }
25 
SkLight(const SkColor3f & color)26     SkLight(const SkColor3f& color)
27         : fType(kAmbient_LightType)
28         , fColor(color) {
29         fDirection.set(0.0f, 0.0f, 1.0f);
30     }
31 
SkLight(const SkColor3f & color,const SkVector3 & dir)32     SkLight(const SkColor3f& color, const SkVector3& dir)
33         : fType(kDirectional_LightType)
34         , fColor(color)
35         , fDirection(dir) {
36         if (!fDirection.normalize()) {
37             fDirection.set(0.0f, 0.0f, 1.0f);
38         }
39     }
40 
type()41     LightType type() const { return fType; }
color()42     const SkColor3f& color() const { return fColor; }
dir()43     const SkVector3& dir() const {
44         SkASSERT(kAmbient_LightType != fType);
45         return fDirection;
46     }
47 
48 private:
49     LightType   fType;
50     SkColor3f   fColor;           // linear (unpremul) color. Range is 0..1 in each channel.
51     SkVector3   fDirection;       // direction towards the light (+Z is out of the screen).
52                                   // If degenerate, it will be replaced with (0, 0, 1).
53 };
54 
55 
56 #endif
57