|
|
|
|
|
|
|
|
|
|
namespace Unity.UIWidgets.ui { |
|
|
|
static class ShadowUtils { |
|
|
|
public const bool kUseFastShadow = true; |
|
|
|
public const bool kUseFastShadow = false; |
|
|
|
|
|
|
|
public const float kAmbientHeightFactor = 1.0f / 128.0f; |
|
|
|
public const float kAmbientGeomFactor = 64.0f; |
|
|
|
|
|
|
return radius > 0 ? kBlurSigmaScale * radius + 0.5f : 0.0f; |
|
|
|
} |
|
|
|
|
|
|
|
public static void computeTonalColors(Color inAmbientColor, Color inSpotColor, |
|
|
|
ref Color outAmbientColor, ref Color outSpotColor) { |
|
|
|
outAmbientColor = Color.fromARGB(inAmbientColor.alpha, 0, 0, 0); |
|
|
|
public static void computeTonalColors(uiColor inAmbientColor, uiColor inSpotColor, |
|
|
|
ref uiColor? outAmbientColor, ref uiColor? outSpotColor) { |
|
|
|
outAmbientColor = uiColor.fromARGB(inAmbientColor.alpha, 0, 0, 0); |
|
|
|
outSpotColor = inSpotColor; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public static void drawShadow(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos, |
|
|
|
float lightRadius, Color ambientColor, Color spotColor, int flags) { |
|
|
|
float lightRadius, uiColor ambientColor, uiColor spotColor, int flags) { |
|
|
|
if (kUseFastShadow) { |
|
|
|
drawShadowFast(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags); |
|
|
|
} |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//cached variables
|
|
|
|
static readonly Paint _shadowPaint = new Paint(); |
|
|
|
static readonly Matrix3 _shadowMatrix = Matrix3.I(); |
|
|
|
float lightRadius, Color ambientColor, Color spotColor, int flags) { |
|
|
|
float lightRadius, uiColor ambientColor, uiColor spotColor, int flags) { |
|
|
|
Matrix3 viewMatrix = canvas.getTotalMatrix(); |
|
|
|
|
|
|
|
//ambient light
|
|
|
|
|
|
|
float blurRadius = 0.5f * devSpaceOutset * oneOverA; |
|
|
|
float strokeWidth = 0.5f * (devSpaceOutset - blurRadius); |
|
|
|
|
|
|
|
Paint paint = new Paint {color = ambientColor, strokeWidth = strokeWidth, style = PaintingStyle.fill}; |
|
|
|
|
|
|
|
//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.setMatrix(Matrix3.I()); |
|
|
|
_shadowMatrix.reset(); |
|
|
|
canvas.setMatrix(_shadowMatrix); |
|
|
|
paint.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma); |
|
|
|
canvas.drawPath(devSpacePath, paint); |
|
|
|
_shadowPaint.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma); |
|
|
|
canvas.drawPath(devSpacePath, _shadowPaint); |
|
|
|
Matrix3 shadowMatrix = Matrix3.I(); |
|
|
|
//Matrix3 shadowMatrix = Matrix3.I();
|
|
|
|
shadowMatrix, ref radius)) { |
|
|
|
_shadowMatrix, ref radius)) { |
|
|
|
canvas.setMatrix(shadowMatrix); |
|
|
|
Paint paint2 = new Paint {color = spotColor}; |
|
|
|
canvas.setMatrix(_shadowMatrix); |
|
|
|
|
|
|
|
_shadowPaint.color = new Color(spotColor.value); |
|
|
|
_shadowPaint.strokeWidth = 0; |
|
|
|
_shadowPaint.style = PaintingStyle.fill; |
|
|
|
paint2.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma2); |
|
|
|
canvas.drawPath(path, paint2); |
|
|
|
_shadowPaint.maskFilter = MaskFilter.blur(BlurStyle.normal, sigma2); |
|
|
|
canvas.drawPath(path, _shadowPaint); |
|
|
|
|
|
|
|
_shadowPaint.maskFilter = null; |
|
|
|
float lightRadius, Color ambientColor, Color spotColor, int flags) { |
|
|
|
float lightRadius, uiColor ambientColor, uiColor spotColor, int flags) { |
|
|
|
Matrix3 viewMatrix = canvas.getTotalMatrix(); |
|
|
|
|
|
|
|
//ambient light
|
|
|
|
|
|
|
float strokeWidth = 0.5f * (devSpaceOutset - blurRadius); |
|
|
|
|
|
|
|
Paint paint = new Paint {color = ambientColor, strokeWidth = strokeWidth, style = PaintingStyle.fill}; |
|
|
|
canvas.drawPath(path, paint); |
|
|
|
//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.drawPath(path, _shadowPaint); |
|
|
|
Matrix3 shadowMatrix = Matrix3.I(); |
|
|
|
shadowMatrix, ref radius)) { |
|
|
|
_shadowMatrix, ref radius)) { |
|
|
|
canvas.setMatrix(shadowMatrix); |
|
|
|
Paint paint2 = new Paint {color = spotColor}; |
|
|
|
canvas.drawPath(path, paint2); |
|
|
|
canvas.setMatrix(_shadowMatrix); |
|
|
|
//Paint paint2 = new Paint {color = spotColor};
|
|
|
|
_shadowPaint.color = new Color(spotColor.value); |
|
|
|
_shadowPaint.strokeWidth = 0; |
|
|
|
_shadowPaint.style = PaintingStyle.fill; |
|
|
|
canvas.drawPath(path, _shadowPaint); |
|
|
|
|
|
|
|
canvas.restore(); |
|
|
|
} |