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

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: fixed compile error for disabled shadowing 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
« no previous file with comments | « gm/shadowmaps.cpp ('k') | include/private/SkRecords.h » ('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 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 fType - Decides which algorithm to use to draw shadows.
64 */
65 struct SkShadowParams {
bsalomon 2016/08/24 18:30:35 I'm not crazy about adding this to the top of SkCa
66 SkScalar fShadowRadius;
67 SkScalar fBiasingConstant;
68 SkScalar fMinVariance;
69
70 enum ShadowType {
71 kNoBlur_ShadowType,
72 kVariance_ShadowType,
73
74 kLast_ShadowType = kVariance_ShadowType
75 };
76 static const int kShadowTypeCount = kLast_ShadowType + 1;
77
78 ShadowType fType;
79 };
80
43 /** \class SkCanvas 81 /** \class SkCanvas
44 82
45 A Canvas encapsulates all of the state about drawing into a device (bitmap). 83 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 84 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 85 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 86 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 87 stack. The transformed geometry is clipped by the intersection of all of
50 the clips in the stack. 88 the clips in the stack.
51 89
52 While the Canvas holds the state of the drawing device, the state (style) 90 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 1104 * This is logically equivalent to
1067 * saveLayer(paint)/drawPicture/restore 1105 * saveLayer(paint)/drawPicture/restore
1068 */ 1106 */
1069 void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* pa int); 1107 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) { 1108 void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, co nst SkPaint* paint) {
1071 this->drawPicture(picture.get(), matrix, paint); 1109 this->drawPicture(picture.get(), matrix, paint);
1072 } 1110 }
1073 1111
1074 #ifdef SK_EXPERIMENTAL_SHADOWING 1112 #ifdef SK_EXPERIMENTAL_SHADOWING
1075 /** 1113 /**
1076 * Draw the picture into this canvas. 1114 * Draw the picture into this canvas, with shadows!
1077 * 1115 *
1078 * We will use the canvas's lights along with the picture information (draw depths of 1116 * 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 1117 * 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. 1118 * then use that set of shadowmaps to render the scene with shadows.
1081 * 1119 *
1082 * If matrix is non-null, apply that matrix to the CTM when drawing this pi cture. This is 1120 * If matrix is non-null, apply that matrix to the CTM when drawing this pi cture. This is
1083 * logically equivalent to 1121 * logically equivalent to
1084 * save/concat/drawPicture/restore 1122 * save/concat/drawPicture/restore
1085 * 1123 *
1086 * If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's 1124 * 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. 1125 * alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
1088 * This is logically equivalent to 1126 * This is logically equivalent to
1089 * saveLayer(paint)/drawPicture/restore 1127 * saveLayer(paint)/drawPicture/restore
1090 * 1128 *
1129 * We also support using variance shadow maps for blurred shadows; the user can specify
1130 * what shadow mapping algorithm to use with params.
1131 * - Variance Shadow Mapping works by storing both the depth and depth^2 in the shadow map.
1132 * - Then, the shadow map can be blurred, and when reading from it, the f ragment shader
1133 * can calculate the variance of the depth at a position by doing E(x^2 ) - E(x)^2.
1134 * - We can then use the depth variance and depth at a fragment to arrive at an upper bound
1135 * of the probability that the current surface is shadowed by using Che byshev's
1136 * inequality, and then use that to shade the fragment.
1137 *
1138 * - There are a few problems with VSM.
1139 * * Light Bleeding | Areas with high variance, such as near the edges of high up rects,
1140 * will cause their shadow penumbras to overwrite ot herwise solid
1141 * shadows.
1142 * * Shape Distortion | We can combat Light Bleeding by biasing the sha dow (setting
1143 * mostly shaded fragments to completely shaded) a nd increasing
1144 * the minimum allowed variance. However, this war ps and rounds
1145 * out the shape of the shadow.
1091 */ 1146 */
1092 void drawShadowedPicture(const SkPicture*, 1147 void drawShadowedPicture(const SkPicture*,
1093 const SkMatrix* matrix, 1148 const SkMatrix* matrix,
1094 const SkPaint* paint); 1149 const SkPaint* paint,
1150 const SkShadowParams& params);
1095 void drawShadowedPicture(const sk_sp<SkPicture>& picture, 1151 void drawShadowedPicture(const sk_sp<SkPicture>& picture,
1096 const SkMatrix* matrix, 1152 const SkMatrix* matrix,
1097 const SkPaint* paint) { 1153 const SkPaint* paint,
1098 this->drawShadowedPicture(picture.get(), matrix, paint); 1154 const SkShadowParams& params) {
1155 this->drawShadowedPicture(picture.get(), matrix, paint, params);
1099 } 1156 }
1100 #endif 1157 #endif
1101 1158
1102 enum VertexMode { 1159 enum VertexMode {
1103 kTriangles_VertexMode, 1160 kTriangles_VertexMode,
1104 kTriangleStrip_VertexMode, 1161 kTriangleStrip_VertexMode,
1105 kTriangleFan_VertexMode 1162 kTriangleFan_VertexMode
1106 }; 1163 };
1107 1164
1108 /** Draw the array of vertices, interpreted as triangles (based on mode). 1165 /** 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); 1484 virtual void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle e dgeStyle);
1428 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op); 1485 virtual void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op);
1429 1486
1430 virtual void onDiscard(); 1487 virtual void onDiscard();
1431 1488
1432 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint* ); 1489 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint* );
1433 1490
1434 #ifdef SK_EXPERIMENTAL_SHADOWING 1491 #ifdef SK_EXPERIMENTAL_SHADOWING
1435 virtual void onDrawShadowedPicture(const SkPicture*, 1492 virtual void onDrawShadowedPicture(const SkPicture*,
1436 const SkMatrix*, 1493 const SkMatrix*,
1437 const SkPaint*); 1494 const SkPaint*,
1495 const SkShadowParams& params);
1438 #endif 1496 #endif
1439 1497
1440 // Returns the canvas to be used by DrawIter. Default implementation 1498 // Returns the canvas to be used by DrawIter. Default implementation
1441 // returns this. Subclasses that encapsulate an indirect canvas may 1499 // returns this. Subclasses that encapsulate an indirect canvas may
1442 // need to overload this method. The impl must keep track of this, as it 1500 // need to overload this method. The impl must keep track of this, as it
1443 // is not released or deleted by the caller. 1501 // is not released or deleted by the caller.
1444 virtual SkCanvas* canvasForDrawIter(); 1502 virtual SkCanvas* canvasForDrawIter();
1445 1503
1446 // Clip rectangle bounds. Called internally by saveLayer. 1504 // Clip rectangle bounds. Called internally by saveLayer.
1447 // returns false if the entire rectangle is entirely clipped out 1505 // returns false if the entire rectangle is entirely clipped out
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 1744
1687 class SkCanvasClipVisitor { 1745 class SkCanvasClipVisitor {
1688 public: 1746 public:
1689 virtual ~SkCanvasClipVisitor(); 1747 virtual ~SkCanvasClipVisitor();
1690 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0; 1748 virtual void clipRect(const SkRect&, SkRegion::Op, bool antialias) = 0;
1691 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0; 1749 virtual void clipRRect(const SkRRect&, SkRegion::Op, bool antialias) = 0;
1692 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0; 1750 virtual void clipPath(const SkPath&, SkRegion::Op, bool antialias) = 0;
1693 }; 1751 };
1694 1752
1695 #endif 1753 #endif
OLDNEW
« no previous file with comments | « gm/shadowmaps.cpp ('k') | include/private/SkRecords.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698