webgl_postprocessing_unreal_bloom.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - postprocessing - unreal 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="main.css">
  8. <style>
  9. #info > * {
  10. max-width: 650px;
  11. margin-left: auto;
  12. margin-right: auto;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div id="container"></div>
  18. <div id="info">
  19. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - 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>
  20. <br/>
  21. Model: <a href="https://blog.sketchfab.com/art-spotlight-primary-ion-drive/" target="_blank" rel="noopener">Primary Ion Drive</a> by
  22. <a href="http://mjmurdock.com/" target="_blank" rel="noopener">Mike Murdock</a>, CC Attribution.
  23. </div>
  24. <script type="module">
  25. import * as THREE from '../build/three.module.js';
  26. import Stats from './jsm/libs/stats.module.js';
  27. import { GUI } from './jsm/libs/dat.gui.module.js';
  28. import { OrbitControls } from './jsm/controls/OrbitControls.js';
  29. import { GLTFLoader } from './jsm/loaders/GLTFLoader.js';
  30. import { EffectComposer } from './jsm/postprocessing/EffectComposer.js';
  31. import { RenderPass } from './jsm/postprocessing/RenderPass.js';
  32. import { UnrealBloomPass } from './jsm/postprocessing/UnrealBloomPass.js';
  33. var scene, camera, controls, pointLight, stats;
  34. var composer, renderer, mixer;
  35. var params = {
  36. exposure: 1,
  37. bloomStrength: 1.5,
  38. bloomThreshold: 0,
  39. bloomRadius: 0
  40. };
  41. var clock = new THREE.Clock();
  42. var container = document.getElementById( 'container' );
  43. stats = new Stats();
  44. container.appendChild( stats.dom );
  45. renderer = new THREE.WebGLRenderer( { antialias: true } );
  46. renderer.setPixelRatio( window.devicePixelRatio );
  47. renderer.setSize( window.innerWidth, window.innerHeight );
  48. renderer.toneMapping = THREE.ReinhardToneMapping;
  49. container.appendChild( renderer.domElement );
  50. scene = new THREE.Scene();
  51. camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 100 );
  52. camera.position.set( - 5, 2.5, - 3.5 );
  53. scene.add( camera );
  54. controls = new OrbitControls( camera, renderer.domElement );
  55. controls.maxPolarAngle = Math.PI * 0.5;
  56. controls.minDistance = 1;
  57. controls.maxDistance = 10;
  58. scene.add( new THREE.AmbientLight( 0x404040 ) );
  59. pointLight = new THREE.PointLight( 0xffffff, 1 );
  60. camera.add( pointLight );
  61. var renderScene = new RenderPass( scene, camera );
  62. var bloomPass = new UnrealBloomPass( new THREE.Vector2( window.innerWidth, window.innerHeight ), 1.5, 0.4, 0.85 );
  63. bloomPass.threshold = params.bloomThreshold;
  64. bloomPass.strength = params.bloomStrength;
  65. bloomPass.radius = params.bloomRadius;
  66. composer = new EffectComposer( renderer );
  67. composer.addPass( renderScene );
  68. composer.addPass( bloomPass );
  69. new GLTFLoader().load( 'models/gltf/PrimaryIonDrive.glb', function ( gltf ) {
  70. var model = gltf.scene;
  71. scene.add( model );
  72. // Mesh contains self-intersecting semi-transparent faces, which display
  73. // z-fighting unless depthWrite is disabled.
  74. var core = model.getObjectByName( 'geo1_HoloFillDark_0' );
  75. core.material.depthWrite = false;
  76. mixer = new THREE.AnimationMixer( model );
  77. var clip = gltf.animations[ 0 ];
  78. mixer.clipAction( clip.optimize() ).play();
  79. animate();
  80. } );
  81. var gui = new GUI();
  82. gui.add( params, 'exposure', 0.1, 2 ).onChange( function ( value ) {
  83. renderer.toneMappingExposure = Math.pow( value, 4.0 );
  84. } );
  85. gui.add( params, 'bloomThreshold', 0.0, 1.0 ).onChange( function ( value ) {
  86. bloomPass.threshold = Number( value );
  87. } );
  88. gui.add( params, 'bloomStrength', 0.0, 3.0 ).onChange( function ( value ) {
  89. bloomPass.strength = Number( value );
  90. } );
  91. gui.add( params, 'bloomRadius', 0.0, 1.0 ).step( 0.01 ).onChange( function ( value ) {
  92. bloomPass.radius = Number( value );
  93. } );
  94. window.onresize = function () {
  95. var width = window.innerWidth;
  96. var height = window.innerHeight;
  97. camera.aspect = width / height;
  98. camera.updateProjectionMatrix();
  99. renderer.setSize( width, height );
  100. composer.setSize( width, height );
  101. };
  102. function animate() {
  103. requestAnimationFrame( animate );
  104. const delta = clock.getDelta();
  105. mixer.update( delta );
  106. stats.update();
  107. composer.render();
  108. }
  109. </script>
  110. </body>
  111. </html>