Skip to content

Commit f163bfa

Browse files
authored
Examples: Add WebGPU check to some compute demos. (#31685)
* Example: Add WebGPU check to some compute demos. * Examples: Clean up. * E2E: Add `webgpu_compute_birds` to exception list.
1 parent ca3194a commit f163bfa

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

examples/webgpu_compute_birds.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import Stats from 'stats-gl';
4545
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
46+
import WebGPU from 'three/addons/capabilities/WebGPU.js';
4647

4748
let container, stats;
4849
let camera, scene, renderer;
@@ -129,6 +130,14 @@
129130
}
130131

131132
}
133+
134+
if ( WebGPU.isAvailable() === false ) {
135+
136+
document.body.appendChild( WebGPU.getErrorMessage() );
137+
138+
throw new Error( 'No WebGPU support' );
139+
140+
}
132141

133142
function init() {
134143

examples/webgpu_compute_cloth.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
3333
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
3434
import { HDRLoader } from 'three/addons/loaders/HDRLoader.js';
35+
import WebGPU from 'three/addons/capabilities/WebGPU.js';
3536

3637
let renderer, scene, camera, controls;
3738

@@ -67,6 +68,14 @@
6768
sheenColor: 0xffffff // sRGB
6869
};
6970

71+
if ( WebGPU.isAvailable() === false ) {
72+
73+
document.body.appendChild( WebGPU.getErrorMessage() );
74+
75+
throw new Error( 'No WebGPU support' );
76+
77+
}
78+
7079
init();
7180

7281
async function init() {
@@ -106,11 +115,19 @@
106115
gui.add( params, 'wind', 0, 5, 0.1 );
107116

108117
const materialFolder = gui.addFolder( 'material' );
109-
materialFolder.addColor( API, 'color' ).onChange( function ( color ) { clothMaterial.color.setHex( color ); } );
118+
materialFolder.addColor( API, 'color' ).onChange( function ( color ) {
119+
120+
clothMaterial.color.setHex( color );
121+
122+
} );
110123
materialFolder.add( clothMaterial, 'roughness', 0.0, 1, 0.01 );
111124
materialFolder.add( clothMaterial, 'sheen', 0.0, 1, 0.01 );
112125
materialFolder.add( clothMaterial, 'sheenRoughness', 0.0, 1, 0.01 );
113-
materialFolder.addColor( API, 'sheenColor' ).onChange( function ( color ) { clothMaterial.sheenColor.setHex( color ); } );
126+
materialFolder.addColor( API, 'sheenColor' ).onChange( function ( color ) {
127+
128+
clothMaterial.sheenColor.setHex( color );
129+
130+
} );
114131

115132
window.addEventListener( 'resize', onWindowResize );
116133

examples/webgpu_compute_texture_3d.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,20 @@
3333
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
3434

3535
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
36+
import WebGPU from 'three/addons/capabilities/WebGPU.js';
3637

3738
let renderer, scene, camera;
3839
let mesh;
3940
let computeNode;
4041

42+
if ( WebGPU.isAvailable() === false ) {
43+
44+
document.body.appendChild( WebGPU.getErrorMessage() );
45+
46+
throw new Error( 'No WebGPU support' );
47+
48+
}
49+
4150
init();
4251

4352
async function init() {

test/e2e/puppeteer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ const exceptionList = [
127127

128128
// Awaiting for WebGL backend support
129129
'webgpu_compute_audio',
130+
'webgpu_compute_birds',
130131
'webgpu_compute_texture',
131132
'webgpu_compute_texture_3d',
132133
'webgpu_compute_texture_pingpong',

0 commit comments

Comments
 (0)