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

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

Issue 2080993002: Added API for Bevel NormalSource. (Closed) Base URL: https://skia.googlesource.com/skia@dvonbeck-diffuse-api-change
Patch Set: Addressed patch 8 comments Created 4 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 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 SkNormalSource_DEFINED 8 #ifndef SkNormalSource_DEFINED
9 #define SkNormalSource_DEFINED 9 #define SkNormalSource_DEFINED
10 10
11 #include "SkFlattenable.h" 11 #include "SkFlattenable.h"
12 #include "SkShader.h"
13
14 class SkMatrix;
15 class SkPoint3;
16
17 #if SK_SUPPORT_GPU
18 class GrFragmentProcessor;
19 class GrContext;
20 enum SkFilterQuality;
21 enum SkSourceGammaTreatment;
22 #endif
12 23
13 /** Abstract class that generates or reads in normals for use by SkLightingShade r. 24 /** Abstract class that generates or reads in normals for use by SkLightingShade r.
14 */ 25 */
15 class SK_API SkNormalSource : public SkFlattenable { 26 class SK_API SkNormalSource : public SkFlattenable {
16 public: 27 public:
17 virtual ~SkNormalSource() override; 28 virtual ~SkNormalSource() override;
18 29
19 #if SK_SUPPORT_GPU 30 #if SK_SUPPORT_GPU
20 /** Returns a fragment processor that takes no input and outputs a normal (a lready rotated) 31 /** Returns a fragment processor that takes no input and outputs a normal (a lready rotated)
21 as its output color. To be used as a child fragment processor. 32 as its output color. To be used as a child fragment processor.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 N.normalize(); 73 N.normalize();
63 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is 74 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis is
64 (127, 127, 0). 75 (127, 127, 0).
65 */ 76 */
66 static sk_sp<SkNormalSource> MakeFromNormalMap(sk_sp<SkShader> map, const Sk Matrix& ctm); 77 static sk_sp<SkNormalSource> MakeFromNormalMap(sk_sp<SkShader> map, const Sk Matrix& ctm);
67 78
68 /** Returns a normal source that provides straight-up normals only (0, 0, 1) . 79 /** Returns a normal source that provides straight-up normals only (0, 0, 1) .
69 */ 80 */
70 static sk_sp<SkNormalSource> MakeFlat(); 81 static sk_sp<SkNormalSource> MakeFlat();
71 82
83 /** This enum specifies the shape of the bevel. All bevels output <0, 0, 1> as the surface
84 * normal for any point more than 'width' away from any edge.
85 *
86 * Mathematical details:
87 * For the purpose of describing the shape of the bevel, we define 'w' to b e the given width of
88 * the bevel, and 'h' to be the given height. We will assume the shape is r otated such that the
89 * point being shaded as well as the closest point in the shape's edge to t hat point are in the
90 * x-axis, and the shape is translated so that the aformentioned point in t he edge is at
91 * coordinates (w, 0, 0) and the end of the bevel is at (0, 0, h).
92 *
93 */
94 enum class BevelType {
95 /* This bevel simulates a surface that is slanted from the shape's edges inwards, linearly.
96 *
97 * Mathematical details:
98 * This bevel follows a straight line from (w, 0, 0) to (0, 0, h).
99 */
100 kLinear,
101 /* This bevel simulates a surface that rounds off at the shape's edges, smoothly becoming
102 * perpendicular to the x-y plane.
103 *
104 * Mathematical details:
105 * This bevel follows the only quadratic bezier curve whose start point is at (w, 0, 0) and
106 * has a perpendicular normal vector of <1,0,0>, and whose end point is at (0, 0, h) and has
107 * a perpendicular normal vector of <0,0,1>.
egdaniel 2016/07/26 19:54:41 What changes if h is negative, is confusing cause
dvonbeck 2016/07/27 17:44:57 Done.
108 */
109 kRoundedOut,
110 /* This bevel simulates a surface that sharply becomes perpendicular to the x-y plane when
111 * at 'width' units from the nearest edge, and then rounds off towards t he shape's
112 * edge, smoothly becoming paralel to the x-y plane.
113 *
114 * Mathematical details:
115 * This bevel follows the only quadratic bezier curve whose start point is at (w, 0, 0) and
116 * has a perpendicular normal vector of <0,0,1>, and whose end point is at (0, 0, h) and has
117 * a perpendicular normal vector of <1,0,0>.
egdaniel 2016/07/26 19:54:41 Same as above, but control point will be at (0,0,0
dvonbeck 2016/07/27 17:44:57 Done.
118 */
119 kRoundedIn
120 };
121 /** Returns a normal source that generates a bevel for the given shape. UNIM PLEMENTED: Will
122 return straight-up normals only.
123
124 @param type the type of bevel to add
125 @param width the width of the bevel, in source space. Must be positive .
126 @param height the height of the plateau, in source space. Can be positi ve, negative,
127 or zero. A negative height means the simulated bevels slo pe downwards.
128 */
129 static sk_sp<SkNormalSource> MakeBevel(BevelType, SkScalar width, SkScalar h eight);
130
72 SK_DEFINE_FLATTENABLE_TYPE(SkNormalSource) 131 SK_DEFINE_FLATTENABLE_TYPE(SkNormalSource)
73 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() 132 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
74 }; 133 };
75 134
76 #endif 135 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698