OLD | NEW |
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 struct SkPoint3; |
| 16 |
| 17 #if SK_SUPPORT_GPU |
| 18 class GrFragmentProcessor; |
| 19 #endif |
12 | 20 |
13 /** Abstract class that generates or reads in normals for use by SkLightingShade
r. | 21 /** Abstract class that generates or reads in normals for use by SkLightingShade
r. |
14 */ | 22 */ |
15 class SK_API SkNormalSource : public SkFlattenable { | 23 class SK_API SkNormalSource : public SkFlattenable { |
16 public: | 24 public: |
17 virtual ~SkNormalSource() override; | 25 virtual ~SkNormalSource() override; |
18 | 26 |
19 #if SK_SUPPORT_GPU | 27 #if SK_SUPPORT_GPU |
20 /** Returns a fragment processor that takes no input and outputs a normal (a
lready rotated) | 28 /** 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. | 29 as its output color. To be used as a child fragment processor. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 N.normalize(); | 65 N.normalize(); |
58 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis
is | 66 The +Z axis is thus encoded in RGB as (127, 127, 255) while the -Z axis
is |
59 (127, 127, 0). | 67 (127, 127, 0). |
60 */ | 68 */ |
61 static sk_sp<SkNormalSource> MakeFromNormalMap(sk_sp<SkShader> map, const Sk
Matrix& ctm); | 69 static sk_sp<SkNormalSource> MakeFromNormalMap(sk_sp<SkShader> map, const Sk
Matrix& ctm); |
62 | 70 |
63 /** Returns a normal source that provides straight-up normals only (0, 0, 1)
. | 71 /** Returns a normal source that provides straight-up normals only (0, 0, 1)
. |
64 */ | 72 */ |
65 static sk_sp<SkNormalSource> MakeFlat(); | 73 static sk_sp<SkNormalSource> MakeFlat(); |
66 | 74 |
| 75 /** This enum specifies the shape of the bevel. All bevels output <0, 0, 1>
as the surface |
| 76 * normal for any point more than 'width' away from any edge. |
| 77 * |
| 78 * Mathematical details: |
| 79 * For the purpose of describing the shape of the bevel, we define 'w' to b
e the given width of |
| 80 * the bevel, and 'h' to be the given height. We will assume the shape is r
otated such that the |
| 81 * point being shaded as well as the closest point in the shape's edge to t
hat point are in the |
| 82 * x-axis, and the shape is translated so that the aforementioned point in
the edge is at |
| 83 * coordinates (w, 0, 0) and the end of the bevel is at (0, 0, h). |
| 84 * |
| 85 */ |
| 86 enum class BevelType { |
| 87 /* This bevel simulates a surface that is slanted from the shape's edges
inwards, linearly. |
| 88 * |
| 89 * Mathematical details: |
| 90 * This bevel follows a straight line from (w, 0, 0) to (0, 0, h). |
| 91 */ |
| 92 kLinear, |
| 93 /* This bevel simulates a surface that rounds off at the shape's edges,
smoothly becoming |
| 94 * perpendicular to the x-y plane. |
| 95 * |
| 96 * Mathematical details: |
| 97 * This bevel follows the only quadratic bezier curve whose start point
is at (w, 0, 0), |
| 98 * control point is at (w, 0, h), and end point is at (0, 0, h). |
| 99 */ |
| 100 kRoundedOut, |
| 101 /* This bevel simulates a surface that sharply becomes perpendicular to
the x-y plane when |
| 102 * at 'width' units from the nearest edge, and then rounds off towards t
he shape's |
| 103 * edge, smoothly becoming parallel to the x-y plane. |
| 104 * |
| 105 * Mathematical details: |
| 106 * This bevel follows the only quadratic bezier curve whose start point
is at (w, 0, 0), |
| 107 * control point is at (0, 0, 0), and end point is at (0, 0, h). |
| 108 */ |
| 109 kRoundedIn |
| 110 }; |
| 111 /** Returns a normal source that generates a bevel for the given shape. UNIM
PLEMENTED: Will |
| 112 return straight-up normals only. |
| 113 |
| 114 @param type the type of bevel to add |
| 115 @param width the width of the bevel, in source space. Must be positive
. |
| 116 @param height the height of the plateau, in source space. Can be positi
ve, negative, |
| 117 or zero. A negative height means the simulated bevels slo
pe downwards. |
| 118 */ |
| 119 static sk_sp<SkNormalSource> MakeBevel(BevelType, SkScalar width, SkScalar h
eight); |
| 120 |
67 SK_DEFINE_FLATTENABLE_TYPE(SkNormalSource) | 121 SK_DEFINE_FLATTENABLE_TYPE(SkNormalSource) |
68 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 122 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
69 }; | 123 }; |
70 | 124 |
71 #endif | 125 #endif |
OLD | NEW |