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, | |
reed1
2016/06/20 15:00:39
0. Should we have a variant that takes SkImage? Sk
dvonbeck
2016/06/20 20:03:58
0. I could make it take in a shader instead of a b
| |
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 texture |
(...skipping 17 matching lines...) Expand all Loading... | |
95 (127, 127, 0). | 46 (127, 127, 0). |
96 */ | 47 */ |
97 static sk_sp<SkShader> Make(const SkBitmap& diffuse, const SkBitmap& normal, | 48 static sk_sp<SkShader> Make(const SkBitmap& diffuse, const SkBitmap& normal, |
98 sk_sp<SkLights> lights, const SkVector& invNormR otation, | 49 sk_sp<SkLights> lights, const SkVector& invNormR otation, |
99 const SkMatrix* diffLocalMatrix, const SkMatrix* normLocalMatrix); | 50 const SkMatrix* diffLocalMatrix, const SkMatrix* normLocalMatrix); |
100 | 51 |
101 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 52 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
102 }; | 53 }; |
103 | 54 |
104 #endif | 55 #endif |
OLD | NEW |