-
Notifications
You must be signed in to change notification settings - Fork 2
/
CircularMask.uno
104 lines (95 loc) · 1.93 KB
/
CircularMask.uno
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using Uno;
using Uno.Graphics;
using Uno.UX;
using Fuse.Effects;
using Fuse;
using Uno.Math;
public sealed class CircularMask : BasicEffect
{
float2 _pos;
public float2 Position{
get{
return _pos;
}
set{
if(value==_pos)return;
_pos = value;
OnRenderingChanged();
}
}
float _softness = 0.001f;
public float EdgeSoftness
{
get{
return _softness;
}
set{
if(value==_softness)return;
_softness = value;
OnRenderingChanged();
}
}
bool _ignoreAspect = true;
public bool IgnoreAspect{
get{
return _ignoreAspect;
}
set{
if(value==_ignoreAspect)return;
_ignoreAspect = value;
OnRenderingChanged();
}
}
bool _cutout;
public bool Cutout{
get{
return _cutout;
}
set{
if(value==_cutout)return;
_cutout = value;
OnRenderingChanged();
}
}
float _radius = 0.0f;
public float Radius
{
get {
return _radius;
}
set{
if(value==_radius)return;
_radius = value;
OnRenderingChanged();
}
}
public CircularMask() : base(EffectType.Composition)
{
}
protected override void OnRender(DrawContext dc, Rect elementRect)
{
var original = Element.CaptureRegion(dc, elementRect, int2(0));
if (original == null)
return;
draw Fuse.Drawing.Planar.Image
{
DrawContext: dc;
Visual: Element;
Position: elementRect.Minimum;
Invert: true;
Size: elementRect.Size;
Texture: original.ColorBuffer;
TextureColor: prev TextureColor;
float2 uv2: pixel float2(TexCoord.X, 1 - TexCoord.Y);
float aspect: _ignoreAspect ? 1.0f : Size.Y / Size.X;
float2 uv3: float2(uv2.X, uv2.Y * aspect);
float2 p: float2(_pos.X, _pos.Y * aspect);
float2 diff: uv3 - p;
float dist: Sqrt(diff.X * diff.X + diff.Y * diff.Y);
float step: SmoothStep(_radius - _softness * 0.5f, _radius + _softness * 0.5f, dist);
float a: _cutout ? step : 1.0f - step;
PixelColor: float4(TextureColor.XYZ, TextureColor.W * a);
};
FramebufferPool.Release(original);
}
}