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

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: rebased off master again! Created 4 years, 3 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
63 fShadowAlgorithm - Decides which 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 fType;
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 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 * This is logically equivalent to 1100 * This is logically equivalent to
1067 * saveLayer(paint)/drawPicture/restore 1101 * saveLayer(paint)/drawPicture/restore
1068 */ 1102 */
1069 void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* pa int); 1103 void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* pa int);
1070 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, co nst SkPaint* paint) { 1104 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, co nst SkPaint* paint) {
1071 this->drawPicture(picture.get(), matrix, paint); 1105 this->drawPicture(picture.get(), matrix, paint);
1072 } 1106 }
1073 1107
1074 #ifdef SK_EXPERIMENTAL_SHADOWING 1108 #ifdef SK_EXPERIMENTAL_SHADOWING
1075 /** 1109 /**
1076 * Draw the picture into this canvas. 1110 * Draw the picture into this canvas, with shadows!
1077 * 1111 *
1078 * We will use the canvas's lights along with the picture information (draw depths of 1112 * We will use the canvas's lights along with the picture information (draw depths of
1079 * objects, etc) to first create a set of shadowmaps for the light-picture pairs, and 1113 * objects, etc) to first create a set of shadowmaps for the light-picture pairs, and
1080 * then use that set of shadowmaps to render the scene with shadows. 1114 * then use that set of shadowmaps to render the scene with shadows.
1081 * 1115 *
1082 * If matrix is non-null, apply that matrix to the CTM when drawing this pi cture. This is 1116 * If matrix is non-null, apply that matrix to the CTM when drawing this pi cture. This is
1083 * logically equivalent to 1117 * logically equivalent to
1084 * save/concat/drawPicture/restore 1118 * save/concat/drawPicture/restore
1085 * 1119 *
1086 * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's 1120 * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
1087 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas. 1121 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
1088 * This is logically equivalent to 1122 * This is logically equivalent to
1089 * saveLayer(paint)/drawPicture/restore 1123 * saveLayer(paint)/drawPicture/restore
1090 * 1124 *
1125 * We also support using variance shadow maps for blurred shadows; the user can specify
robertphillips 2016/08/23 17:19:39 sType -> params
vjiaoblack 2016/08/23 18:01:21 Done.
1126 * what shadow mapping algorithm to use with sType.
1127 * - Variance Shadow Mapping works by storing both the depth and depth^2 in the shadow map.
1128 * - Then, the shadow map can be blurred, and when reading from it, the f ragment shader
1129 * can calculate the variance of the depth at a position by doing E(x^2 ) - E(x)^2.
1130 * - We can then use the depth variance and depth at a fragment to arrive at an upper bound
1131 * of the probability that the current surface is shadowed by using Che byshev's
1132 * inequality, and then use that to shade the fragment.
1133 *
1134 * - There are a few problems with VSM.
1135 * * Light Bleeding | Areas with high variance, such as near the edges of high up rects,
1136 * will cause their shadow penumbras to overwrite ot herwise solid
1137 * shadows.
1138 * * Shape Distortion | We can combat Light Bleeding by biasing the sha dow (setting
1139 * mostly shaded fragments to completely shaded) a nd increasing
1140 * the minimum allowed variance. However, this war ps and rounds
1141 * out the shape of the shadow.
1091 */ 1142 */
1092 void drawShadowedPicture(const SkPicture*, 1143 void drawShadowedPicture(const SkPicture*,
1093 const SkMatrix* matrix, 1144 const SkMatrix* matrix,
1094 const SkPaint* paint); 1145 const SkPaint* paint,
1146 const SkShadowParams& params);
1095 void drawShadowedPicture(const sk_sp<SkPicture>& picture, 1147 void drawShadowedPicture(const sk_sp<SkPicture>& picture,
1096 const SkMatrix* matrix, 1148 const SkMatrix* matrix,
1097 const SkPaint* paint) { 1149 const SkPaint* paint,
1098 this->drawShadowedPicture(picture.get(), matrix, paint); 1150 const SkShadowParams& params) {
1151 this->drawShadowedPicture(picture.get(), matrix, paint, params);
1099 } 1152 }
1100 #endif 1153 #endif
1101 1154
1102 enum VertexMode { 1155 enum VertexMode {
1103 kTriangles_VertexMode, 1156 kTriangles_VertexMode,
1104 kTriangleStrip_VertexMode, 1157 kTriangleStrip_VertexMode,
1105 kTriangleFan_VertexMode 1158 kTriangleFan_VertexMode
1106 }; 1159 };
1107 1160
1108 /** Draw the array of vertices, interpreted as triangles (based on mode). 1161 /** Draw the array of vertices, interpreted as triangles (based on mode).
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle); 1480 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle);
1428 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op); 1481 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op);
1429 1482
1430 virtual void onDiscard(); 1483 virtual void onDiscard();
1431 1484
1432 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint* ); 1485 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint* );
1433 1486
1434 #ifdef SK_EXPERIMENTAL_SHADOWING 1487 #ifdef SK_EXPERIMENTAL_SHADOWING
1435 virtual void onDrawShadowedPicture(const SkPicture*, 1488 virtual void onDrawShadowedPicture(const SkPicture*,
1436 const SkMatrix*, 1489 const SkMatrix*,
1437 const SkPaint*); 1490 const SkPaint*,
1491 const SkShadowParams& params);
1438 #endif 1492 #endif
1439 1493
1440 // Returns the canvas to be used by DrawIter. Default implementation 1494 // Returns the canvas to be used by DrawIter. Default implementation
1441 // returns this. Subclasses that encapsulate an indirect canvas may 1495 // returns this. Subclasses that encapsulate an indirect canvas may
1442 // need to overload this method. The impl must keep track of this, as it 1496 // need to overload this method. The impl must keep track of this, as it
1443 // is not released or deleted by the caller. 1497 // is not released or deleted by the caller.
1444 virtual SkCanvas* canvasForDrawIter(); 1498 virtual SkCanvas* canvasForDrawIter();
1445 1499
1446 // Clip rectangle bounds. Called internally by saveLayer. 1500 // Clip rectangle bounds. Called internally by saveLayer.
1447 // returns false if the entire rectangle is entirely clipped out 1501 // returns false if the entire rectangle is entirely clipped out
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 1740
1687 class SkCanvasClipVisitor { 1741 class SkCanvasClipVisitor {
1688 public: 1742 public:
1689 virtual ~SkCanvasClipVisitor(); 1743 virtual ~SkCanvasClipVisitor();
1690 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; 1744 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
1691 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; 1745 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
1692 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; 1746 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
1693 }; 1747 };
1694 1748
1695 #endif 1749 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698