Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: src/core/SkLightingShader.h

Issue 2101653002: Revert of Refactoring of CPU NormalMap handling out into its own class (Closed) Base URL: https://skia.googlesource.com/skia@dvonbeck-normals-gpu-cl
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkFlattenable.h ('k') | src/core/SkLightingShader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
19 /** Returns a shader that lights the diffuse and normal maps with a set of l ights. 68 /** Returns a shader that lights the diffuse and normal maps with a set of l ights.
20 69
21 It returns a shader with a reference count of 1. 70 It returns a shader with a reference count of 1.
22 The caller should decrement the shader's reference count when done with the shader. 71 The caller should decrement the shader's reference count when done with the shader.
23 It is an error for count to be < 2. 72 It is an error for count to be < 2.
24 @param diffuse the diffuse bitmap 73 @param diffuse the diffuse bitmap
25 @param normal the normal map 74 @param normal the normal map
26 @param lights the lights applied to the normal map 75 @param lights the lights applied to the normal map
27 @param invNormRotation rotation applied to the normal map's normals 76 @param invNormRotation rotation applied to the normal map's normals
28 @param diffLocalMatrix the local matrix for the diffuse map (transform from 77 @param diffLocalMatrix the local matrix for the diffuse texture
29 texture coordinates to shape source coordinates) . nullptr is 78 @param normLocalMatrix the local matrix for the normal map
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.
34 79
35 nullptr will be returned if: 80 nullptr will be returned if:
36 either 'diffuse' or 'normal' are empty 81 either 'diffuse' or 'normal' are empty
37 either 'diffuse' or 'normal' are too big (> 65535 on a side) 82 either 'diffuse' or 'normal' are too big (> 65535 on a side)
38 'diffuse' and 'normal' aren't the same size 83 'diffuse' and 'normal' aren't the same size
39 84
40 The lighting equation is currently: 85 The lighting equation is currently:
41 result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientCo lor 86 result = LightColor * DiffuseColor * (Normal * LightDir) + AmbientCo lor
42 87
43 The normal map is currently assumed to be an 8888 image where the normal at a texel 88 The normal map is currently assumed to be an 8888 image where the normal at a texel
44 is retrieved by: 89 is retrieved by:
45 N.x = R-127; 90 N.x = R-127;
46 N.y = G-127; 91 N.y = G-127;
47 N.z = B-127; 92 N.z = B-127;
48 N.normalize(); 93 N.normalize();
49 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is 94 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is
50 (127, 127, 0). 95 (127, 127, 0).
51 */ 96 */
52 static sk_sp<SkShader> Make(const SkBitmap& diffuse, const SkBitmap& normal, 97 static sk_sp<SkShader> Make(const SkBitmap& diffuse, const SkBitmap& normal,
53 sk_sp<SkLights> lights, const SkVector& invNormR otation, 98 sk_sp<SkLights> lights, const SkVector& invNormR otation,
54 const SkMatrix* diffLocalMatrix, const SkMatrix* normLocalMatrix); 99 const SkMatrix* diffLocalMatrix, const SkMatrix* normLocalMatrix);
55 100
56 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() 101 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
57 }; 102 };
58 103
59 #endif 104 #endif
OLDNEW
« no previous file with comments | « include/core/SkFlattenable.h ('k') | src/core/SkLightingShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698