webgl_loader_texture_hdr.html 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - materials - HDR texture loader</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> - webgl HDR (RGBE) texture loader example<br/>
  12. Image courtesy of <a href="http://www.pauldebevec.com/Research/HDR/" target="_blank" rel="noopener">Paul Debevec</a>.
  13. </div>
  14. <script type="module">
  15. import * as THREE from '../build/three.module.js';
  16. import { GUI } from './jsm/libs/dat.gui.module.js';
  17. import { RGBELoader } from './jsm/loaders/RGBELoader.js';
  18. var params = {
  19. exposure: 2.0
  20. };
  21. var renderer, scene, camera;
  22. init();
  23. function init() {
  24. renderer = new THREE.WebGLRenderer();
  25. renderer.setPixelRatio( window.devicePixelRatio );
  26. renderer.setSize( window.innerWidth, window.innerHeight );
  27. document.body.appendChild( renderer.domElement );
  28. renderer.toneMapping = THREE.ReinhardToneMapping;
  29. renderer.toneMappingExposure = params.exposure;
  30. renderer.outputEncoding = THREE.sRGBEncoding;
  31. scene = new THREE.Scene();
  32. var aspect = window.innerWidth / window.innerHeight;
  33. camera = new THREE.OrthographicCamera( - aspect, aspect, 1, - 1, 0, 1 );
  34. new RGBELoader()
  35. .setDataType( THREE.UnsignedByteType ) // alt: FloatType, HalfFloatType
  36. .load( 'textures/memorial.hdr', function ( texture, textureData ) {
  37. //console.log( textureData );
  38. //console.log( texture );
  39. var material = new THREE.MeshBasicMaterial( { map: texture } );
  40. var quad = new THREE.PlaneBufferGeometry( 1.5 * textureData.width / textureData.height, 1.5 );
  41. var mesh = new THREE.Mesh( quad, material );
  42. scene.add( mesh );
  43. render();
  44. } );
  45. //
  46. var gui = new GUI();
  47. gui.add( params, 'exposure', 0, 4, 0.01 ).onChange( render );
  48. gui.open();
  49. //
  50. window.addEventListener( 'resize', onWindowResize, false );
  51. }
  52. function onWindowResize() {
  53. var aspect = window.innerWidth / window.innerHeight;
  54. var frustumHeight = camera.top - camera.bottom;
  55. camera.left = - frustumHeight * aspect / 2;
  56. camera.right = frustumHeight * aspect / 2;
  57. camera.updateProjectionMatrix();
  58. renderer.setSize( window.innerWidth, window.innerHeight );
  59. render();
  60. }
  61. //
  62. function render() {
  63. renderer.toneMappingExposure = params.exposure;
  64. renderer.render( scene, camera );
  65. }
  66. </script>
  67. </body>
  68. </html>