webgl_loader_texture_rgbm.html 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - materials - RGBM 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 RGBM texture loader example
  12. </div>
  13. <script type="module">
  14. import * as THREE from '../build/three.module.js';
  15. import { GUI } from './jsm/libs/dat.gui.module.js';
  16. var params = {
  17. exposure: 2.0
  18. };
  19. var renderer, scene, camera;
  20. init();
  21. function init() {
  22. renderer = new THREE.WebGLRenderer();
  23. renderer.setPixelRatio( window.devicePixelRatio );
  24. renderer.setSize( window.innerWidth, window.innerHeight );
  25. document.body.appendChild( renderer.domElement );
  26. renderer.toneMapping = THREE.ReinhardToneMapping;
  27. renderer.toneMappingExposure = params.exposure;
  28. renderer.outputEncoding = THREE.sRGBEncoding;
  29. scene = new THREE.Scene();
  30. var aspect = window.innerWidth / window.innerHeight;
  31. camera = new THREE.OrthographicCamera( - aspect, aspect, 1, - 1, 0, 1 );
  32. new THREE.TextureLoader().load( 'textures/memorial.png', function ( texture ) {
  33. texture.encoding = THREE.RGBM16Encoding;
  34. texture.minFilter = THREE.LinearFilter;
  35. texture.magFilter = THREE.LinearFilter;
  36. texture.flipY = true;
  37. var material = new THREE.MeshBasicMaterial( { map: texture } );
  38. var quad = new THREE.PlaneBufferGeometry( 1.5 * texture.width / texture.height, 1.5 );
  39. var mesh = new THREE.Mesh( quad, material );
  40. scene.add( mesh );
  41. render();
  42. } );
  43. //
  44. var gui = new GUI();
  45. gui.add( params, 'exposure', 0, 4, 0.01 ).onChange( render );
  46. gui.open();
  47. //
  48. window.addEventListener( 'resize', onWindowResize, false );
  49. }
  50. function onWindowResize() {
  51. var aspect = window.innerWidth / window.innerHeight;
  52. var frustumHeight = camera.top - camera.bottom;
  53. camera.left = - frustumHeight * aspect / 2;
  54. camera.right = frustumHeight * aspect / 2;
  55. camera.updateProjectionMatrix();
  56. renderer.setSize( window.innerWidth, window.innerHeight );
  57. render();
  58. }
  59. //
  60. function render() {
  61. renderer.toneMappingExposure = params.exposure;
  62. renderer.render( scene, camera );
  63. }
  64. </script>
  65. </body>
  66. </html>