浏览代码

fast shadow version 1.0

/main
xingwei.zhu 5 年前
当前提交
f50d1240
共有 7 个文件被更改,包括 47 次插入34 次删除
  1. 15
      Runtime/ui/geometry.cs
  2. 22
      Runtime/ui/painting/path.cs
  3. 12
      Runtime/ui/painting/shadow_utils.cs
  4. 8
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs
  5. 3
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shadow_utils.cs
  6. 13
      Runtime/ui/renderer/common/geometry/path/path.cs
  7. 8
      Runtime/ui/renderer/common/geometry/path/path_extension.cs

15
Runtime/ui/geometry.cs


get { return this.brRadius.y; }
}
public bool isNaiveRRect {
get {
var radius = this.tlRadiusX;
return this.tlRadiusY == radius &&
this.trRadiusX == radius &&
this.trRadiusY == radius &&
this.blRadiusX == radius &&
this.blRadiusY == radius &&
this.brRadiusX == radius &&
this.brRadiusY == radius &&
radius <= this.width / 2 &&
radius <= this.height / 2;
}
}
public static readonly RRect zero = new RRect(0, 0, 0, 0, (Radius) null);
public RRect shift(Offset offset) {

22
Runtime/ui/painting/path.cs


PathShapeHint _shapeHint = PathShapeHint.Other;
public PathShapeHint shapeHint => this._shapeHint;
float _rCorner;
public float rCorner => this._rCorner;
public uint pathKey {
get {
return this._pathKey;

public List<float> commands => this._commands;
void _updateRRectFlag(bool isRRect, PathShapeHint shapeHint = PathShapeHint.Other) {
void _updateRRectFlag(bool isRRect, PathShapeHint shapeHint = PathShapeHint.Other, float corner = 0) {
this._shapeHint = shapeHint;
if (this._isRRect) {
this._shapeHint = shapeHint;
this._rCorner = corner;
}
}
bool _hasOnlyMoveTos() {

}
public void addRRect(RRect rrect) {
this._updateRRectFlag(true, PathShapeHint.RRect);
this._updateRRectFlag(rrect.isNaiveRRect, PathShapeHint.NaiveRRect, rrect.blRadiusX);
float w = rrect.width;
float h = rrect.height;
float halfw = Mathf.Abs(w) * 0.5f;

}
public void addEllipse(float cx, float cy, float rx, float ry) {
this._updateRRectFlag(true, PathShapeHint.Oval);
this._updateRRectFlag(rx == ry, PathShapeHint.Circle, rx);
this._appendMoveTo(cx - rx, cy);
this._appendBezierTo(cx - rx, cy + ry * _KAPPA90,
cx - rx * _KAPPA90, cy + ry, cx, cy + ry);

}
public void addCircle(float cx, float cy, float r) {
this._updateRRectFlag(true, PathShapeHint.Oval);
this._updateRRectFlag(true, PathShapeHint.Oval);
var center = oval.center;
this.addEllipse(center.dx, center.dy, oval.width / 2, oval.height / 2);
}

public void addPath(Path path, Matrix3 transform = null) {
D.assert(path != null);
this._updateRRectFlag(path.isRRect, path.shapeHint);
this._updateRRectFlag(path.isRRect, path.shapeHint, path.rCorner);
var i = 0;
while (i < path._commands.Count) {
var cmd = (PathCommand) path._commands[i];

public enum PathShapeHint {
Rect,
Oval,
RRect,
Circle,
NaiveRRect,
Other
}

12
Runtime/ui/painting/shadow_utils.cs


}
//ambient light
_devSpacePath.resetAll();
_devSpacePath.addPath(path, viewMatrix);
float devSpaceOutset = ambientBlurRadius(zPlaneParams.z);
float oneOverA = ambientRecipAlpha(zPlaneParams.z);
float blurRadius = 0.5f * devSpaceOutset * oneOverA;

_shadowPaint.strokeWidth = strokeWidth;
_shadowPaint.style = PaintingStyle.fill;
canvas.save();
_shadowMatrix.reset();
canvas.setMatrix(_shadowMatrix);
float sigma = convertRadiusToSigma(blurRadius);
_shadowPaint.maskFilter = _devSpacePath.isRRect ? MaskFilter.fastShadow(sigma) : MaskFilter.blur(BlurStyle.normal, sigma);
//canvas.drawPath(_devSpacePath, _shadowPaint);
canvas.restore();
canvas.drawPath(path, _shadowPaint);
if (!getSpotShadowTransform(devLightPos, lightRadius, viewMatrix, zPlaneParams, path.getBounds(),
_shadowMatrix, ref radius)) {
return;

8
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader.cs


);
}
public static PictureFlusher.CmdDraw fastShadow(PictureFlusher.RenderLayer layer, uiMeshMesh mesh,
bool isRect, Vector4 bound, uiColor color) {
public static PictureFlusher.CmdDraw fastShadow(PictureFlusher.RenderLayer layer, uiMeshMesh mesh, float sigma,
bool isRect, bool isCircle, float corner, Vector4 bound, uiColor color) {
Vector4 viewport = layer.viewport;
var mat = _shadowBox;
if (!isRect) {

//use props to set all the uniforms !!!!!
var props = ObjectPool<MaterialPropertyBlockWrapper>.alloc();
props.SetVector(_viewportId, viewport);
props.SetFloat(_shadowSigmaId, 3f);
props.SetFloat(_shadowSigmaId, sigma);
props.SetFloat(_shadowCornerId, 30f);
props.SetFloat(_shadowCornerId, corner);
}
return PictureFlusher.CmdDraw.create(

3
Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shadow_utils.cs


var layer = this._currentLayer;
var state = layer.currentState;
float sigma = state.scale * paint.maskFilter.Value.sigma;
var vertices = ObjectPool<uiList<Vector3>>.alloc();
vertices.SetCapacity(4);

_triangles.Add(3);
var mesh = uiMeshMesh.create(state.matrix, vertices, _triangles);
layer.draws.Add(CanvasShader.fastShadow(layer, mesh, path.isRect, new Vector4(bound.left, bound.top, bound.right, bound.bottom), paint.color));
layer.draws.Add(CanvasShader.fastShadow(layer, mesh, sigma, path.isRect, path.isCircle, path.rCorner, new Vector4(bound.left, bound.top, bound.right, bound.bottom), paint.color));
}
}

13
Runtime/ui/renderer/common/geometry/path/path.cs


uiPathShapeHint _shapeHint = uiPathShapeHint.Other;
public uiPathShapeHint shapeHint => this._shapeHint;
void _updateRRectFlag(bool isRRect, uiPathShapeHint shapeHint = uiPathShapeHint.Other) {
float _rCorner;
public float rCorner => this._rCorner;
void _updateRRectFlag(bool isRRect, uiPathShapeHint shapeHint = uiPathShapeHint.Other, float corner = 0) {
if (this._commands.Count > 0 && !this._isRRect) {
return;
}

this._rCorner = corner;
}
}

}
public void addRRect(RRect rrect) {
this._updateRRectFlag(true, uiPathShapeHint.RRect);
this._updateRRectFlag(rrect.isNaiveRRect, uiPathShapeHint.NaiveRRect, rrect.blRadiusX);
float w = rrect.width;
float h = rrect.height;
float halfw = Mathf.Abs(w) * 0.5f;

}
public void addEllipse(float cx, float cy, float rx, float ry) {
this._updateRRectFlag(true, uiPathShapeHint.Oval);
this._updateRRectFlag(rx == ry, uiPathShapeHint.Circle, rx);
this._appendMoveTo(cx - rx, cy);
this._appendBezierTo(cx - rx, cy + ry * _KAPPA90,
cx - rx * _KAPPA90, cy + ry, cx, cy + ry);

}
public void addCircle(float cx, float cy, float r) {
this._updateRRectFlag(true, uiPathShapeHint.Oval);
this.addEllipse(cx, cy, r, r);
}

return uipath;
}
uipath._updateRRectFlag(path.isRRect, (uiPathShapeHint)path.shapeHint);
uipath._updateRRectFlag(path.isRRect, (uiPathShapeHint)path.shapeHint, path.rCorner);
var i = 0;
var _commands = path.commands;

8
Runtime/ui/renderer/common/geometry/path/path_extension.cs


public enum uiPathShapeHint {
Rect,
Oval,
RRect,
Circle,
NaiveRRect,
Other
}

public bool isOval {
get { return this._shapeHint == uiPathShapeHint.Oval; }
public bool isCircle {
get { return this._shapeHint == uiPathShapeHint.Circle; }
}
}
}
正在加载...
取消
保存