ThorAILabs commited on
Commit
8020f7e
·
verified ·
1 Parent(s): 60aeb77

add instructions for raytracing

Browse files
Files changed (1) hide show
  1. index.html +143 -14
index.html CHANGED
@@ -39,9 +39,86 @@
39
  color: white;
40
  font-size: 12px;
41
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  </style>
43
  </head>
44
  <body class="bg-gray-900 text-white h-screen flex overflow-hidden">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  <!-- Sidebar -->
46
  <div id="sidebar" class="sidebar w-64 bg-gray-800 h-full flex flex-col border-r border-gray-700">
47
  <div class="p-4 border-b border-gray-700 flex justify-between items-center">
@@ -196,6 +273,29 @@
196
  vertexCount: 0
197
  };
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  // Initialize the application
200
  async function init() {
201
  // Create scene
@@ -216,20 +316,27 @@
216
 
217
  // Initialize WebGPU raytracing renderer
218
  try {
219
- raytracingRenderer = new WebGPURaytracingRenderer({
220
- canvas: document.createElement('canvas'),
221
- width: window.innerWidth,
222
- height: window.innerHeight
223
- });
224
-
225
- await raytracingRenderer.init();
226
-
227
- // Configure raytracing settings
228
- raytracingRenderer.setBounces(3);
229
- raytracingRenderer.setSamples(4);
230
- raytracingRenderer.setDenoise(true);
231
-
232
- console.log("WebGPU Raytracing initialized successfully");
 
 
 
 
 
 
 
233
  } catch (e) {
234
  console.error("Failed to initialize WebGPU raytracing:", e);
235
  document.getElementById('toggleRaytracing').disabled = true;
@@ -259,6 +366,9 @@
259
  // Event listeners
260
  setupEventListeners();
261
 
 
 
 
262
  // Start animation loop
263
  animate();
264
  }
@@ -345,6 +455,11 @@
345
 
346
  // Raytracing toggle
347
  document.getElementById('toggleRaytracing').addEventListener('click', () => {
 
 
 
 
 
348
  raytracingEnabled = !raytracingEnabled;
349
  document.getElementById('raytraceSettings').classList.toggle('hidden', !raytracingEnabled);
350
  document.getElementById('renderMode').textContent = raytracingEnabled ? 'Raytracing' : 'Rasterization';
@@ -426,6 +541,20 @@
426
  document.getElementById('fileInput').accept = '.stl,.obj';
427
  document.getElementById('fileInput').click();
428
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
  }
430
 
431
  // Add ambient light
 
39
  color: white;
40
  font-size: 12px;
41
  }
42
+ .instruction-step {
43
+ counter-increment: step-counter;
44
+ position: relative;
45
+ padding-left: 2rem;
46
+ margin-bottom: 0.5rem;
47
+ }
48
+ .instruction-step::before {
49
+ content: counter(step-counter);
50
+ position: absolute;
51
+ left: 0;
52
+ background-color: #3b82f6;
53
+ color: white;
54
+ width: 1.5rem;
55
+ height: 1.5rem;
56
+ border-radius: 50%;
57
+ display: flex;
58
+ align-items: center;
59
+ justify-content: center;
60
+ font-size: 0.8rem;
61
+ }
62
  </style>
63
  </head>
64
  <body class="bg-gray-900 text-white h-screen flex overflow-hidden">
65
+ <!-- WebGPU Modal -->
66
+ <div id="webgpuModal" class="fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50 hidden">
67
+ <div class="bg-gray-800 rounded-lg shadow-xl p-6 max-w-2xl w-full mx-4">
68
+ <div class="flex justify-between items-center mb-4">
69
+ <h2 class="text-xl font-bold text-blue-400">
70
+ <i class="fas fa-info-circle mr-2"></i> WebGPU Setup Required
71
+ </h2>
72
+ <button id="closeWebgpuModal" class="text-gray-400 hover:text-white">
73
+ <i class="fas fa-times"></i>
74
+ </button>
75
+ </div>
76
+
77
+ <div class="bg-gray-700 p-4 rounded mb-4">
78
+ <p class="text-yellow-300 mb-2">
79
+ <i class="fas fa-exclamation-triangle mr-2"></i>
80
+ Raytracing requires WebGPU which is currently experimental in Chrome/Edge
81
+ </p>
82
+ <p class="text-sm text-gray-300">
83
+ Follow these steps to enable WebGPU in Chromium browsers (Chrome/Edge):
84
+ </p>
85
+ </div>
86
+
87
+ <div class="space-y-3 mb-6 pl-4" style="counter-reset: step-counter;">
88
+ <div class="instruction-step">
89
+ <strong>Type this in your address bar:</strong>
90
+ <code class="block bg-gray-900 p-2 rounded mt-1 text-sm">chrome://flags/#enable-unsafe-webgpu</code>
91
+ </div>
92
+ <div class="instruction-step">
93
+ <strong>Find "Unsafe WebGPU"</strong> in the list and change it from "Default" to <span class="bg-blue-600 px-2 py-1 rounded">Enabled</span>
94
+ </div>
95
+ <div class="instruction-step">
96
+ <strong>Restart your browser</strong> when prompted
97
+ </div>
98
+ <div class="instruction-step">
99
+ <strong>Reload this page</strong> after restarting
100
+ </div>
101
+ </div>
102
+
103
+ <div class="bg-gray-700 p-4 rounded">
104
+ <p class="text-sm text-gray-300">
105
+ <i class="fas fa-info-circle mr-2 text-blue-400"></i>
106
+ WebGPU is only available in Chrome 113+ and Edge 113+ on Windows/Linux/Mac.
107
+ Other browsers will fall back to traditional rasterization.
108
+ </p>
109
+ </div>
110
+
111
+ <div class="flex justify-end mt-4 space-x-2">
112
+ <button id="dontShowAgain" class="bg-gray-600 hover:bg-gray-500 px-4 py-2 rounded">
113
+ Don't Show Again
114
+ </button>
115
+ <button id="gotItButton" class="bg-blue-600 hover:bg-blue-500 px-4 py-2 rounded">
116
+ Got It!
117
+ </button>
118
+ </div>
119
+ </div>
120
+ </div>
121
+
122
  <!-- Sidebar -->
123
  <div id="sidebar" class="sidebar w-64 bg-gray-800 h-full flex flex-col border-r border-gray-700">
124
  <div class="p-4 border-b border-gray-700 flex justify-between items-center">
 
273
  vertexCount: 0
274
  };
275
 
276
+ // Check if WebGPU is supported
277
+ function isWebGPUSupported() {
278
+ return navigator.gpu !== undefined;
279
+ }
280
+
281
+ // Check if this is a Chromium browser
282
+ function isChromium() {
283
+ return /Chrome|Edg/.test(navigator.userAgent) && !/Opera|OPR/.test(navigator.userAgent);
284
+ }
285
+
286
+ // Show WebGPU instructions if needed
287
+ function checkWebGPUSupport() {
288
+ // Check if user has previously dismissed the modal
289
+ if (localStorage.getItem('dontShowWebGPUModal') === 'true') {
290
+ return;
291
+ }
292
+
293
+ // Only show for Chromium browsers without WebGPU support
294
+ if (isChromium() && !isWebGPUSupported()) {
295
+ document.getElementById('webgpuModal').classList.remove('hidden');
296
+ }
297
+ }
298
+
299
  // Initialize the application
300
  async function init() {
301
  // Create scene
 
316
 
317
  // Initialize WebGPU raytracing renderer
318
  try {
319
+ if (isWebGPUSupported()) {
320
+ raytracingRenderer = new WebGPURaytracingRenderer({
321
+ canvas: document.createElement('canvas'),
322
+ width: window.innerWidth,
323
+ height: window.innerHeight
324
+ });
325
+
326
+ await raytracingRenderer.init();
327
+
328
+ // Configure raytracing settings
329
+ raytracingRenderer.setBounces(3);
330
+ raytracingRenderer.setSamples(4);
331
+ raytracingRenderer.setDenoise(true);
332
+
333
+ console.log("WebGPU Raytracing initialized successfully");
334
+ } else {
335
+ console.warn("WebGPU not supported in this browser");
336
+ document.getElementById('toggleRaytracing').disabled = true;
337
+ document.getElementById('toggleRaytracing').classList.add('opacity-50', 'cursor-not-allowed');
338
+ document.getElementById('toggleRaytracing').title = "WebGPU not supported in your browser";
339
+ }
340
  } catch (e) {
341
  console.error("Failed to initialize WebGPU raytracing:", e);
342
  document.getElementById('toggleRaytracing').disabled = true;
 
366
  // Event listeners
367
  setupEventListeners();
368
 
369
+ // Check WebGPU support
370
+ checkWebGPUSupport();
371
+
372
  // Start animation loop
373
  animate();
374
  }
 
455
 
456
  // Raytracing toggle
457
  document.getElementById('toggleRaytracing').addEventListener('click', () => {
458
+ if (!isWebGPUSupported()) {
459
+ document.getElementById('webgpuModal').classList.remove('hidden');
460
+ return;
461
+ }
462
+
463
  raytracingEnabled = !raytracingEnabled;
464
  document.getElementById('raytraceSettings').classList.toggle('hidden', !raytracingEnabled);
465
  document.getElementById('renderMode').textContent = raytracingEnabled ? 'Raytracing' : 'Rasterization';
 
541
  document.getElementById('fileInput').accept = '.stl,.obj';
542
  document.getElementById('fileInput').click();
543
  });
544
+
545
+ // WebGPU modal controls
546
+ document.getElementById('closeWebgpuModal').addEventListener('click', () => {
547
+ document.getElementById('webgpuModal').classList.add('hidden');
548
+ });
549
+
550
+ document.getElementById('gotItButton').addEventListener('click', () => {
551
+ document.getElementById('webgpuModal').classList.add('hidden');
552
+ });
553
+
554
+ document.getElementById('dontShowAgain').addEventListener('click', () => {
555
+ localStorage.setItem('dontShowWebGPUModal', 'true');
556
+ document.getElementById('webgpuModal').classList.add('hidden');
557
+ });
558
  }
559
 
560
  // Add ambient light