mondk commited on
Commit
d006177
·
verified ·
1 Parent(s): 243de13

Delete Loi_giai_Toan8.html

Browse files
Files changed (1) hide show
  1. Loi_giai_Toan8.html +0 -288
Loi_giai_Toan8.html DELETED
@@ -1,288 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1">
6
- <title>Black Hole</title>
7
- <style>
8
- html, body {
9
- margin: 0;
10
- padding: 0;
11
- width: 100%;
12
- height: 100%;
13
- overflow: hidden;
14
- background: #ffffff;
15
- }
16
- canvas { display: block; }
17
- </style>
18
- </head>
19
- <body>
20
- <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/build/three.min.js"></script>
21
- <script src="https://cdn.jsdelivr.net/npm/three@0.128.0/examples/js/controls/OrbitControls.js"></script>
22
- <script>
23
- (function () {
24
- 'use strict';
25
-
26
- /* ---------------- Renderer / Camera / Controls ---------------- */
27
-
28
- var renderer = new THREE.WebGLRenderer({ antialias: true, powerPreference: 'high-performance' });
29
- var resScale = Math.min(window.devicePixelRatio || 1, 1.5);
30
- renderer.setPixelRatio(resScale);
31
- renderer.setSize(window.innerWidth, window.innerHeight);
32
- renderer.setClearColor(0xffffff, 1);
33
- document.body.appendChild(renderer.domElement);
34
-
35
- var scene = new THREE.Scene();
36
-
37
- var camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 300);
38
- camera.position.set(0, 1.4, 15.5);
39
-
40
- var controls = new THREE.OrbitControls(camera, renderer.domElement);
41
- controls.target.set(0, 0, 0);
42
- controls.enableDamping = true;
43
- controls.dampingFactor = 0.08;
44
- controls.rotateSpeed = 0.55;
45
- controls.zoomSpeed = 0.9;
46
- controls.enablePan = false;
47
- controls.minDistance = 6.5;
48
- controls.maxDistance = 40;
49
- controls.minPolarAngle = 0.12;
50
- controls.maxPolarAngle = Math.PI - 0.12;
51
- // scroll wheel = zoom (default), right button = rotate, left button disabled
52
- controls.mouseButtons = { LEFT: -1, MIDDLE: THREE.MOUSE.DOLLY, RIGHT: THREE.MOUSE.ROTATE };
53
- controls.update();
54
-
55
- /* ---------------- Fullscreen geodesic ray-tracer ---------------- */
56
-
57
- var uniforms = {
58
- uTime: { value: 0 },
59
- uRes: { value: new THREE.Vector2(1, 1) },
60
- uCamPos: { value: new THREE.Vector3() },
61
- uCamMat: { value: new THREE.Matrix3() },
62
- uTanFov: { value: Math.tan(camera.fov * Math.PI / 360) }
63
- };
64
-
65
- var VERT = [
66
- 'void main(){',
67
- ' gl_Position = vec4(position.xy, 0.0, 1.0);',
68
- '}'
69
- ].join('\n');
70
-
71
- var FRAG = [
72
- 'uniform float uTime;',
73
- 'uniform vec2 uRes;',
74
- 'uniform vec3 uCamPos;',
75
- 'uniform mat3 uCamMat;',
76
- 'uniform float uTanFov;',
77
- '',
78
- 'const float DISK_IN = 2.6;', // inner edge (just outside shadow, rs = 1)
79
- 'const float DISK_OUT = 13.0;',
80
- 'const float ESC_R2 = 4900.0;',
81
- 'const float LOOP = 8.0;', // seamless loop period (animation repeats exactly)
82
- 'const int STEPS = 320;',
83
- '',
84
- 'float hash21(vec2 p){',
85
- ' p = fract(p * vec2(233.34, 851.73));',
86
- ' p += dot(p, p + 23.45);',
87
- ' return fract(p.x * p.y);',
88
- '}',
89
- 'float vnoise(vec2 p){',
90
- ' vec2 i = floor(p), f = fract(p);',
91
- ' f = f * f * (3.0 - 2.0 * f);',
92
- ' float a = hash21(i);',
93
- ' float b = hash21(i + vec2(1.0, 0.0));',
94
- ' float c = hash21(i + vec2(0.0, 1.0));',
95
- ' float d = hash21(i + vec2(1.0, 1.0));',
96
- ' return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);',
97
- '}',
98
- // value noise, periodic in x (so the disk texture wraps around seamlessly)
99
- 'float wnoise(vec2 p, float per){',
100
- ' vec2 i = floor(p), f = fract(p);',
101
- ' f = f * f * (3.0 - 2.0 * f);',
102
- ' float x0 = mod(i.x, per), x1 = mod(i.x + 1.0, per);',
103
- ' float a = hash21(vec2(x0, i.y));',
104
- ' float b = hash21(vec2(x1, i.y));',
105
- ' float c = hash21(vec2(x0, i.y + 1.0));',
106
- ' float d = hash21(vec2(x1, i.y + 1.0));',
107
- ' return mix(mix(a, b, f.x), mix(c, d, f.x), f.y);',
108
- '}',
109
- 'float diskFBM(float r, float ang, float seed){',
110
- ' vec2 p = vec2(ang * 0.7957747, r * 4.0 + seed);', // 5 cells around the circle
111
- ' float v = 0.0, a = 0.55, per = 5.0;',
112
- ' for(int i = 0; i < 4; i++){',
113
- ' v += a * wnoise(p, per);',
114
- ' p = vec2(p.x * 2.0, p.y * 2.0 + 17.7);',
115
- ' per *= 2.0; a *= 0.52;',
116
- ' }',
117
- ' return v;',
118
- '}',
119
- 'vec3 diskRamp(float t){',
120
- ' t = clamp(t, 0.0, 1.0);',
121
- ' vec3 c = mix(vec3(0.36, 0.07, 0.005), vec3(1.00, 0.42, 0.06), smoothstep(0.0, 0.30, t));',
122
- ' c = mix(c, vec3(1.00, 0.66, 0.22), smoothstep(0.30, 0.55, t));',
123
- ' c = mix(c, vec3(1.02, 0.88, 0.55), smoothstep(0.55, 0.80, t));',
124
- ' c = mix(c, vec3(1.05, 1.02, 0.95), smoothstep(0.80, 1.00, t));',
125
- ' return c;',
126
- '}',
127
- // accretion disk emission at hit point p, photon direction rdn
128
- 'vec3 diskShade(vec3 p, vec3 rdn, out float alpha){',
129
- ' float r = length(p.xz);',
130
- ' float phi = atan(p.z, p.x);',
131
- ' float prof = smoothstep(DISK_IN, DISK_IN + 0.12, r) * (1.0 - smoothstep(DISK_OUT - 4.0, DISK_OUT, r));',
132
- ' // Keplerian differential rotation as a perfectly seamless loop:',
133
- ' // two copies of the pattern advect continuously, cross-faded by a',
134
- ' // triangle weight that is exactly 0 whenever a copy resets its',
135
- ' // phase -> the flow never pops, jumps or pauses, it just keeps going.',
136
- ' float sp = 1.5 * inversesqrt(r * r * r);',
137
- ' float ph = fract(uTime / LOOP);',
138
- ' float ph2 = fract(uTime / LOOP + 0.5);',
139
- ' float wA = 1.0 - abs(1.0 - 2.0 * ph);', // 0 at phase reset, 1 mid-cycle
140
- ' wA = wA * wA * (3.0 - 2.0 * wA);', // smooth the cross-fade
141
- ' float nA = diskFBM(r, phi + ph * sp * LOOP, 0.0);',
142
- ' float nB = diskFBM(r, phi + ph2 * sp * LOOP, 37.0);',
143
- ' // energy-preserving blend: pattern contrast stays constant while fading',
144
- ' float wn = sqrt(wA * wA + (1.0 - wA) * (1.0 - wA));',
145
- ' float dens = (mix(nB, nA, wA) - 0.5) / wn + 0.5;',
146
- ' float m = clamp((dens - 0.30) * 2.2, 0.0, 1.0);',
147
- ' m = m * m * (3.0 - 2.0 * m);',
148
- ' float bands = 0.55 + 0.8 * vnoise(vec2(r * 0.8, 3.17));',
149
- ' // temperature profile: hot inner rim, cooler outskirts',
150
- ' float x = (r - DISK_IN) / (DISK_OUT - DISK_IN);',
151
- ' float h = 0.18 + pow(clamp(1.0 - x, 0.0, 1.0), 1.2);',
152
- ' h += 1.15 * pow(clamp(1.0 - (r - DISK_IN) / 2.2, 0.0, 1.0), 2.0);',
153
- ' h *= 0.5 + 0.8 * m;',
154
- ' h *= bands;',
155
- ' h = clamp(h, 0.0, 1.35);',
156
- ' // relativistic beaming + gravitational redshift',
157
- ' float beta = clamp(sqrt(0.5 / max(r, 1.75)), 0.0, 0.65);',
158
- ' float dop = 1.0 / (1.0 - beta * dot(normalize(vec3(-p.z, 0.0, p.x)), -rdn));',
159
- ' dop = clamp(dop * dop * dop, 0.15, 5.0);',
160
- ' float gr = sqrt(max(1.0 - 1.0 / r, 0.0));',
161
- ' float L = (0.5 + 3.0 * m) * prof * h * (0.6 + 0.4 * gr) * dop;',
162
- ' vec3 c = diskRamp(clamp(h * 0.8 + 0.12, 0.0, 1.0));',
163
- ' c = mix(c, vec3(1.05, 1.0, 0.9), clamp((dop - 1.0) * 0.3, 0.0, 0.55));',
164
- ' c *= L;',
165
- ' alpha = clamp(prof * (0.75 + 0.4 * m) + (1.0 - smoothstep(DISK_IN, 4.6, r)) * 0.25, 0.0, 1.0);',
166
- ' return c;',
167
- '}',
168
- '',
169
- 'void main(){',
170
- ' vec2 uv = (gl_FragCoord.xy * 2.0 - uRes) / uRes.y;',
171
- ' vec3 rd = normalize(uCamMat * vec3(uv * uTanFov, -1.0));',
172
- ' vec3 pos = uCamPos;',
173
- ' vec3 dir = rd;',
174
- ' vec3 hv = cross(pos, dir);',
175
- ' float h2 = dot(hv, hv);', // conserved angular momentum^2
176
- ' vec3 col = vec3(0.0);',
177
- ' float T = 1.0;', // transmittance
178
- ' float captured = 0.0;',
179
- ' float glowD = 0.0;', // soft haze around the disk plane
180
- ' float glowP = 0.0;', // halo hugging the photon sphere
181
- ' for(int i = 0; i < STEPS; i++){',
182
- ' float r2 = dot(pos, pos);',
183
- ' float r = sqrt(r2);',
184
- ' if(r < 1.0){ captured = 1.0; break; }', // event horizon (rs = 1)
185
- ' float dt = clamp(r * 0.055, 0.02, 1.0);',
186
- ' if(r < 4.5) dt *= 0.55;',
187
- ' // Schwarzschild null geodesic: a = -1.5 h^2 r / |r|^5',
188
- ' dir += (-1.5 * h2 * pos / (r2 * r2 * r)) * dt;',
189
- ' vec3 np = pos + dir * dt;',
190
- ' // equatorial plane crossing -> accretion disk',
191
- ' if(pos.y * np.y < 0.0){',
192
- ' vec3 hp = mix(pos, np, pos.y / (pos.y - np.y));',
193
- ' float hr = length(hp.xz);',
194
- ' if(hr > DISK_IN && hr < DISK_OUT){',
195
- ' float a;',
196
- ' vec3 dc = diskShade(hp, normalize(dir), a);',
197
- ' col += T * dc * a;',
198
- ' T *= 1.0 - a;',
199
- ' if(T < 0.02) break;',
200
- ' }',
201
- ' }',
202
- ' glowD += dt * exp(-abs(pos.y) * 0.9) * exp(-max(r - 3.0, 0.0) * 0.35) * smoothstep(1.4, 2.8, r);',
203
- ' glowP += dt * exp(-max(r - 1.5, 0.0) * 2.0);',
204
- ' pos = np;',
205
- ' if(r2 > ESC_R2 && dot(pos, dir) > 0.0) break;', // escaped to white sky
206
- ' }',
207
- ' float cov;',
208
- ' if(captured > 0.5){',
209
- ' cov = 1.0;', // the shadow
210
- ' } else {',
211
- ' col += T * vec3(1.0, 0.52, 0.16) * (glowD * 0.32);',
212
- ' col += T * vec3(1.0, 0.78, 0.45) * (glowP * 0.70);',
213
- ' cov = clamp((1.0 - T) + glowD * 0.32 + glowP * 0.70, 0.0, 1.0);',
214
- ' }',
215
- ' vec3 tc = 1.0 - exp(-col * 1.35);',
216
- ' vec3 outc = mix(vec3(1.0), tc, cov);', // composite over white background
217
- ' outc += (hash21(gl_FragCoord.xy + vec2(uTime * 61.7, uTime * 12.9)) - 0.5) * 0.006 * clamp(cov * 4.0, 0.0, 1.0);',
218
- ' gl_FragColor = vec4(outc, 1.0);',
219
- '}'
220
- ].join('\n');
221
-
222
- var material = new THREE.ShaderMaterial({
223
- uniforms: uniforms,
224
- vertexShader: VERT,
225
- fragmentShader: FRAG,
226
- depthTest: false,
227
- depthWrite: false
228
- });
229
-
230
- var quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), material);
231
- quad.frustumCulled = false;
232
- scene.add(quad);
233
-
234
- var dummyCam = new THREE.Camera();
235
-
236
- /* ---------------- Resize / Loop ---------------- */
237
-
238
- var LOOP_PERIOD = 8.0; // must match LOOP in the shader
239
-
240
- function resize() {
241
- camera.aspect = window.innerWidth / window.innerHeight;
242
- camera.updateProjectionMatrix();
243
- renderer.setSize(window.innerWidth, window.innerHeight);
244
- uniforms.uRes.value.set(renderer.domElement.width, renderer.domElement.height);
245
- }
246
- window.addEventListener('resize', resize);
247
- resize();
248
-
249
- var clock = new THREE.Clock();
250
- var lastT = 0, warm = 0, frCount = 0, frAcc = 0;
251
-
252
- function tick() {
253
- requestAnimationFrame(tick);
254
- var t = clock.getElapsedTime();
255
- var dt = Math.min(t - lastT, 0.1);
256
- lastT = t;
257
-
258
- controls.update();
259
- camera.updateMatrixWorld();
260
-
261
- // wrap time into the loop period so the animation repeats seamlessly forever
262
- uniforms.uTime.value = t % LOOP_PERIOD;
263
- uniforms.uRes.value.set(renderer.domElement.width, renderer.domElement.height);
264
- uniforms.uCamPos.value.copy(camera.position);
265
- var e = camera.matrixWorld.elements;
266
- uniforms.uCamMat.value.set(e[0], e[4], e[8], e[1], e[5], e[9], e[2], e[6], e[10]);
267
-
268
- renderer.render(scene, dummyCam);
269
-
270
- // gentle adaptive resolution if the GPU struggles
271
- warm += dt;
272
- if (warm > 2.5) {
273
- frAcc += dt; frCount++;
274
- if (frCount >= 45) {
275
- if (frAcc / frCount > 0.037 && resScale > 0.7) {
276
- resScale = Math.max(0.7, resScale * 0.78);
277
- renderer.setPixelRatio(resScale);
278
- renderer.setSize(window.innerWidth, window.innerHeight);
279
- }
280
- frCount = 0; frAcc = 0;
281
- }
282
- }
283
- }
284
- tick();
285
- })();
286
- </script>
287
- </body>
288
- </html>