webgpu_loader_gltf_transmission.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - glTF + transmission</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 - glTF + <a href="https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission" target="_blank" rel="noopener">KHR_materials_transmission</a><br />
  12. Iridescent Dish With Olives by <a href="https://github.com/echadwick-wayfair" target="_blank" rel="noopener">Eric Chadwick</a><br />
  13. <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>
  14. </div>
  15. <script type="importmap">
  16. {
  17. "imports": {
  18. "three": "../build/three.webgpu.js",
  19. "three/tsl": "../build/three.webgpu.js",
  20. "three/addons/": "./jsm/"
  21. }
  22. }
  23. </script>
  24. <script type="module">
  25. import * as THREE from 'three';
  26. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  27. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  28. import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
  29. import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
  30. let camera, scene, renderer, controls, clock, mixer;
  31. init();
  32. function init() {
  33. clock = new THREE.Clock();
  34. const container = document.createElement( 'div' );
  35. document.body.appendChild( container );
  36. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );
  37. camera.position.set( 0, 0.4, 0.7 );
  38. scene = new THREE.Scene();
  39. new RGBELoader()
  40. .setPath( 'textures/equirectangular/' )
  41. .load( 'royal_esplanade_1k.hdr', function ( texture ) {
  42. texture.mapping = THREE.EquirectangularReflectionMapping;
  43. scene.background = texture;
  44. scene.backgroundBlurriness = 0.35;
  45. scene.environment = texture;
  46. // model
  47. new GLTFLoader()
  48. .setPath( 'models/gltf/' )
  49. .setDRACOLoader( new DRACOLoader().setDecoderPath( 'jsm/libs/draco/gltf/' ) )
  50. .load( 'IridescentDishWithOlives.glb', function ( gltf ) {
  51. mixer = new THREE.AnimationMixer( gltf.scene );
  52. mixer.clipAction( gltf.animations[ 0 ] ).play();
  53. scene.add( gltf.scene );
  54. } );
  55. } );
  56. renderer = new THREE.WebGPURenderer( { antialias: true } );
  57. renderer.setAnimationLoop( render );
  58. renderer.setPixelRatio( window.devicePixelRatio );
  59. renderer.setSize( window.innerWidth, window.innerHeight );
  60. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  61. renderer.toneMappingExposure = 1;
  62. container.appendChild( renderer.domElement );
  63. controls = new OrbitControls( camera, renderer.domElement );
  64. controls.autoRotate = true;
  65. controls.autoRotateSpeed = - 0.75;
  66. controls.enableDamping = true;
  67. controls.minDistance = 0.5;
  68. controls.maxDistance = 1;
  69. controls.target.set( 0, 0.1, 0 );
  70. controls.update();
  71. window.addEventListener( 'resize', onWindowResize );
  72. }
  73. function onWindowResize() {
  74. camera.aspect = window.innerWidth / window.innerHeight;
  75. camera.updateProjectionMatrix();
  76. renderer.setSize( window.innerWidth, window.innerHeight );
  77. }
  78. //
  79. function render() {
  80. if ( mixer ) mixer.update( clock.getDelta() );
  81. controls.update();
  82. renderer.render( scene, camera );
  83. }
  84. </script>
  85. </body>
  86. </html>