浏览代码

Merge pull request #268 from UnityTech/optmize_shadow

fix shadow clip bug
/main
GitHub 5 年前
当前提交
afc5823c
共有 1 个文件被更改,包括 37 次插入5 次删除
  1. 42
      Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shadow_utils.cs

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


void _drawRRectShadow(uiPath path, uiPaint paint) {
D.assert(path.isNaiveRRect, () => "Cannot draw fast Shadow for non-NaiveRRect shapes");
D.assert(paint.style == PaintingStyle.fill, () => "Cannot draw fast Shadow for stroke lines");
var bound = path.getBounds();
if (!this._applyClip(bound)) {
var layer = this._currentLayer;
var state = layer.currentState;
var cache = path.flatten(state.scale * this._devicePixelRatio);
bool convex;
var fillMesh = cache.getFillMesh(out convex);
var meshBounds = fillMesh.transform(state.matrix);
var clipBounds = layer.layerBounds;
uiRect? stackBounds;
bool iior;
layer.clipStack.getBounds(out stackBounds, out iior);
if (stackBounds != null) {
clipBounds = uiRectHelper.intersect(clipBounds, stackBounds.Value);
}
if (clipBounds.isEmpty) {
ObjectPool<uiMeshMesh>.release(meshBounds);
var layer = this._currentLayer;
var state = layer.currentState;
float sigma = state.scale * paint.maskFilter.Value.sigma;
var maskBounds = meshBounds.bounds;
maskBounds = uiRectHelper.intersect(maskBounds, clipBounds);
if (maskBounds.isEmpty) {
ObjectPool<uiMeshMesh>.release(meshBounds);
return;
}
var blurMesh = ImageMeshGenerator.imageMesh(null, uiRectHelper.one, maskBounds);
if (!this._applyClip(blurMesh.bounds)) {
ObjectPool<uiMeshMesh>.release(meshBounds);
ObjectPool<uiMeshMesh>.release(blurMesh);
return;
}
var bound = path.getBounds();
var sigma = state.scale * paint.maskFilter.Value.sigma;
var vertices = ObjectPool<uiList<Vector3>>.alloc();
vertices.SetCapacity(4);

_triangles.Add(1);
_triangles.Add(3);
ObjectPool<uiMeshMesh>.release(meshBounds);
ObjectPool<uiMeshMesh>.release(blurMesh);
var mesh = uiMeshMesh.create(state.matrix, vertices, _triangles);
layer.draws.Add(CanvasShader.fastShadow(layer, mesh, sigma, path.isRect, path.isCircle, path.rRectCorner, new Vector4(bound.left, bound.top, bound.right, bound.bottom), paint.color));
}

正在加载...
取消
保存