OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkLightingShader_DEFINED | 8 #ifndef SkLightingShader_DEFINED |
9 #define SkLightingShader_DEFINED | 9 #define SkLightingShader_DEFINED |
10 | 10 |
11 #include "SkLights.h" | 11 #include "SkLights.h" |
12 #include "SkShader.h" | 12 #include "SkShader.h" |
13 | 13 |
14 class SkBitmap; | 14 class SkBitmap; |
15 class SkMatrix; | 15 class SkMatrix; |
16 | 16 |
17 class SK_API SkLightingShader { | 17 class SK_API SkLightingShader { |
18 public: | 18 public: |
19 /** Abstract class that generates or reads in normals for use by SkLightingS
hader. Currently | |
20 implements the GPU side only. Not to be used as part of the API yet. Use
d internally by | |
21 SkLightingShader. | |
22 */ | |
23 class SK_API NormalSource : public SkFlattenable { | |
24 public: | |
25 virtual ~NormalSource(); | |
26 | |
27 #if SK_SUPPORT_GPU | |
28 /** Returns a fragment processor that takes no input and outputs a norma
l (already rotated) | |
29 as its output color. To be used as a child fragment processor. | |
30 */ | |
31 virtual sk_sp<GrFragmentProcessor> asFragmentProcessor( | |
32 GrContext* context, | |
33 const SkMatrix& viewM, | |
34 const SkMatrix* localMatrix, | |
35 SkFilterQuality filterQuality, | |
36 SkSourceGammaTreatment gammaTreatment) const = 0; | |
37 #endif | |
38 | |
39 /** Returns a normal source that provides normals sourced from the the n
ormal map argument. | |
40 Not to be used as part of the API yet. Used internally by SkLighti
ngShader. | |
41 | |
42 @param normal the normal map | |
43 @param invNormRotation rotation applied to the normal map's
normals | |
44 @param normLocalM the local matrix for the normal map | |
45 | |
46 nullptr will be returned if | |
47 'normal' is empty | |
48 'normal' too big (> 65535 on either side) | |
49 | |
50 The normal map is currently assumed to be an 8888 image where the
normal at a texel | |
51 is retrieved by: | |
52 N.x = R-127; | |
53 N.y = G-127; | |
54 N.z = B-127; | |
55 N.normalize(); | |
56 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z
axis is | |
57 (127, 127, 0). | |
58 */ | |
59 static sk_sp<NormalSource> MakeMap(const SkBitmap& normal, const SkVecto
r& invNormRotation, | |
60 const SkMatrix* normLocalM); | |
61 | |
62 SK_DEFINE_FLATTENABLE_TYPE(NormalSource) | |
63 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | |
64 }; | |
65 | |
66 | |
67 | |
68 /** Returns a shader that lights the diffuse and normal maps with a set of l
ights. | 19 /** Returns a shader that lights the diffuse and normal maps with a set of l
ights. |
69 | 20 |
70 It returns a shader with a reference count of 1. | 21 It returns a shader with a reference count of 1. |
71 The caller should decrement the shader's reference count when done with
the shader. | 22 The caller should decrement the shader's reference count when done with
the shader. |
72 It is an error for count to be < 2. | 23 It is an error for count to be < 2. |
73 @param diffuse the diffuse bitmap | 24 @param diffuse the diffuse bitmap |
74 @param normal the normal map | 25 @param normal the normal map |
75 @param lights the lights applied to the normal map | 26 @param lights the lights applied to the normal map |
76 @param invNormRotation rotation applied to the normal map's normals | 27 @param invNormRotation rotation applied to the normal map's normals |
77 @param diffLocalMatrix the local matrix for the diffuse texture | 28 @param diffLocalMatrix the local matrix for the diffuse map (transform
from |
78 @param normLocalMatrix the local matrix for the normal map | 29 texture coordinates to shape source coordinates)
. nullptr is |
| 30 interpreted as an identity matrix. |
| 31 @param normLocalMatrix the local matrix for the normal map (transform f
rom |
| 32 texture coordinates to shape source coordinates)
. nullptr is |
| 33 interpreted as an identity matrix. |
79 | 34 |
80 nullptr will be returned if: | 35 nullptr will be returned if: |
81 either 'diffuse' or 'normal' are empty | 36 either 'diffuse' or 'normal' are empty |
82 either 'diffuse' or 'normal' are too big (> 65535 on a side) | 37 either 'diffuse' or 'normal' are too big (> 65535 on a side) |
83 'diffuse' and 'normal' aren't the same size | 38 'diffuse' and 'normal' aren't the same size |
84 | 39 |
85 The lighting equation is currently: | 40 The lighting equation is currently: |
86 result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientCo
lor | 41 result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientCo
lor |
87 | 42 |
88 The normal map is currently assumed to be an 8888 image where the normal
at a texel | 43 The normal map is currently assumed to be an 8888 image where the normal
at a texel |
89 is retrieved by: | 44 is retrieved by: |
90 N.x = R-127; | 45 N.x = R-127; |
91 N.y = G-127; | 46 N.y = G-127; |
92 N.z = B-127; | 47 N.z = B-127; |
93 N.normalize(); | 48 N.normalize(); |
94 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis
is | 49 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis
is |
95 (127, 127, 0). | 50 (127, 127, 0). |
96 */ | 51 */ |
97 static sk_sp<SkShader> Make(const SkBitmap& diffuse, const SkBitmap& normal, | 52 static sk_sp<SkShader> Make(const SkBitmap& diffuse, const SkBitmap& normal, |
98 sk_sp<SkLights> lights, const SkVector& invNormR
otation, | 53 sk_sp<SkLights> lights, const SkVector& invNormR
otation, |
99 const SkMatrix* diffLocalMatrix, const SkMatrix*
normLocalMatrix); | 54 const SkMatrix* diffLocalMatrix, const SkMatrix*
normLocalMatrix); |
100 | 55 |
101 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 56 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
102 }; | 57 }; |
103 | 58 |
104 #endif | 59 #endif |
OLD | NEW |