浏览代码

add drawShadowFast

/main
xingwei.zhu 5 年前
当前提交
05ab139c
共有 1 个文件被更改,包括 2 次插入35 次删除
  1. 37
      Runtime/ui/painting/shadow_utils.cs

37
Runtime/ui/painting/shadow_utils.cs


public static void drawShadow(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
float lightRadius, uiColor ambientColor, uiColor spotColor, int flags) {
if (kUseFastShadow) {
drawShadowFull2(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags);
drawShadowFast(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags);
}
else {
drawShadowFull(canvas, path, zPlaneParams, devLightPos, lightRadius, ambientColor, spotColor, flags);

}
static void drawShadowFull2(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
static void drawShadowFast(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
float lightRadius, uiColor ambientColor, uiColor spotColor, int flags) {
Matrix3 viewMatrix = canvas.getTotalMatrix();

canvas.restore();
_shadowPaint.maskFilter = null;
}
static void drawShadowFast(Canvas canvas, Path path, Vector3 zPlaneParams, Vector3 devLightPos,
float lightRadius, uiColor ambientColor, uiColor spotColor, int flags) {
Matrix3 viewMatrix = canvas.getTotalMatrix();
//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;
canvas.drawPath(path, _shadowPaint);
canvas.restore();
}
/*

正在加载...
取消
保存