Minor shadow fixes.

Fix inset value for analytic shadows to get full inset (and hence
proper falloff).
Fix compute_radial_values in tessellator to return only positive values
and produce cleaner arcs.
Adjust shadow params in Android sample to match Android.
Fix corner calculation for analytic shadow.

Bug: skia:7486
Change-Id: Ib393b5d577f5a5eb89d3388aa4726ea4dae37055
Reviewed-on: https://skia-review.googlesource.com/123220
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
Jim Van Verth 2018-04-23 17:14:48 -04:00 committed by Skia Commit-Bot
parent 058f2e6ed2
commit 4c8c1e8302
4 changed files with 16 additions and 8 deletions

View File

@ -206,8 +206,8 @@ protected:
void onDrawContent(SkCanvas* canvas) override {
this->drawBG(canvas);
const SkScalar kLightWidth = 800;
const SkScalar kAmbientAlpha = 0.1f;
const SkScalar kSpotAlpha = 0.25f;
const SkScalar kAmbientAlpha = 0.039f;
const SkScalar kSpotAlpha = 0.19f;
SkPaint paint;
paint.setAntiAlias(true);

View File

@ -1110,7 +1110,7 @@ bool GrRenderTargetContext::drawFastShadow(const GrClip& clip,
maxOffset = SkScalarSqrt(SkTMax(SkPointPriv::LengthSqd(upperLeftOffset),
SkPointPriv::LengthSqd(lowerRightOffset))) + dr;
}
insetWidth += maxOffset;
insetWidth += SkTMax(blurOutset, maxOffset);
}
// Outset the shadow rrect to the border of the penumbra

View File

@ -460,11 +460,19 @@ private:
// we also skew the vectors we send to the shader that help define the circle.
// By doing so, we end up with a quarter circle in the corner rather than the
// elliptical curve.
SkVector outerVec = SkVector::Make(0.5f*(outerRadius - umbraInset), -umbraInset);
// This is a bit magical, but it gives us the correct results at extrema:
// a) umbraInset == outerRadius produces an orthogonal vector
// b) outerRadius == 0 produces a diagonal vector
// And visually the corner looks correct.
SkVector outerVec = SkVector::Make(outerRadius - umbraInset, -outerRadius - umbraInset);
outerVec.normalize();
SkVector diagVec = SkVector::Make(outerVec.fX + outerVec.fY,
outerVec.fX + outerVec.fY);
diagVec *= umbraInset / (2 * umbraInset - outerRadius);
// We want the circle edge to fall fractionally along the diagonal at
// (sqrt(2)*(umbraInset - outerRadius) + outerRadius)/sqrt(2)*umbraInset
//
// Setting the components of the diagonal offset to the following value will give us that.
SkScalar diagVal = umbraInset / (SK_ScalarSqrt2*(outerRadius - umbraInset) - outerRadius);
SkVector diagVec = SkVector::Make(diagVal, diagVal);
SkScalar distanceCorrection = umbraInset / blurRadius;
SkScalar clampValue = args.fClampValue;

View File

@ -121,7 +121,7 @@ static void compute_radial_steps(const SkVector& v1, const SkVector& v2, SkScala
SkScalar rSin = v1.cross(v2);
SkScalar theta = SkScalarATan2(rSin, rCos);
int steps = SkScalarFloorToInt(r*theta*kRecipPixelsPerArcSegment);
int steps = SkScalarRoundToInt(SkScalarAbs(r*theta*kRecipPixelsPerArcSegment));
SkScalar dTheta = theta / steps;
*rotSin = SkScalarSinCos(dTheta, rotCos);