webgpu_postprocessing_bloom.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. <link type="text/css" rel="stylesheet" href="example.css">
  8. </head>
  9. <body>
  10. <div id="info">
  11. <a href="https://threejs.org/" target="_blank" rel="noopener" class="logo-link"></a>
  12. <div class="title-wrapper">
  13. <a href="https://threejs.org/" target="_blank" rel="noopener">three.js</a><span>Bloom</span>
  14. </div>
  15. <small>
  16. 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/>
  17. <a href="https://blog.sketchfab.com/art-spotlight-primary-ion-drive/" target="_blank" rel="noopener">Primary Ion Drive</a>
  18. 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 />
  19. </small>
  20. </div>
  21. <script type="importmap">
  22. {
  23. "imports": {
  24. "three": "../build/three.webgpu.js",
  25. "three/webgpu": "../build/three.webgpu.js",
  26. "three/tsl": "../build/three.tsl.js",
  27. "three/addons/": "./jsm/"
  28. }
  29. }
  30. </script>
  31. <script type="module">
  32. import * as THREE from 'three/webgpu';
  33. import { pass } from 'three/tsl';
  34. import { bloom } from 'three/addons/tsl/display/BloomNode.js';
  35. import { Inspector } from 'three/addons/inspector/Inspector.js';
  36. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  37. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  38. let camera;
  39. let postProcessing, renderer, mixer, clock;
  40. const params = {
  41. threshold: 0,
  42. strength: 1,
  43. radius: 0,
  44. exposure: 1
  45. };
  46. init();
  47. async function init() {
  48. clock = new THREE.Clock();
  49. const scene = new THREE.Scene();
  50. camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 100 );
  51. camera.position.set( - 5, 2.5, - 3.5 );
  52. scene.add( camera );
  53. scene.add( new THREE.AmbientLight( 0xcccccc ) );
  54. const pointLight = new THREE.PointLight( 0xffffff, 100 );
  55. camera.add( pointLight );
  56. const loader = new GLTFLoader();
  57. const gltf = await loader.loadAsync( 'models/gltf/PrimaryIonDrive.glb' );
  58. const model = gltf.scene;
  59. scene.add( model );
  60. mixer = new THREE.AnimationMixer( model );
  61. const clip = gltf.animations[ 0 ];
  62. mixer.clipAction( clip.optimize() ).play();
  63. //
  64. renderer = new THREE.WebGPURenderer( { antialias: true } );
  65. renderer.setPixelRatio( window.devicePixelRatio );
  66. renderer.setSize( window.innerWidth, window.innerHeight );
  67. renderer.setAnimationLoop( animate );
  68. renderer.toneMapping = THREE.ReinhardToneMapping;
  69. renderer.inspector = new Inspector();
  70. document.body.appendChild( renderer.domElement );
  71. //
  72. postProcessing = new THREE.PostProcessing( renderer );
  73. const scenePass = pass( scene, camera );
  74. const scenePassColor = scenePass.getTextureNode( 'output' ).toInspector( 'Color' );
  75. const bloomPass = bloom( scenePassColor ).toInspector( 'Bloom' );
  76. postProcessing.outputNode = scenePassColor.add( bloomPass );
  77. //
  78. const controls = new OrbitControls( camera, renderer.domElement );
  79. controls.maxPolarAngle = Math.PI * 0.5;
  80. controls.minDistance = 3;
  81. controls.maxDistance = 8;
  82. //
  83. const gui = renderer.inspector.createParameters( 'Settings' );
  84. const bloomFolder = gui.addFolder( 'bloom' );
  85. bloomFolder.add( params, 'threshold', 0.0, 1.0 ).onChange( function ( value ) {
  86. bloomPass.threshold.value = value;
  87. } );
  88. bloomFolder.add( params, 'strength', 0.0, 3.0 ).onChange( function ( value ) {
  89. bloomPass.strength.value = value;
  90. } );
  91. gui.add( params, 'radius', 0.0, 1.0, 0.01 ).onChange( function ( value ) {
  92. bloomPass.radius.value = value;
  93. } );
  94. const toneMappingFolder = gui.addFolder( 'tone mapping' );
  95. toneMappingFolder.add( params, 'exposure', 0.1, 2 ).onChange( function ( value ) {
  96. renderer.toneMappingExposure = Math.pow( value, 4.0 );
  97. } );
  98. window.addEventListener( 'resize', onWindowResize );
  99. }
  100. function onWindowResize() {
  101. const width = window.innerWidth;
  102. const height = window.innerHeight;
  103. camera.aspect = width / height;
  104. camera.updateProjectionMatrix();
  105. renderer.setSize( width, height );
  106. }
  107. function animate() {
  108. const delta = clock.getDelta();
  109. mixer.update( delta );
  110. postProcessing.render();
  111. }
  112. </script>
  113. </body>
  114. </html>
粤ICP备19079148号