-
Notifications
You must be signed in to change notification settings - Fork 18
/
WvN.DelphiShader.FX.FlagUK.pas
94 lines (70 loc) · 1.59 KB
/
WvN.DelphiShader.FX.FlagUK.pas
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
unit WvN.DelphiShader.FX.FlagUK;
interface
uses GR32, Types, WvN.DelphiShader.Shader;
type
TFlagUK = class(TShader)
ripple :float;
rippleSpeed :float;
rippleSize :float;
function Main(var gl_FragCoord: Vec2): TColor32;
constructor Create; override;
procedure PrepareFrame;
end;
var
FlagUK: TShader;
implementation
uses SysUtils, Math;
constructor TFlagUK.Create;
begin
inherited;
FrameProc := PrepareFrame;
PixelProc := Main;
end;
procedure TFlagUK.PrepareFrame;
begin
ripple := 7.0;
rippleSpeed := 0.5;
rippleSize := 0.05;
end;
function TFlagUK.main;
var
p :vec2;
d :float;
kRed :vec3;
kBlue :vec3;
begin
p := ( gl_FragCoord.xy / resolution.xy ) * 2.0 - 1.0;
p.y := p.y + (rippleSize * system.sin(ripple * (p.x + time * rippleSpeed)));
d := -p.x * Math.sign(p.y) + p.y * Math.sign(p.x);
kRed := vec3.Create( 204.0 / 255.0,0,0 );
kBlue := vec3.Create( 0.0,0.0,102.0 / 255.0 );
if (System.Abs(p.x) < (6.0/60.0)) or (System.Abs(p.y) < (6.0/30.0)) then
begin
Result := TColor32(kRed);
end
else
if (System.Abs(p.x) < (10.0/60.0)) or (System.Abs(p.y) < (10.0/30.0)) then
begin
Result := clWhite32;
end
else
if (d > 0) and (d < 0.15) then
begin
Result := TColor32(kRed);
end
else
if (d > -0.15 * 3.0 / 2.0) and (d < 0.15 * 3.0 /2.0) then
begin
Result := clWhite32;
end
else
begin
Result := TColor32(kBlue);
end;
end;
initialization
FlagUK := TFlagUK.Create;
Shaders.Add('FlagUK', FlagUK);
finalization
FreeandNil(FlagUK);
end.