webgpu_postprocessing_bloom_emissive.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - bloom emissive</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 - bloom emissive
  12. </div>
  13. <script type="importmap">
  14. {
  15. "imports": {
  16. "three": "../build/three.webgpu.js",
  17. "three/tsl": "../build/three.webgpu.js",
  18. "three/addons/": "./jsm/"
  19. }
  20. }
  21. </script>
  22. <script type="module">
  23. import * as THREE from 'three';
  24. import { pass, mrt, output, bloom, emissive } from 'three/tsl';
  25. import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
  26. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  27. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  28. import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
  29. let camera, scene, renderer;
  30. let postProcessing;
  31. init();
  32. function init() {
  33. const container = document.createElement( 'div' );
  34. document.body.appendChild( container );
  35. //
  36. camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.25, 20 );
  37. camera.position.set( - 1.8, 0.6, 2.7 );
  38. scene = new THREE.Scene();
  39. new RGBELoader()
  40. .setPath( 'textures/equirectangular/' )
  41. .load( 'moonless_golf_1k.hdr', function ( texture ) {
  42. texture.mapping = THREE.EquirectangularReflectionMapping;
  43. scene.background = texture;
  44. scene.environment = texture;
  45. // model
  46. const loader = new GLTFLoader().setPath( 'models/gltf/DamagedHelmet/glTF/' );
  47. loader.load( 'DamagedHelmet.gltf', function ( gltf ) {
  48. scene.add( gltf.scene );
  49. } );
  50. } );
  51. //
  52. renderer = new THREE.WebGPURenderer();
  53. renderer.setPixelRatio( window.devicePixelRatio );
  54. renderer.setSize( window.innerWidth, window.innerHeight );
  55. renderer.setAnimationLoop( render );
  56. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  57. container.appendChild( renderer.domElement );
  58. //
  59. const scenePass = pass( scene, camera );
  60. scenePass.setMRT( mrt( {
  61. output,
  62. emissive
  63. } ) );
  64. const outputPass = scenePass.getTextureNode();
  65. const emissivePass = scenePass.getTextureNode( 'emissive' );
  66. const bloomPass = bloom( emissivePass, 2.5, .5 );
  67. postProcessing = new THREE.PostProcessing( renderer );
  68. postProcessing.outputNode = outputPass.add( bloomPass );
  69. //
  70. const controls = new OrbitControls( camera, renderer.domElement );
  71. controls.minDistance = 2;
  72. controls.maxDistance = 10;
  73. controls.target.set( 0, 0, - 0.2 );
  74. window.addEventListener( 'resize', onWindowResize );
  75. //
  76. const gui = new GUI();
  77. const bloomFolder = gui.addFolder( 'bloom' );
  78. bloomFolder.add( bloomPass.strength, 'value', 0.0, 5.0 ).name( 'strength' );
  79. bloomFolder.add( bloomPass.radius, 'value', 0.0, 1.0 ).name( 'radius' );
  80. const toneMappingFolder = gui.addFolder( 'tone mapping' );
  81. toneMappingFolder.add( renderer, 'toneMappingExposure', 0.1, 2 ).name( 'exposure' );
  82. }
  83. function onWindowResize() {
  84. camera.aspect = window.innerWidth / window.innerHeight;
  85. camera.updateProjectionMatrix();
  86. renderer.setSize( window.innerWidth, window.innerHeight );
  87. }
  88. //
  89. function render() {
  90. postProcessing.render();
  91. }
  92. </script>
  93. </body>
  94. </html>