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. Not to be | 19 /** Abstract class that generates or reads in normals for use by SkLightingS hader. |
20 used as part of the API yet. Used internally by SkLightingShader. | |
21 */ | 20 */ |
22 class NormalSource : public SkFlattenable { | 21 class NormalSource : public SkFlattenable { |
23 public: | 22 public: |
24 virtual ~NormalSource(); | 23 virtual ~NormalSource(); |
25 | 24 |
26 #if SK_SUPPORT_GPU | 25 #if SK_SUPPORT_GPU |
27 | 26 |
28 /** Returns a fragment processor that takes no input and outputs a norma l (already rotated) | 27 /** 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. | 28 as its output color. To be used as a child fragment processor. |
30 */ | 29 */ |
31 virtual sk_sp<GrFragmentProcessor> asFragmentProcessor( | 30 virtual sk_sp<GrFragmentProcessor> asFragmentProcessor( |
32 GrContext* context, | 31 GrContext* context, |
33 const SkMatrix& viewM, | 32 const SkMatrix& viewM, |
34 const SkMatrix* localMatrix, | 33 const SkMatrix* localMatrix, |
35 SkFilterQuality filterQuality, | 34 SkFilterQuality filterQuality, |
36 SkSourceGammaTreatment gammaTreatment) const = 0; | 35 SkSourceGammaTreatment gammaTreatment) const = 0; |
37 #endif | 36 #endif |
38 | 37 |
egdaniel
2016/06/16 13:15:08
extra spaces added here?
dvonbeck
2016/06/16 23:21:57
Oops, that was an accident. Reverted. Are space-on
| |
39 class Provider { | 38 class Provider { |
40 public: | 39 public: |
41 virtual ~Provider(){}; | 40 virtual ~Provider(){}; |
42 | 41 |
43 /** Called for each span of the object being drawn on the CPU. Your subclass should set | 42 /** Called for each span of the object being drawn on the CPU. Your subclass should set |
44 the appropriate normals that correspond to the specified device coordinates. | 43 the appropriate normals that correspond to the specified device coordinates. |
45 */ | 44 */ |
46 virtual void fillScanLine(int x, int y, SkPoint3 output[], int count ) const = 0; | 45 virtual void fillScanLine(int x, int y, SkPoint3 output[], int count ) const = 0; |
47 | 46 |
48 /** Returns the maximum count that can be passed into 'fillScanLine' for an output | 47 /** Returns the maximum count that can be passed into 'fillScanLine' for an output |
49 buffer of size 'count'. | 48 buffer of size 'count'. |
50 */ | 49 */ |
51 virtual int maxCountForFillScanLine(int count) const = 0; | 50 virtual int maxCountForFillScanLine(int count) const = 0; |
52 }; | 51 }; |
53 | 52 |
54 /** Returns an instance of 'Provider' that provides normals for the CPU pipeline. The | 53 /** Returns an instance of 'Provider' that provides normals for the CPU pipeline. The |
55 necessary data will be initialized in place at 'storage'. | 54 necessary data will be initialized in place at 'storage'. |
56 */ | 55 */ |
57 virtual Provider* asProvider(const SkShader::ContextRec& rec, void* stor age) const = 0; | 56 virtual Provider* asProvider(const SkShader::ContextRec& rec, void* stor age) const = 0; |
58 | 57 |
59 /** Amount of memory needed to store a provider object and its dependenc ies. | 58 /** Amount of memory needed to store a provider object and its dependenc ies. |
60 */ | 59 */ |
61 virtual size_t providerSize() const = 0; | 60 virtual size_t providerSize() const = 0; |
62 | 61 |
63 SK_DEFINE_FLATTENABLE_TYPE(NormalSource) | 62 SK_DEFINE_FLATTENABLE_TYPE(NormalSource) |
64 }; | 63 }; |
65 | 64 |
66 /** Returns a normal source that provides normals sourced from the the norma l map argument. | |
67 Not to be used as part of the API yet. Used internally by SkLightingShad er. | |
68 | |
69 @param normal the normal map | |
70 @param invNormRotation rotation applied to the normal map's norma ls | |
71 @param normLocalM the local matrix for the normal map | |
72 | |
73 nullptr will be returned if | |
74 'normal' is empty | |
75 'normal' too big (> 65535 on either side) | |
76 | |
77 The normal map is currently assumed to be an 8888 image where the normal at a texel | |
78 is retrieved by: | |
79 N.x = R-127; | |
80 N.y = G-127; | |
81 N.z = B-127; | |
82 N.normalize(); | |
83 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is | |
84 (127, 127, 0). | |
85 */ | |
86 class NormalMapSource { | 65 class NormalMapSource { |
87 public: | 66 public: |
67 | |
68 /** Returns a normal source that provides normals sourced from the the n ormal map argument. | |
69 | |
70 @param normal the normal map | |
71 @param invNormRotation rotation applied to the normal map's n ormals | |
72 @param normLocalM the local matrix for the normal map | |
73 | |
74 nullptr will be returned if | |
75 'normal' is empty | |
76 'normal' too big (> 65535 on either side) | |
77 | |
78 The normal map is currently assumed to be an 8888 image where the no rmal at a texel is | |
79 retrieved by: | |
80 N.x = R-127; | |
81 N.y = G-127; | |
82 N.z = B-127; | |
83 N.normalize(); | |
84 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z a xis is | |
85 (127, 127, 0). | |
86 */ | |
88 static sk_sp<NormalSource> Make(const SkBitmap& normal, const SkVector& invNormRotation, | 87 static sk_sp<NormalSource> Make(const SkBitmap& normal, const SkVector& invNormRotation, |
89 const SkMatrix* normLocalM); | 88 const SkMatrix* normLocalM); |
90 | |
91 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 89 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
92 }; | 90 }; |
93 | 91 |
94 /** Returns a shader that lights the diffuse and normal maps with a set of l ights. | 92 /** Returns a shader that lights the diffuse map and normals with a set of l ights. |
95 | 93 |
96 It returns a shader with a reference count of 1. | 94 It returns a shader with a reference count of 1. |
97 The caller should decrement the shader's reference count when done with the shader. | 95 The caller should decrement the shader's reference count when done with the shader. |
98 It is an error for count to be < 2. | 96 It is an error for count to be < 2. |
99 @param diffuse the diffuse bitmap | 97 @param diffuse the diffuse bitmap |
100 @param normal the normal map | 98 @param lights the lights applied to the normals |
101 @param lights the lights applied to the normal map | |
102 @param invNormRotation rotation applied to the normal map's normals | |
103 @param diffLocalMatrix the local matrix for the diffuse texture | 99 @param diffLocalMatrix the local matrix for the diffuse texture |
104 @param normLocalMatrix the local matrix for the normal map | 100 @param normalSource the source for the normals |
105 | 101 |
106 nullptr will be returned if: | 102 nullptr will be returned if: |
107 either 'diffuse' or 'normal' are empty | 103 'diffuse' is empty |
108 either 'diffuse' or 'normal' are too big (> 65535 on a side) | 104 'diffuse' is too big (> 65535 on any side) |
109 'diffuse' and 'normal' aren't the same size | |
110 | 105 |
111 The lighting equation is currently: | 106 The lighting equation is currently: |
112 result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientCo lor | 107 result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientCo lor |
113 | 108 |
114 The normal map is currently assumed to be an 8888 image where the normal at a texel | |
115 is retrieved by: | |
116 N.x = R-127; | |
117 N.y = G-127; | |
118 N.z = B-127; | |
119 N.normalize(); | |
120 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is | |
121 (127, 127, 0). | |
122 */ | 109 */ |
123 static sk_sp<SkShader> Make(const SkBitmap& diffuse, const SkBitmap& normal, | 110 static sk_sp<SkShader> Make(const SkBitmap& diffuse, sk_sp<SkLights> lights, |
124 sk_sp<SkLights> lights, const SkVector& invNormR otation, | 111 const SkMatrix* diffLocalMatrix, sk_sp<NormalSou rce> normalSource); |
125 const SkMatrix* diffLocalMatrix, const SkMatrix* normLocalMatrix); | |
126 | 112 |
127 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 113 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
128 }; | 114 }; |
129 | 115 |
130 #endif | 116 #endif |
OLD | NEW |