webgl_loader_texture_exr.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - materials - EXR 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 EXR 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 { EXRLoader } from './jsm/loaders/EXRLoader.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 EXRLoader()
  35. .setDataType( THREE.FloatType )
  36. .load( 'textures/memorial.exr', function ( texture, textureData ) {
  37. // memorial.exr is NPOT
  38. //console.log( textureData );
  39. //console.log( texture );
  40. // EXRLoader sets these default settings
  41. //texture.generateMipmaps = false;
  42. //texture.minFilter = LinearFilter;
  43. //texture.magFilter = LinearFilter;
  44. var material = new THREE.MeshBasicMaterial( { map: texture } );
  45. var quad = new THREE.PlaneBufferGeometry( 1.5 * textureData.width / textureData.height, 1.5 );
  46. var mesh = new THREE.Mesh( quad, material );
  47. scene.add( mesh );
  48. render();
  49. } );
  50. //
  51. var gui = new GUI();
  52. gui.add( params, 'exposure', 0, 4, 0.01 ).onChange( render );
  53. gui.open();
  54. //
  55. window.addEventListener( 'resize', onWindowResize, false );
  56. }
  57. function onWindowResize() {
  58. var aspect = window.innerWidth / window.innerHeight;
  59. var frustumHeight = camera.top - camera.bottom;
  60. camera.left = - frustumHeight * aspect / 2;
  61. camera.right = frustumHeight * aspect / 2;
  62. camera.updateProjectionMatrix();
  63. renderer.setSize( window.innerWidth, window.innerHeight );
  64. render();
  65. }
  66. //
  67. function render() {
  68. renderer.toneMappingExposure = params.exposure;
  69. renderer.render( scene, camera );
  70. }
  71. </script>
  72. </body>
  73. </html>