webgpu_performance.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - GLTFloader</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link type="text/css" rel="stylesheet" href="main.css">
  8. </head>
  9. <body>
  10. <div id="info">
  11. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - WebGPU Performance<br />
  12. Dungeon - Low Poly Game Level Challenge by
  13. <a href="https://sketchfab.com/warkarma" target="_blank" rel="noopener">Warkarma</a><br />
  14. <a href="https://hdrihaven.com/hdri/?h=royal_esplanade" target="_blank" rel="noopener">Royal Esplanade</a> from <a href="https://hdrihaven.com/" target="_blank" rel="noopener">HDRI Haven</a>
  15. </div>
  16. <script type="importmap">
  17. {
  18. "imports": {
  19. "three": "../build/three.webgpu.js",
  20. "three/webgpu": "../build/three.webgpu.js",
  21. "three/addons/": "./jsm/",
  22. "stats-gl": "https://cdn.jsdelivr.net/npm/stats-gl@3.6.0/dist/main.js"
  23. }
  24. }
  25. </script>
  26. <script type="module">
  27. import * as THREE from 'three/webgpu';
  28. import Stats from 'stats-gl';
  29. import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
  30. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  31. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  32. import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
  33. import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
  34. let camera, scene, renderer, stats;
  35. let model;
  36. const options = { static: true };
  37. init();
  38. function setStatic( object, value ) {
  39. object.traverse( child => {
  40. if ( child.isMesh ) {
  41. child.static = value;
  42. }
  43. } );
  44. }
  45. function init() {
  46. const container = document.createElement( 'div' );
  47. document.body.appendChild( container );
  48. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 100 );
  49. camera.position.set( 60, 60, 60 );
  50. scene = new THREE.Scene();
  51. renderer = new THREE.WebGPURenderer( { antialias: true } );
  52. renderer.setPixelRatio( window.devicePixelRatio );
  53. renderer.setSize( window.innerWidth, window.innerHeight );
  54. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  55. renderer.toneMappingExposure = 1;
  56. renderer.setAnimationLoop( render );
  57. container.appendChild( renderer.domElement );
  58. //
  59. stats = new Stats( {
  60. precision: 3,
  61. horizontal: false,
  62. trackGPU: true,
  63. } );
  64. stats.init( renderer );
  65. document.body.appendChild( stats.dom );
  66. new RGBELoader()
  67. .setPath( 'textures/equirectangular/' )
  68. .load( 'royal_esplanade_1k.hdr', function ( texture ) {
  69. texture.mapping = THREE.EquirectangularReflectionMapping;
  70. scene.environment = texture;
  71. // model
  72. const dracoLoader = new DRACOLoader();
  73. dracoLoader.setDecoderPath( 'jsm/libs/draco/gltf/' );
  74. const loader = new GLTFLoader().setPath( 'models/gltf/' );
  75. loader.setDRACOLoader( dracoLoader );
  76. loader.load( 'dungeon_warkarma.glb', async function ( gltf ) {
  77. model = gltf.scene;
  78. // wait until the model can be added to the scene without blocking due to shader compilation
  79. await renderer.compileAsync( model, camera, scene );
  80. scene.add( model );
  81. //
  82. setStatic( model, options.static );
  83. } );
  84. } );
  85. const controls = new OrbitControls( camera, renderer.domElement );
  86. controls.minDistance = 2;
  87. controls.maxDistance = 60;
  88. controls.target.set( 0, 0, - 0.2 );
  89. controls.update();
  90. // gui
  91. const gui = new GUI();
  92. gui.add( options, 'static' ).onChange( () => {
  93. setStatic( model, options.static );
  94. } );
  95. window.addEventListener( 'resize', onWindowResize );
  96. }
  97. function onWindowResize() {
  98. camera.aspect = window.innerWidth / window.innerHeight;
  99. camera.updateProjectionMatrix();
  100. renderer.setSize( window.innerWidth, window.innerHeight );
  101. }
  102. //
  103. async function render() {
  104. await renderer.renderAsync( scene, camera );
  105. renderer.resolveTimestampsAsync( THREE.TimestampQuery.RENDER );
  106. stats.update();
  107. }
  108. </script>
  109. </body>
  110. </html>
粤ICP备19079148号