webgl_loader_texture_rgbm.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. import { RGBMLoader } from './jsm/loaders/RGBMLoader.js';
  17. const params = {
  18. exposure: 2.0
  19. };
  20. let renderer, scene, camera;
  21. init();
  22. function init() {
  23. renderer = new THREE.WebGLRenderer();
  24. renderer.setPixelRatio( window.devicePixelRatio );
  25. renderer.setSize( window.innerWidth, window.innerHeight );
  26. document.body.appendChild( renderer.domElement );
  27. renderer.toneMapping = THREE.ReinhardToneMapping;
  28. renderer.toneMappingExposure = params.exposure;
  29. renderer.outputEncoding = THREE.sRGBEncoding;
  30. scene = new THREE.Scene();
  31. const aspect = window.innerWidth / window.innerHeight;
  32. camera = new THREE.OrthographicCamera( - aspect, aspect, 1, - 1, 0, 1 );
  33. new RGBMLoader().load( 'textures/memorial.png', function ( texture ) {
  34. texture.encoding = THREE.RGBM16Encoding;
  35. const material = new THREE.MeshBasicMaterial( { map: texture } );
  36. const quad = new THREE.PlaneGeometry( 1, 1.5 );
  37. const mesh = new THREE.Mesh( quad, material );
  38. scene.add( mesh );
  39. render();
  40. } );
  41. //
  42. const gui = new GUI();
  43. gui.add( params, 'exposure', 0, 4, 0.01 ).onChange( render );
  44. gui.open();
  45. //
  46. window.addEventListener( 'resize', onWindowResize );
  47. }
  48. function onWindowResize() {
  49. const aspect = window.innerWidth / window.innerHeight;
  50. const frustumHeight = camera.top - camera.bottom;
  51. camera.left = - frustumHeight * aspect / 2;
  52. camera.right = frustumHeight * aspect / 2;
  53. camera.updateProjectionMatrix();
  54. renderer.setSize( window.innerWidth, window.innerHeight );
  55. render();
  56. }
  57. //
  58. function render() {
  59. renderer.toneMappingExposure = params.exposure;
  60. renderer.render( scene, camera );
  61. }
  62. </script>
  63. </body>
  64. </html>