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

Side by Side Diff: include/core/SkCanvas.h

Issue 2224163005: Made shadows blurry (thru implementing variance mapping) (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Made req changes; added some sliders 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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 SkCanvas_DEFINED 8 #ifndef SkCanvas_DEFINED
9 #define SkCanvas_DEFINED 9 #define SkCanvas_DEFINED
10 10
(...skipping 22 matching lines...) Expand all
33 class SkPath; 33 class SkPath;
34 class SkPicture; 34 class SkPicture;
35 class SkPixmap; 35 class SkPixmap;
36 class SkRasterClip; 36 class SkRasterClip;
37 class SkRRect; 37 class SkRRect;
38 struct SkRSXform; 38 struct SkRSXform;
39 class SkSurface; 39 class SkSurface;
40 class SkSurface_Base; 40 class SkSurface_Base;
41 class SkTextBlob; 41 class SkTextBlob;
42 42
43 /** \struct SkShadowParams
44
45 This struct holds information needed for drawing shadows.
46
47 fShadowRadius - radius of the shadow blur
48
49 fBiasingConstant - A constant used in variance shadow mapping to directly
50 0.0 - 1.0 reduce light bleeding. Essentially sets all shadows
51 ~.25 below a certain brightness equal to no light, and does
52 a linear step on the rest. Essentially makes shadows
53 darker and more rounded at higher values.
54
55 fMinVariance - Too low of a variance (near the outer edges of blurry
56 ~512, 1024 shadows) will lead to ugly sharp shadow brightness
57 distortions. This enforces a minimum amount of variance
58 in the calculation to smooth out the outside edges of
59 blurry shadows. However, too high of a value for this will
60 cause all shadows to be lighter by visibly different
61 amounts varying on depth.
62
robertphillips 2016/08/16 15:58:16 Specifies which ... ?
vjiaoblack 2016/08/16 16:48:21 Done.
63 fShadowAlgorithm - Decides what algorithm to use to draw shadows.
64 */
65 struct SkShadowParams {
66 SkScalar fShadowRadius;
67 SkScalar fBiasingConstant;
68 SkScalar fMinVariance;
69
70 enum ShadowType {
71 kNoBlur_BlurAlgorithm,
72 kVariance_BlurAlgorithm
73 };
74 ShadowType fShadowType;
75 };
76
43 /** \class SkCanvas 77 /** \class SkCanvas
44 78
45 A Canvas encapsulates all of the state about drawing into a device (bitmap). 79 A Canvas encapsulates all of the state about drawing into a device (bitmap).
46 This includes a reference to the device itself, and a stack of matrix/clip 80 This includes a reference to the device itself, and a stack of matrix/clip
47 values. For any given draw call (e.g. drawRect), the geometry of the object 81 values. For any given draw call (e.g. drawRect), the geometry of the object
48 being drawn is transformed by the concatenation of all the matrices in the 82 being drawn is transformed by the concatenation of all the matrices in the
49 stack. The transformed geometry is clipped by the intersection of all of 83 stack. The transformed geometry is clipped by the intersection of all of
50 the clips in the stack. 84 the clips in the stack.
51 85
52 While the Canvas holds the state of the drawing device, the state (style) 86 While the Canvas holds the state of the drawing device, the state (style)
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 * This is logically equivalent to 1131 * This is logically equivalent to
1098 * saveLayer(paint)/drawPicture/restore 1132 * saveLayer(paint)/drawPicture/restore
1099 */ 1133 */
1100 void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* pa int); 1134 void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* pa int);
1101 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, co nst SkPaint* paint) { 1135 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, co nst SkPaint* paint) {
1102 this->drawPicture(picture.get(), matrix, paint); 1136 this->drawPicture(picture.get(), matrix, paint);
1103 } 1137 }
1104 1138
1105 #ifdef SK_EXPERIMENTAL_SHADOWING 1139 #ifdef SK_EXPERIMENTAL_SHADOWING
1106 /** 1140 /**
1107 * Draw the picture into this canvas. 1141 * Draw the picture into this canvas, with shadows!
1108 * 1142 *
1109 * We will use the canvas's lights along with the picture information (draw depths of 1143 * We will use the canvas's lights along with the picture information (draw depths of
1110 * objects, etc) to first create a set of shadowmaps for the light-picture pairs, and 1144 * objects, etc) to first create a set of shadowmaps for the light-picture pairs, and
1111 * then use that set of shadowmaps to render the scene with shadows. 1145 * then use that set of shadowmaps to render the scene with shadows.
1112 * 1146 *
1113 * If matrix is non-null, apply that matrix to the CTM when drawing this pi cture. This is 1147 * If matrix is non-null, apply that matrix to the CTM when drawing this pi cture. This is
1114 * logically equivalent to 1148 * logically equivalent to
1115 * save/concat/drawPicture/restore 1149 * save/concat/drawPicture/restore
1116 * 1150 *
1117 * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's 1151 * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
1118 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas. 1152 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
1119 * This is logically equivalent to 1153 * This is logically equivalent to
1120 * saveLayer(paint)/drawPicture/restore 1154 * saveLayer(paint)/drawPicture/restore
1121 * 1155 *
1156 * We also support using variance shadow maps for blurred shadows; the user can specify
1157 * what shadow mapping algorithm to use with sType.
1158 * - Variance Shadow Mapping works by storing both the depth and depth^2 in the shadow map.
1159 * - Then, the shadow map can be blurred, and when reading from it, the f ragment shader
1160 * can calculate the variance of the depth at a position by doing E(x^2 ) - E(x)^2.
1161 * - We can then use the depth variance and depth at a fragment to arrive at an upper bound
1162 * of the probability that the current surface is shadowed by using Che byshev's
1163 * inequality, and then use that to shade the fragment.
1164 *
1165 * - There are a few problems with VSM.
1166 * * Light Bleeding | Areas with high variance, such as near the edges of high up rects,
1167 * will cause their shadow penumbras to overwrite ot herwise solid
1168 * shadows.
1169 * * Shape Distortion | We can combat Light Bleeding by biasing the sha dow (setting
1170 * mostly shaded fragments to completely shaded) a nd increasing
1171 * the minimum allowed variance. However, this war ps and rounds
1172 * out the shape of the shadow.
1122 */ 1173 */
1123 void drawShadowedPicture(const SkPicture*, 1174 void drawShadowedPicture(const SkPicture*,
1124 const SkMatrix* matrix, 1175 const SkMatrix* matrix,
1125 const SkPaint* paint); 1176 const SkPaint* paint,
robertphillips 2016/08/16 15:58:16 sParams -> params ?
vjiaoblack 2016/08/16 16:48:21 Done.
1177 const SkShadowParams& sParams);
1126 void drawShadowedPicture(const sk_sp<SkPicture>& picture, 1178 void drawShadowedPicture(const sk_sp<SkPicture>& picture,
1127 const SkMatrix* matrix, 1179 const SkMatrix* matrix,
1128 const SkPaint* paint) { 1180 const SkPaint* paint,
1129 this->drawShadowedPicture(picture.get(), matrix, paint); 1181 const SkShadowParams& sParams) {
1182 this->drawShadowedPicture(picture.get(), matrix, paint, sParams);
1130 } 1183 }
1131 #endif 1184 #endif
1132 1185
1133 enum VertexMode { 1186 enum VertexMode {
1134 kTriangles_VertexMode, 1187 kTriangles_VertexMode,
1135 kTriangleStrip_VertexMode, 1188 kTriangleStrip_VertexMode,
1136 kTriangleFan_VertexMode 1189 kTriangleFan_VertexMode
1137 }; 1190 };
1138 1191
1139 /** Draw the array of vertices, interpreted as triangles (based on mode). 1192 /** Draw the array of vertices, interpreted as triangles (based on mode).
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle); 1542 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle);
1490 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op); 1543 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op);
1491 1544
1492 virtual void onDiscard(); 1545 virtual void onDiscard();
1493 1546
1494 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint* ); 1547 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint* );
1495 1548
1496 #ifdef SK_EXPERIMENTAL_SHADOWING 1549 #ifdef SK_EXPERIMENTAL_SHADOWING
1497 virtual void onDrawShadowedPicture(const SkPicture*, 1550 virtual void onDrawShadowedPicture(const SkPicture*,
1498 const SkMatrix*, 1551 const SkMatrix*,
1499 const SkPaint*); 1552 const SkPaint*,
1553 const SkShadowParams& sParams);
1500 #endif 1554 #endif
1501 1555
1502 // Returns the canvas to be used by DrawIter. Default implementation 1556 // Returns the canvas to be used by DrawIter. Default implementation
1503 // returns this. Subclasses that encapsulate an indirect canvas may 1557 // returns this. Subclasses that encapsulate an indirect canvas may
1504 // need to overload this method. The impl must keep track of this, as it 1558 // need to overload this method. The impl must keep track of this, as it
1505 // is not released or deleted by the caller. 1559 // is not released or deleted by the caller.
1506 virtual SkCanvas* canvasForDrawIter(); 1560 virtual SkCanvas* canvasForDrawIter();
1507 1561
1508 // Clip rectangle bounds. Called internally by saveLayer. 1562 // Clip rectangle bounds. Called internally by saveLayer.
1509 // returns false if the entire rectangle is entirely clipped out 1563 // returns false if the entire rectangle is entirely clipped out
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 1772
1719 class SkCanvasClipVisitor { 1773 class SkCanvasClipVisitor {
1720 public: 1774 public:
1721 virtual ~SkCanvasClipVisitor(); 1775 virtual ~SkCanvasClipVisitor();
1722 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; 1776 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
1723 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; 1777 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
1724 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; 1778 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
1725 }; 1779 };
1726 1780
1727 #endif 1781 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698