1
0

webgpu_postprocessing_bloom.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - postprocessing - bloom</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. <meta property="og:title" content="three.js webgpu - postprocessing - bloom">
  8. <meta property="og:type" content="website">
  9. <meta property="og:url" content="https://threejs.org/examples/webgpu_postprocessing_bloom.html">
  10. <meta property="og:image" content="https://threejs.org/examples/screenshots/webgpu_postprocessing_bloom.jpg">
  11. <link type="text/css" rel="stylesheet" href="example.css">
  12. </head>
  13. <body>
  14. <div id="info">
  15. <a href="https://threejs.org/" target="_blank" rel="noopener" class="logo-link"></a>
  16. <div class="title-wrapper">
  17. <a href="https://threejs.org/" target="_blank" rel="noopener">three.js</a><span>Bloom</span>
  18. </div>
  19. <small>
  20. Bloom pass by <a href="http://eduperiment.com" target="_blank" rel="noopener">Prashant Sharma</a> and <a href="https://clara.io" target="_blank" rel="noopener">Ben Houston</a>.<br/>
  21. <a href="https://blog.sketchfab.com/art-spotlight-primary-ion-drive/" target="_blank" rel="noopener">Primary Ion Drive</a>
  22. by <a href="http://mjmurdock.com/" target="_blank" rel="noopener">Mike Murdock</a> is licensed under <a href="https://creativecommons.org/licenses/by/4.0/" target="_blank" rel="noopener">Creative Commons Attribution</a>.<br />
  23. </small>
  24. </div>
  25. <script type="importmap">
  26. {
  27. "imports": {
  28. "three": "../build/three.webgpu.js",
  29. "three/webgpu": "../build/three.webgpu.js",
  30. "three/tsl": "../build/three.tsl.js",
  31. "three/addons/": "./jsm/"
  32. }
  33. }
  34. </script>
  35. <script type="module">
  36. import * as THREE from 'three/webgpu';
  37. import { pass } from 'three/tsl';
  38. import { bloom } from 'three/addons/tsl/display/BloomNode.js';
  39. import { Inspector } from 'three/addons/inspector/Inspector.js';
  40. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  41. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  42. let camera;
  43. let renderPipeline, renderer, mixer, timer;
  44. const params = {
  45. threshold: 0,
  46. strength: 1,
  47. radius: 0,
  48. exposure: 1
  49. };
  50. init();
  51. async function init() {
  52. timer = new THREE.Timer();
  53. timer.connect( document );
  54. const scene = new THREE.Scene();
  55. camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 100 );
  56. camera.position.set( - 5, 2.5, - 3.5 );
  57. scene.add( camera );
  58. scene.add( new THREE.AmbientLight( 0xcccccc ) );
  59. const pointLight = new THREE.PointLight( 0xffffff, 100 );
  60. camera.add( pointLight );
  61. const loader = new GLTFLoader();
  62. const gltf = await loader.loadAsync( 'models/gltf/PrimaryIonDrive.glb' );
  63. const model = gltf.scene;
  64. scene.add( model );
  65. mixer = new THREE.AnimationMixer( model );
  66. const clip = gltf.animations[ 0 ];
  67. mixer.clipAction( clip.optimize() ).play();
  68. //
  69. renderer = new THREE.WebGPURenderer( { antialias: true } );
  70. renderer.setPixelRatio( window.devicePixelRatio );
  71. renderer.setSize( window.innerWidth, window.innerHeight );
  72. renderer.setAnimationLoop( animate );
  73. renderer.toneMapping = THREE.ReinhardToneMapping;
  74. renderer.inspector = new Inspector();
  75. document.body.appendChild( renderer.domElement );
  76. //
  77. renderPipeline = new THREE.RenderPipeline( renderer );
  78. // below optimized config is only relevant when using MSAA and also optional.
  79. // store no multisampled data and only resolve color
  80. const config = {
  81. storeMultisampledColorBuffer: false,
  82. storeMultisampledDepthBuffer: false,
  83. storeMultisampledStencilBuffer: false,
  84. resolveColorBuffer: true,
  85. resolveDepthBuffer: false,
  86. resolveStencilBuffer: false
  87. };
  88. const scenePass = pass( scene, camera, config );
  89. const scenePassColor = scenePass.getTextureNode( 'output' ).toInspector( 'Color' );
  90. const bloomPass = bloom( scenePassColor ).toInspector( 'Bloom' );
  91. renderPipeline.outputNode = scenePassColor.add( bloomPass );
  92. //
  93. const controls = new OrbitControls( camera, renderer.domElement );
  94. controls.maxPolarAngle = Math.PI * 0.5;
  95. controls.minDistance = 3;
  96. controls.maxDistance = 8;
  97. //
  98. const gui = renderer.inspector.createParameters( 'Settings' );
  99. const bloomFolder = gui.addFolder( 'bloom' );
  100. bloomFolder.add( params, 'threshold', 0.0, 1.0 ).onChange( function ( value ) {
  101. bloomPass.threshold.value = value;
  102. } );
  103. bloomFolder.add( params, 'strength', 0.0, 3.0 ).onChange( function ( value ) {
  104. bloomPass.strength.value = value;
  105. } );
  106. bloomFolder.add( params, 'radius', 0.0, 1.0, 0.01 ).onChange( function ( value ) {
  107. bloomPass.radius.value = value;
  108. } );
  109. const toneMappingFolder = gui.addFolder( 'tone mapping' );
  110. toneMappingFolder.add( params, 'exposure', 0.1, 2 ).onChange( function ( value ) {
  111. renderer.toneMappingExposure = Math.pow( value, 4.0 );
  112. } );
  113. window.addEventListener( 'resize', onWindowResize );
  114. }
  115. function onWindowResize() {
  116. const width = window.innerWidth;
  117. const height = window.innerHeight;
  118. camera.aspect = width / height;
  119. camera.updateProjectionMatrix();
  120. renderer.setSize( width, height );
  121. }
  122. function animate() {
  123. timer.update();
  124. const delta = timer.getDelta();
  125. mixer.update( delta );
  126. renderPipeline.render();
  127. }
  128. </script>
  129. </body>
  130. </html>
粤ICP备19079148号