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 | 9 |
10 #ifndef SkLightingShader_DEFINED | 10 #ifndef SkLightingShader_DEFINED |
11 #define SkLightingShader_DEFINED | 11 #define SkLightingShader_DEFINED |
12 | 12 |
13 #include "SkPoint3.h" | 13 #include "SkFlattenable.h" |
14 #include "SkLight.h" | |
14 #include "SkShader.h" | 15 #include "SkShader.h" |
16 #include "SkTDArray.h" | |
17 | |
18 class SkBitmap; | |
19 class SkMatrix; | |
15 | 20 |
16 class SK_API SkLightingShader { | 21 class SK_API SkLightingShader { |
17 public: | 22 public: |
18 struct Light { | 23 class Lights : public SkRefCnt { |
19 SkVector3 fDirection; // direction towards the light (+Z is out of the screen). | 24 public: |
20 // If degenerate, it will be replaced with (0, 0, 1). | 25 class Builder { |
jvanverth1
2015/08/19 13:57:48
This class is new -- can you mention it in the cha
robertphillips
2015/08/19 16:17:57
Done.
| |
21 SkColor3f fColor; // linear (unpremul) color. Range is 0..1 in each channel. | 26 public: |
27 Builder(const SkLight lights[], int numLights) | |
28 : fLights(SkNEW_ARGS(Lights, (lights, numLights))) { | |
29 } | |
30 | |
31 Builder() : fLights(SkNEW(Lights)) { } | |
32 | |
33 void add(const SkLight& light) { | |
jvanverth1
2015/08/19 13:57:48
I think we'll need a way to limit the number of di
robertphillips
2015/08/19 16:17:57
I've added a TODO.
| |
34 if (fLights) { | |
35 *fLights->fLights.push() = light; | |
36 } | |
37 } | |
38 | |
39 const Lights* finish() { | |
40 return fLights.detach(); | |
41 } | |
42 | |
43 private: | |
44 SkAutoTUnref<Lights> fLights; | |
45 }; | |
46 | |
47 int numLights() const { | |
48 return fLights.count(); | |
49 } | |
50 | |
51 const SkLight& light(int index) const { | |
52 return fLights[index]; | |
53 } | |
54 | |
55 private: | |
56 Lights() {} | |
57 Lights(const SkLight lights[], int numLights) : fLights(lights, numLight s) {} | |
58 | |
59 SkTDArray<SkLight> fLights; | |
60 | |
61 typedef SkRefCnt INHERITED; | |
22 }; | 62 }; |
23 | 63 |
24 /** Returns a shader that lights the diffuse and normal maps with a single l ight. | 64 /** Returns a shader that lights the diffuse and normal maps with a single l ight. |
25 | 65 |
26 It returns a shader with a reference count of 1. | 66 It returns a shader with a reference count of 1. |
27 The caller should decrement the shader's reference count when done with the shader. | 67 The caller should decrement the shader's reference count when done with the shader. |
28 It is an error for count to be < 2. | 68 It is an error for count to be < 2. |
29 @param diffuse the diffuse bitmap | 69 @param diffuse the diffuse bitmap |
30 @param normal the normal map | 70 @param normal the normal map |
31 @param light the light applied to the normal map | 71 @param light the light applied to the normal map |
(...skipping 11 matching lines...) Expand all Loading... | |
43 The normal map is currently assumed to be an 8888 image where the normal at a texel | 83 The normal map is currently assumed to be an 8888 image where the normal at a texel |
44 is retrieved by: | 84 is retrieved by: |
45 N.x = R-127; | 85 N.x = R-127; |
46 N.y = G-127; | 86 N.y = G-127; |
47 N.z = B-127; | 87 N.z = B-127; |
48 N.normalize(); | 88 N.normalize(); |
49 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is | 89 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is |
50 (127, 127, 0). | 90 (127, 127, 0). |
51 */ | 91 */ |
52 static SkShader* Create(const SkBitmap& diffuse, const SkBitmap& normal, | 92 static SkShader* Create(const SkBitmap& diffuse, const SkBitmap& normal, |
53 const SkLightingShader::Light& light, const SkColor3 f& ambient, | 93 const Lights* lights, const SkVector& invNormRotatio n, |
54 const SkMatrix* localMatrix); | 94 const SkMatrix* diffLocalMatrix, const SkMatrix* nor mLocalMatrix); |
55 | 95 |
56 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 96 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
57 }; | 97 }; |
58 | 98 |
59 #endif | 99 #endif |
OLD | NEW |