static void drawShadowFull(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos, float lightRadius, uiColor ambientColor, uiColor spotColor, int flags) { Matrix3 viewMatrix = canvas.getTotalMatrix(); //ambient light _devSpacePath.resetAll(); _devSpacePath.addPath(path, viewMatrix); float devSpaceOutset = ambientBlurRadius(zPlaneParams.z); float oneOverA = ambientRecipAlpha(zPlaneParams.z); float blurRadius = 0.5f * devSpaceOutset * oneOverA; float strokeWidth = 0.5f * (devSpaceOutset - blurRadius); //Paint paint = new Paint {color = ambientColor, strokeWidth = strokeWidth, style = PaintingStyle.fill}; _shadowPaint.color = new Color(ambientColor.value); _shadowPaint.strokeWidth = strokeWidth; _shadowPaint.style = PaintingStyle.fill; canvas.save(); _shadowMatrix.reset(); canvas.setMatrix(_shadowMatrix); float sigma = convertRadiusToSigma(blurRadius); _shadowPaint.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma); canvas.drawPath(_devSpacePath, _shadowPaint); canvas.restore(); //spot light //Matrix3 shadowMatrix = Matrix3.I(); float radius = 0.0f; if (!getSpotShadowTransform(devLightPos, lightRadius, viewMatrix, zPlaneParams, path.getBounds(), _shadowMatrix, ref radius)) { return; } canvas.save(); canvas.setMatrix(_shadowMatrix); _shadowPaint.color = new Color(spotColor.value); _shadowPaint.strokeWidth = 0; _shadowPaint.style = PaintingStyle.fill; float sigma2 = convertRadiusToSigma(radius); _shadowPaint.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma2); canvas.drawPath(path, _shadowPaint); canvas.restore(); _shadowPaint.maskFilter = null; }
public static void drawShadow(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos, float lightRadius, Color ambientColor, Color spotColor, int flags) { if (!_drawShadowFlag) { return; } Matrix3 viewMatrix = canvas.getTotalMatrix(); //ambient light Path devSpacePath = path.transform(viewMatrix); float devSpaceOutset = ambientBlurRadius(zPlaneParams.z); float oneOverA = ambientRecipAlpha(zPlaneParams.z); float blurRadius = 0.5f * devSpaceOutset * oneOverA; float strokeWidth = 0.5f * (devSpaceOutset - blurRadius); Paint paint = new Paint { color = ambientColor, strokeWidth = strokeWidth, style = PaintingStyle.fill }; canvas.save(); canvas.setMatrix(Matrix3.I()); float sigma = convertRadiusToSigma(blurRadius); paint.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma); canvas.drawPath(devSpacePath, paint); canvas.restore(); //spot light Matrix3 shadowMatrix = Matrix3.I(); float radius = 0.0f; if (!getSpotShadowTransform(devLightPos, lightRadius, viewMatrix, zPlaneParams, path.getBounds(), shadowMatrix, ref radius)) { return; } canvas.save(); canvas.setMatrix(shadowMatrix); Paint paint2 = new Paint { color = spotColor }; float sigma2 = convertRadiusToSigma(radius); paint2.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma2); canvas.drawPath(path, paint2); canvas.restore(); }
static void drawShadowFast(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos, float lightRadius, uiColor ambientColor, uiColor spotColor, int flags) { Matrix3 viewMatrix = canvas.getTotalMatrix(); //debug shadow #pragma warning disable CS0162 if (debugShadow) { var isRRect = path.isNaiveRRect; if (isRRect) { ambientColor = uiColor.fromColor(Colors.red); spotColor = uiColor.fromColor(Colors.red); } else { ambientColor = uiColor.fromColor(Colors.green); spotColor = uiColor.fromColor(Colors.green); } } #pragma warning restore CS0162 //ambient light float devSpaceOutset = ambientBlurRadius(zPlaneParams.z); float oneOverA = ambientRecipAlpha(zPlaneParams.z); float blurRadius = 0.5f * devSpaceOutset * oneOverA; float strokeWidth = 0.5f * (devSpaceOutset - blurRadius); _shadowPaint.color = new Color(ambientColor.value); _shadowPaint.strokeWidth = strokeWidth; _shadowPaint.style = PaintingStyle.fill; canvas.drawPath(path, _shadowPaint); //spot light float radius = 0.0f; if (!getSpotShadowTransform(devLightPos, lightRadius, viewMatrix, zPlaneParams, path.getBounds(), _shadowMatrix, ref radius)) { return; } canvas.save(); canvas.setMatrix(_shadowMatrix); _shadowPaint.color = new Color(spotColor.value); _shadowPaint.strokeWidth = 0; _shadowPaint.style = PaintingStyle.fill; float sigma2 = convertRadiusToSigma(radius); _shadowPaint.maskFilter = path.isNaiveRRect ? MaskFilter.fastShadow(sigma2) : MaskFilter.blur(BlurStyle.normal, sigma2); canvas.drawPath(path, _shadowPaint); canvas.restore(); _shadowPaint.maskFilter = null; }