-
Notifications
You must be signed in to change notification settings - Fork 18
/
WvN.DelphiShader.FX.Circles.pas
120 lines (95 loc) · 3.26 KB
/
WvN.DelphiShader.FX.Circles.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
unit WvN.DelphiShader.FX.Circles;
interface
uses GR32, Types, WvN.DelphiShader.Shader;
type
TCircles = class(TShader)
const
vec3_1:vec3=(x:0.7;y:0.2;z:0.8);
vec2_2:vec2=(x:0.30;y:0.70);
vec2_3:vec2=(x:0.6;y:0.6);
vec3_4:vec3=(x:0.7;y:0.9;z:0.6);
vec2_5:vec2=(x:0.02;y:0.20);
vec2_6:vec2=(x:0.1;y:0.1);
vec3_7:vec3=(x:0.3;y:0.4;z:0.1);
vec2_8:vec2=(x:0.10;y:0.04);
vec2_9:vec2=(x:0.1;y:0.1);
vec3_10:vec3=(x:0.2;y:0.5;z:0.1);
vec2_11:vec2=(x:0.10;y:0.20);
vec2_12:vec2=(x:0.3;y:0.3);
vec3_13:vec3=(x:0.1;y:0.3;z:0.7);
vec2_14:vec2=(x:0.40;y:0.25);
vec2_15:vec2=(x:0.2;y:0.2);
vec3_16:vec3=(x:0.9;y:0.4;z:0.2);
vec2_17:vec2=(x:0.15;y:0.20);
vec2_18:vec2=(x:0;y:0);
var
pos : vec2;
aspect :float;
color:vec3;
c_ar: array[0..5] of vec2;
function center ( const border , offset , vel :vec2 ):vec2;
procedure circle ( index:integer; r :float;const col :vec3 );
function Main(var gl_FragCoord: Vec2): TColor32;
constructor Create; override;
procedure PrepareFrame;
end;
var
Circles: TShader;
implementation
uses SysUtils, Math;
constructor TCircles.Create;
begin
inherited;
FrameProc := PrepareFrame;
PixelProc := Main;
end;
procedure TCircles.PrepareFrame;
const r_ar:array[0..5] of double=(0.03,0.05,0.07,0.10,0.20,0.30);
begin
aspect := resolution.x / resolution.y;
c_ar[0] := center( vec2.create( r_ar[0] / aspect , r_ar[0] ) , vec2_3 , vec2_2 ); c_ar[0].x := c_ar[0].x * aspect;
c_ar[1] := center( vec2.create( r_ar[1] / aspect , r_ar[1] ) , vec2_6 , vec2_5 ); c_ar[1].x := c_ar[1].x * aspect;
c_ar[2] := center( vec2.create( r_ar[2] / aspect , r_ar[2] ) , vec2_9 , vec2_8 ); c_ar[2].x := c_ar[2].x * aspect;
c_ar[3] := center( vec2.create( r_ar[3] / aspect , r_ar[3] ) , vec2_12 , vec2_11); c_ar[3].x := c_ar[3].x * aspect;
c_ar[4] := center( vec2.create( r_ar[4] / aspect , r_ar[4] ) , vec2_15 , vec2_14); c_ar[4].x := c_ar[4].x * aspect;
c_ar[5] := center( vec2.create( r_ar[5] / aspect , r_ar[5] ) , vec2_18 , vec2_17); c_ar[5].x := c_ar[5].x * aspect;
end;
function TCircles.center ( const border , offset , vel :vec2 ):vec2;
var
c :vec2;
begin
c := offset + vel * time;
c := &mod ( c , 2 - 4 * border );
if c.x > 1 - border.x then c.x := 2 - c.x - 2 * border.x;
if c.x < border.x then c.x := 2 * border.x - c.x;
if c.y > 1 - border.y then c.y := 2 - c.y - 2 * border.y;
if c.y < border.y then c.y := 2 * border.y - c.y;
Result := c;
end;
procedure TCircles.circle ( index:integer; r :float;const col :vec3 );
var
c :vec2;
d :float;
begin
c := c_ar[index];
d := distance ( pos , c );
color := color + col * ( ifthen( d < r , 0.5 , max( 0.8 - min( pow ( d - r , 0.3 ) , 0.9 ) , -0.2 )) );
end;
function TCircles.Main(var gl_FragCoord: Vec2): TColor32;
begin
color := vec3Black;
pos := gl_FragCoord.xy / resolution.y;
circle (0, 0.03 , vec3_1 );
circle (1, 0.05 , vec3_4 );
circle (2, 0.07 , vec3_7 );
circle (3, 0.10 , vec3_10 );
circle (4, 0.20 , vec3_13 );
circle (5, 0.30 , vec3_16 );
Result := TColor32( color );
end;
initialization
Circles := TCircles.Create;
Shaders.Add('Circles', Circles);
finalization
FreeandNil(Circles);
end.