-
Notifications
You must be signed in to change notification settings - Fork 18
/
WvN.DelphiShader.FX.AngelicParticles2.pas
135 lines (102 loc) · 2.8 KB
/
WvN.DelphiShader.FX.AngelicParticles2.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
unit WvN.DelphiShader.FX.AngelicParticles2;
interface
uses GR32, Types, WvN.DelphiShader.Shader;
type
TAngelicParticles2 = class(TShader)
const
STEPS = 60;
vec3_2: vec3 = (x: 0.9; y: 0.3; z: 0.1);
vec3_3: vec3 = (x: 1.2; y: 1.2; z: 1.2);
var
ray : vec3;
function rotate(const p: vec2; a: float): vec2;
function Main(var gl_FragCoord: vec2): TColor32;
constructor Create; override;
procedure PrepareFrame;
end;
var
AngelicParticles2: TShader;
implementation
uses SysUtils, Math;
constructor TAngelicParticles2.Create;
begin
inherited;
Image.FrameProc := PrepareFrame;
Image.PixelProc := Main;
end;
function TAngelicParticles2.rotate(const p: vec2; a: float): vec2;
var sa,ca:double;
begin
sa := system.Sin(a);
ca := system.Cos(a);
Result := vec2.Create(
p.x * ca - p.y * sa,
p.x * sa + p.y * ca
);
end;
procedure TAngelicParticles2.PrepareFrame;
begin
// by srtuss, 2013
// did some research on kali's "comsos" and came up with this.
// as always, not optimized, just pretty :)
//
// name & inspiration was taken from here:
// http://www.youtube.com/watch?v=BzQmeeXcDwQ
ray := vec3.Create(
sinLarge(iGlobalTime * 0.1) * 0.2,
cosLarge(iGlobalTime * 0.13) * 0.2, 1.5);
end;
function TAngelicParticles2.Main(var gl_FragCoord: vec2): TColor32;
var
uv : vec2;
v : float;
dir : vec3;
inc : float;
acc : vec3;
i, j: integer;
p : vec3;
it : float;
br : float;
col : vec3;
dp:float;
begin
uv := gl_FragCoord.xy / resolution.xy;
uv := uv * 2 - 1;
uv.x := uv.x * (resolution.x / resolution.y);
v := 0;
dir := vec3.Create(uv, 1);
dir.NormalizeSelf;
ray.z := ray.z + (iGlobalTime * 0.1 - 20);
dir.xz := rotate(dir.xz, sinLarge(iGlobalTime * 0.1) * 2);
dir.xy := rotate(dir.xy, iGlobalTime * 0.2);
// very little steps for the sake of a good framerate
inc := 0.35 / STEPS;
acc := vec3Black;
for i := 0 to STEPS - 1 do
begin
p := ray * 0.1;
// fractal from "cosmos"
for j := 0 to 13 do
begin
dp := dot(p, p) * 0.5;
p.x := abs(p.x) / dp - 1;
p.y := abs(p.y) / dp - 1;
p.z := abs(p.z) / dp - 1;
end;
it := 0.001 * length(p * p);
v := v + it;
// cheap coloring
acc := acc + system.sqrt(it) * texture2D(tex[8], ray.xy * 0.1 + ray.z * 0.1).rgb;
ray := ray + dir * inc;
end;
br := pow(v * 4, 3) ;
col := pow(acc * 0.5, vec3_3) + br;
col := col * 2 - 1;
Result := TColor32(col);
end;
initialization
AngelicParticles2 := TAngelicParticles2.Create;
Shaders.Add('AngelicParticles2', AngelicParticles2);
finalization
FreeandNil(AngelicParticles2);
end.