webgpu_postprocessing_bloom_emissive.html 3.5 KB

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