-
Notifications
You must be signed in to change notification settings - Fork 18
/
WvN.DelphiShader.FX.Fly.pas
67 lines (49 loc) · 1.28 KB
/
WvN.DelphiShader.FX.Fly.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
unit WvN.DelphiShader.FX.Fly;
interface
uses GR32, Types, WvN.DelphiShader.Shader;
type
TFly=class(TShader)
an,san,can:Double;
constructor Create;override;
procedure PrepareFrame;
function RenderPixel(var gl_FragCoord:Vec2): TColor32;
end;
var
Fly:TShader;
implementation
uses SysUtils, Math;
constructor TFly.Create;
begin
inherited;
// LoadTexture(tex0,'C:\Users\Wouter\Documents\RAD Studio\Projects\tex2.jpg');
FrameProc := prepareFrame;
PixelProc := RenderPixel;
end;
procedure TFly.PrepareFrame;
begin
an := iGlobalTime * 0.25;
san := system.sin(an);
can := system.cos(an)
end;
function TFly.RenderPixel(var gl_FragCoord:Vec2): TColor32;
var
p : Vec2;
uv : vec2;
lx, ly : TVecType;
begin
p.x := -1.0 + 2.0 * gl_FragCoord.x / Resolution.x;
p.y := -1.0 + 2.0 * gl_FragCoord.y / Resolution.y;
lx := p.x * can - p.y * san;
ly := p.x * san + p.y * can;
if ly=0 then
Exit(clBlack32);
uv.x := 0.25 * lx / System.abs(ly);
uv.y := 0.20 * iGlobalTime + 0.25 / System.abs(ly);
Result := TColor32(vec4.Create(texture2D(tex[0], uv).xyz * ly * ly,1));
end;
initialization
Fly := TFly.Create;
Shaders.Add('Fly',Fly);
finalization
FreeandNil(Fly);
end.