webgpu_postprocessing_bloom_emissive.html 3.6 KB

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