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 "SkPoint3.h" |
14 #include "SkShader.h" | 14 #include "SkShader.h" |
15 | 15 |
16 class SK_API SkLightingShader { | 16 class SK_API SkLightingShader { |
17 public: | 17 public: |
18 struct Light { | 18 struct Light { |
19 SkVector3 fDirection; // direction towards the light (+Z is out
of the screen). | 19 SkVector3 fDirection; // direction towards the light (+Z is out
of the screen). |
20 // If degenerate, it will be replaced with
(0, 0, 1). | 20 // If degenerate, it will be replaced with
(0, 0, 1). |
21 SkColor fColor; // linear (unpremul) color. Note: alpha as
sumed to be 255. | 21 SkColor3f fColor; // linear (unpremul) color. Range is 0..1
in each channel. |
22 }; | 22 }; |
23 | 23 |
24 /** Returns a shader that lights the diffuse and normal maps with a single l
ight. | 24 /** Returns a shader that lights the diffuse and normal maps with a single l
ight. |
25 | 25 |
26 It returns a shader with a reference count of 1. | 26 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. | 27 The caller should decrement the shader's reference count when done with
the shader. |
28 It is an error for count to be < 2. | 28 It is an error for count to be < 2. |
29 @param diffuse the diffuse bitmap | 29 @param diffuse the diffuse bitmap |
30 @param normal the normal map | 30 @param normal the normal map |
31 @param light the light applied to the normal map | 31 @param light the light applied to the normal map |
32 @param ambient the linear (unpremul) ambient light color. Note: alp
ha assumed to be 255. | 32 @param ambient the linear (unpremul) ambient light color. Range is
0..1/channel. |
33 @param localMatrix the matrix mapping the textures to the dest rect | 33 @param localMatrix the matrix mapping the textures to the dest rect |
34 | 34 |
35 NULL will be returned if: | 35 NULL will be returned if: |
36 either 'diffuse' or 'normal' are empty | 36 either 'diffuse' or 'normal' are empty |
37 either 'diffuse' or 'normal' are too big (> 65535 on a side) | 37 either 'diffuse' or 'normal' are too big (> 65535 on a side) |
38 'diffuse' and 'normal' aren't the same size | 38 'diffuse' and 'normal' aren't the same size |
| 39 |
| 40 The lighting equation is currently: |
| 41 result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientCo
lor |
| 42 |
| 43 The normal map is currently assumed to be an 8888 image where the normal
at a texel |
| 44 is retrieved by: |
| 45 N.x = R-127; |
| 46 N.y = G-127; |
| 47 N.z = B-127; |
| 48 N.normalize(); |
| 49 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis
is |
| 50 (127, 127, 0). |
39 */ | 51 */ |
40 static SkShader* Create(const SkBitmap& diffuse, const SkBitmap& normal, | 52 static SkShader* Create(const SkBitmap& diffuse, const SkBitmap& normal, |
41 const SkLightingShader::Light& light, const SkColor
ambient, | 53 const SkLightingShader::Light& light, const SkColor3
f& ambient, |
42 const SkMatrix* localMatrix); | 54 const SkMatrix* localMatrix); |
43 | 55 |
44 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 56 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
45 }; | 57 }; |
46 | 58 |
47 #endif | 59 #endif |
OLD | NEW |