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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: include/core/SkCanvas.h
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 26e3c8e3c52bf98590650f7be13f19012b866be4..d7ae0467f3616c48992c4ee609944bbf218389ac 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -40,6 +40,40 @@ class SkSurface;
class SkSurface_Base;
class SkTextBlob;
+/** \struct SkShadowParams
+
+ This struct holds information needed for drawing shadows.
+
+ fShadowRadius - radius of the shadow blur
+
+ fBiasingConstant - A constant used in variance shadow mapping to directly
+ 0.0 - 1.0 reduce light bleeding. Essentially sets all shadows
+ ~.25 below a certain brightness equal to no light, and does
+ a linear step on the rest. Essentially makes shadows
+ darker and more rounded at higher values.
+
+ fMinVariance - Too low of a variance (near the outer edges of blurry
+ ~512, 1024 shadows) will lead to ugly sharp shadow brightness
+ distortions. This enforces a minimum amount of variance
+ in the calculation to smooth out the outside edges of
+ blurry shadows. However, too high of a value for this will
+ cause all shadows to be lighter by visibly different
+ amounts varying on depth.
+
robertphillips 2016/08/16 15:58:16 Specifies which ... ?
vjiaoblack 2016/08/16 16:48:21 Done.
+ fShadowAlgorithm - Decides what algorithm to use to draw shadows.
+*/
+struct SkShadowParams {
+ SkScalar fShadowRadius;
+ SkScalar fBiasingConstant;
+ SkScalar fMinVariance;
+
+ enum ShadowType {
+ kNoBlur_BlurAlgorithm,
+ kVariance_BlurAlgorithm
+ };
+ ShadowType fShadowType;
+};
+
/** \class SkCanvas
A Canvas encapsulates all of the state about drawing into a device (bitmap).
@@ -1104,7 +1138,7 @@ public:
#ifdef SK_EXPERIMENTAL_SHADOWING
/**
- * Draw the picture into this canvas.
+ * Draw the picture into this canvas, with shadows!
*
* We will use the canvas's lights along with the picture information (draw depths of
* objects, etc) to first create a set of shadowmaps for the light-picture pairs, and
@@ -1119,14 +1153,33 @@ public:
* This is logically equivalent to
* saveLayer(paint)/drawPicture/restore
*
+ * We also support using variance shadow maps for blurred shadows; the user can specify
+ * what shadow mapping algorithm to use with sType.
+ * - Variance Shadow Mapping works by storing both the depth and depth^2 in the shadow map.
+ * - Then, the shadow map can be blurred, and when reading from it, the fragment shader
+ * can calculate the variance of the depth at a position by doing E(x^2) - E(x)^2.
+ * - We can then use the depth variance and depth at a fragment to arrive at an upper bound
+ * of the probability that the current surface is shadowed by using Chebyshev's
+ * inequality, and then use that to shade the fragment.
+ *
+ * - There are a few problems with VSM.
+ * * Light Bleeding | Areas with high variance, such as near the edges of high up rects,
+ * will cause their shadow penumbras to overwrite otherwise solid
+ * shadows.
+ * * Shape Distortion | We can combat Light Bleeding by biasing the shadow (setting
+ * mostly shaded fragments to completely shaded) and increasing
+ * the minimum allowed variance. However, this warps and rounds
+ * out the shape of the shadow.
*/
void drawShadowedPicture(const SkPicture*,
const SkMatrix* matrix,
- const SkPaint* paint);
+ const SkPaint* paint,
robertphillips 2016/08/16 15:58:16 sParams -> params ?
vjiaoblack 2016/08/16 16:48:21 Done.
+ const SkShadowParams& sParams);
void drawShadowedPicture(const sk_sp<SkPicture>& picture,
const SkMatrix* matrix,
- const SkPaint* paint) {
- this->drawShadowedPicture(picture.get(), matrix, paint);
+ const SkPaint* paint,
+ const SkShadowParams& sParams) {
+ this->drawShadowedPicture(picture.get(), matrix, paint, sParams);
}
#endif
@@ -1496,7 +1549,8 @@ protected:
#ifdef SK_EXPERIMENTAL_SHADOWING
virtual void onDrawShadowedPicture(const SkPicture*,
const SkMatrix*,
- const SkPaint*);
+ const SkPaint*,
+ const SkShadowParams& sParams);
#endif
// Returns the canvas to be used by DrawIter. Default implementation

Powered by Google App Engine
This is Rietveld 408576698