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

Unified Diff: src/core/SkCanvas.cpp

Issue 2224163005: Made shadows blurry (thru implementing variance mapping) (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: 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: src/core/SkCanvas.cpp
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 24d9506bd79ca2719440e3f0f16cd09fb833f0ca..f2f5e6c7015999a99a9dec875d760be7c97536ec 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -39,11 +39,28 @@
#include "SkTraceEvent.h"
#include <new>
+#include <SkShadowPaintFilterCanvas.h>
+#include "SkLights.h"
+
+#include "SkDrawFilter.h"
+#include "SkLights.h"
+#include "SkPictureRecorder.h"
+#include "SkSurface.h"
+#include "SkPaintFilterCanvas.h"
+#include "SkMatrix.h"
+#include "SkShadowShader.h"
+#include "SkBitmapProcShader.h"
+#include "SkNormalSource.h"
+
+
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "GrRenderTarget.h"
#include "SkGrPriv.h"
+#include "SkShadowShader.h"
+#include "SkShadowMapShader.h"
+
#endif
#define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0)
@@ -3068,6 +3085,9 @@ void SkCanvas::drawShadowedPicture(const SkPicture* picture,
this->onDrawShadowedPicture(picture, matrix, paint);
}
+#include "GrDrawContext.h"
+#include "../../include/effects/SkBlurImageFilter.h"
+
robertphillips 2016/08/10 14:23:18 Let's parameterize this so we can turn variance sh
vjiaoblack 2016/08/11 18:28:51 Done.
void SkCanvas::onDrawShadowedPicture(const SkPicture* picture,
const SkMatrix* matrix,
const SkPaint* paint) {
@@ -3086,46 +3106,6 @@ void SkCanvas::onDrawShadowedPicture(const SkPicture* picture,
SkAutoCanvasMatrixPaint acmp(this, matrix, paint, picture->cullRect());
- for (int i = 0; i < fLights->numLights(); ++i) {
- // skip over ambient lights; they don't cast shadows
- // lights that have shadow maps do not need updating (because lights are immutable)
-
- if (SkLights::Light::kAmbient_LightType == fLights->light(i).type() ||
- fLights->light(i).getShadowMap() != nullptr) {
- continue;
- }
-
- // TODO: compute the correct size of the depth map from the light properties
- // TODO: maybe add a kDepth_8_SkColorType
- // TODO: find actual max depth of picture
- SkISize shMapSize = SkShadowPaintFilterCanvas::ComputeDepthMapSize(
- fLights->light(i), 255,
- picture->cullRect().width(),
- picture->cullRect().height());
-
- SkImageInfo info = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight,
- kBGRA_8888_SkColorType,
- kOpaque_SkAlphaType);
-
- // Create a new surface (that matches the backend of canvas)
- // for each shadow map
- sk_sp<SkSurface> surf(this->makeSurface(info));
-
- // Wrap another SPFCanvas around the surface
- sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas =
- sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas());
-
- // set the depth map canvas to have the light we're drawing.
- SkLights::Builder builder;
- builder.add(fLights->light(i));
- sk_sp<SkLights> curLight = builder.finish();
-
- depthMapCanvas->setLights(std::move(curLight));
- depthMapCanvas->drawPicture(picture);
-
- fLights->light(i).setShadowMap(surf->makeImageSnapshot());
- }
-
sk_sp<SkImage> povDepthMap;
sk_sp<SkImage> diffuseMap;
@@ -3156,7 +3136,6 @@ void SkCanvas::onDrawShadowedPicture(const SkPicture* picture,
depthMapCanvas->setLights(std::move(povLight));
depthMapCanvas->drawPicture(picture);
-
povDepthMap = surf->makeImageSnapshot();
}
@@ -3173,14 +3152,67 @@ void SkCanvas::onDrawShadowedPicture(const SkPicture* picture,
diffuseMap = surf->makeImageSnapshot();
}
robertphillips 2016/08/10 14:23:18 Why was this moved down?
vjiaoblack 2016/08/11 18:28:51 Done.
+ for (int i = 0; i < fLights->numLights(); ++i) {
+ // skip over ambient lights; they don't cast shadows
+ // lights that have shadow maps do not need updating (because lights are immutable)
+
+ if (SkLights::Light::kAmbient_LightType == fLights->light(i).type() ||
+ fLights->light(i).getShadowMap() != nullptr) {
+ continue;
+ }
+
+ // TODO: compute the correct size of the depth map from the light properties
+ // TODO: maybe add a kDepth_8_SkColorType
+ // TODO: find actual max depth of picture
+ SkISize shMapSize = SkShadowPaintFilterCanvas::ComputeDepthMapSize(
+ fLights->light(i), 255,
+ picture->cullRect().width(),
+ picture->cullRect().height());
+
+ SkImageInfo info = SkImageInfo::Make(shMapSize.fWidth, shMapSize.fHeight,
+ kBGRA_8888_SkColorType,
+ kOpaque_SkAlphaType);
+
+ // Create a new surface (that matches the backend of canvas)
+ // for each shadow map
+ sk_sp<SkSurface> surf(this->makeSurface(info));
+
+ // Wrap another SPFCanvas around the surface
+ sk_sp<SkShadowPaintFilterCanvas> depthMapCanvas =
+ sk_make_sp<SkShadowPaintFilterCanvas>(surf->getCanvas());
+
+ // set the depth map canvas to have the light we're drawing.
+ SkLights::Builder builder;
+ builder.add(fLights->light(i));
+ sk_sp<SkLights> curLight = builder.finish();
+ depthMapCanvas->setLights(curLight);
+
+ depthMapCanvas->drawPicture(picture);
+ sk_sp<SkImage> depthMap = surf->makeImageSnapshot();
+
+ // we blur the variance map
+ SkPaint paint2;
+ paint2.setImageFilter(SkBlurImageFilter::Make(2.0f, 2.0f, nullptr));
+
+ SkImageInfo info2 = SkImageInfo::Make(picture->cullRect().width(),
+ picture->cullRect().height(),
+ kBGRA_8888_SkColorType,
+ kOpaque_SkAlphaType);
+
+ sk_sp<SkSurface> surf2(this->makeSurface(info2));
+ sk_sp<SkCanvas> depthMapCanvas2 = sk_ref_sp(surf2->getCanvas());
+
+ depthMapCanvas2->drawImage(depthMap, 0, 0, &paint2);
+
+ fLights->light(i).setShadowMap(surf2->makeImageSnapshot());
+ }
+
SkPaint shadowPaint;
sk_sp<SkShader> povDepthShader = povDepthMap->makeShader(SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode);
-
sk_sp<SkShader> diffuseShader = diffuseMap->makeShader(SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode);
-
sk_sp<SkShader> shadowShader = SkShadowShader::Make(std::move(povDepthShader),
std::move(diffuseShader),
std::move(fLights),

Powered by Google App Engine
This is Rietveld 408576698