-
Notifications
You must be signed in to change notification settings - Fork 2
/
ChromaticAberration.uno
94 lines (85 loc) · 1.71 KB
/
ChromaticAberration.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
using Uno;
using Uno.Graphics;
using Uno.UX;
using Fuse.Effects;
using Fuse;
public sealed class ChromaticAberration : BasicEffect
{
float2 _offsetR;
float2 _offsetG;
float2 _offsetB;
public float2 OffsetR
{
get
{
return _offsetR;
}
set
{
if(value != _offsetR)
{
_offsetR = value;
OnRenderingChanged();
}
}
}
public float2 OffsetG
{
get
{
return _offsetG;
}
set
{
if(value != _offsetG)
{
_offsetG = value;
OnRenderingChanged();
}
}
}
public float2 OffsetB
{
get
{
return _offsetB;
}
set
{
if(value != _offsetB)
{
_offsetB = value;
OnRenderingChanged();
}
}
}
public ChromaticAberration() : 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;
float2 texelSize: 1.0f/Size;
float2 uv2: float2(TexCoord.X, 1 - TexCoord.Y);
float2 offsetR: _offsetR * texelSize;
float2 offsetG: _offsetG * texelSize;
float2 offsetB: _offsetB * texelSize;
float4 r: sample(Texture, TexCoord+offsetR, Uno.Graphics.SamplerState.LinearClamp);
float4 g: sample(Texture, TexCoord+offsetG, Uno.Graphics.SamplerState.LinearClamp);
float4 b: sample(Texture, TexCoord+offsetB, Uno.Graphics.SamplerState.LinearClamp);
float4 a: sample(Texture, TexCoord, Uno.Graphics.SamplerState.LinearClamp);
PixelColor: float4(r.X, g.Y, b.Z, a.W);
};
FramebufferPool.Release(original);
}
}