webgl_materials_envmaps_fasthdr.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>threejs webgl - materials - equirectangular exr image based lighting</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. <meta property="og:title" content="threejs webgl - materials - equirectangular exr image based lighting">
  8. <meta property="og:type" content="website">
  9. <meta property="og:url" content="https://threejs.org/examples/webgl_materials_envmaps_fasthdr.html">
  10. <meta property="og:image" content="https://threejs.org/examples/screenshots/webgl_materials_envmaps_fasthdr.jpg">
  11. <link type="text/css" rel="stylesheet" href="main.css">
  12. </head>
  13. <body>
  14. <div id="container"></div>
  15. <div id="info"><a href="https://threejs.org" target="_blank" rel="noopener">threejs</a> - Example of <a href="https://cloud.needle.tools/hdris" target="_blank">FastHDR</a>, loading 10x faster and using 95% less GPU memory than EXR.<br/>Photography by <a href="https://cloud.needle.tools/hdris?img=Ballroom" target="_blank" rel="noopener">Sergej Majboroda</a></div>
  16. <script type="importmap">
  17. {
  18. "imports": {
  19. "three": "../build/three.module.js",
  20. "three/addons/": "./jsm/"
  21. }
  22. }
  23. </script>
  24. <script type="module">
  25. import * as THREE from 'three';
  26. import Stats from 'three/addons/libs/stats.module.js';
  27. import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
  28. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  29. import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
  30. const params = {
  31. 'image': 'ballroom',
  32. 'fov': 40,
  33. 'exposure': 1.0,
  34. 'backgroundBlurriness': 0.0
  35. };
  36. let container, stats;
  37. let camera, scene, renderer, controls;
  38. init();
  39. function init() {
  40. container = document.createElement( 'div' );
  41. document.body.appendChild( container );
  42. camera = new THREE.PerspectiveCamera( params.fov, window.innerWidth / window.innerHeight, .1, 50 );
  43. camera.position.set( 7, 0, 0 );
  44. scene = new THREE.Scene();
  45. renderer = new THREE.WebGLRenderer();
  46. renderer.setPixelRatio( window.devicePixelRatio );
  47. renderer.setSize( window.innerWidth, window.innerHeight );
  48. renderer.setAnimationLoop( animate );
  49. container.appendChild( renderer.domElement );
  50. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  51. //
  52. const sphereGeometry = new THREE.SphereGeometry( 0.45, 64, 32 );
  53. const sphere01 = new THREE.Mesh( sphereGeometry, new THREE.MeshPhysicalMaterial( {
  54. transmission: 1.0,
  55. thickness: 2.0,
  56. metalness: 0.0,
  57. roughness: 0.0,
  58. } ) );
  59. sphere01.position.z += 2;
  60. scene.add( sphere01 );
  61. const sphere02 = new THREE.Mesh( sphereGeometry, new THREE.MeshStandardMaterial( {
  62. metalness: 0.0,
  63. roughness: 1.0,
  64. } ) );
  65. sphere02.position.z += 1;
  66. scene.add( sphere02 );
  67. const sphere03 = new THREE.Mesh( sphereGeometry, new THREE.MeshStandardMaterial( {
  68. metalness: 1.0,
  69. roughness: 0.0,
  70. } ) );
  71. sphere03.position.z += 0;
  72. scene.add( sphere03 );
  73. const sphere04 = new THREE.Mesh( sphereGeometry, new THREE.MeshStandardMaterial( {
  74. metalness: 1.0,
  75. roughness: 0.5,
  76. color: 0x888888
  77. } ) );
  78. sphere04.position.z -= 1;
  79. scene.add( sphere04 );
  80. const sphere05 = new THREE.Mesh( sphereGeometry, new THREE.MeshStandardMaterial( {
  81. metalness: 0.0,
  82. roughness: 0.0,
  83. color: 0x6ab440
  84. } ) );
  85. sphere05.position.z -= 2;
  86. scene.add( sphere05 );
  87. const loader = new KTX2Loader()
  88. .detectSupport( renderer );
  89. function loadTexture( url ) {
  90. loader.load( url, ( texture ) => {
  91. texture.mapping = THREE.CubeUVReflectionMapping;
  92. scene.environment = texture;
  93. scene.background = texture;
  94. } );
  95. }
  96. loadTexture( 'https://cdn.needle.tools/static/hdris/ballroom_2k.pmrem.ktx2' );
  97. stats = new Stats();
  98. container.appendChild( stats.dom );
  99. controls = new OrbitControls( camera, renderer.domElement );
  100. controls.minDistance = .1;
  101. controls.maxDistance = 20;
  102. controls.enableDamping = true;
  103. window.addEventListener( 'resize', onWindowResize );
  104. const gui = new GUI();
  105. gui.add( params, 'image', {
  106. 'ballroom': 'https://cdn.needle.tools/static/hdris/ballroom_2k.pmrem.ktx2',
  107. 'brown photostudio': 'https://cdn.needle.tools/static/hdris/brown_photostudio_02_2k.pmrem.ktx2',
  108. 'cape hill': 'https://cdn.needle.tools/static/hdris/cape_hill_2k.pmrem.ktx2',
  109. 'cannon': 'https://cdn.needle.tools/static/hdris/cannon_2k.pmrem.ktx2',
  110. 'metro noord': 'https://cdn.needle.tools/static/hdris/metro_noord_2k.pmrem.ktx2',
  111. 'the sky is on fire': 'https://cdn.needle.tools/static/hdris/the_sky_is_on_fire_2k.pmrem.ktx2',
  112. 'studio small 09': 'https://cdn.needle.tools/static/hdris/studio_small_09_2k.pmrem.ktx2',
  113. 'wide street 01': 'https://cdn.needle.tools/static/hdris/wide_street_01_2k.pmrem.ktx2'
  114. } ).onChange( () => {
  115. loadTexture( params.image );
  116. } );
  117. gui.add( params, 'exposure', 0, 2, 0.01 );
  118. gui.add( params, 'fov', 10, 100 ).onChange( () => {
  119. camera.fov = params.fov;
  120. camera.updateProjectionMatrix();
  121. } );
  122. gui.add( params, 'backgroundBlurriness', 0, 1, 0.01 ).name( 'background blurriness' );
  123. gui.open();
  124. }
  125. function onWindowResize() {
  126. const width = window.innerWidth;
  127. const height = window.innerHeight;
  128. camera.aspect = width / height;
  129. camera.updateProjectionMatrix();
  130. renderer.setSize( width, height );
  131. }
  132. function animate() {
  133. stats.begin();
  134. render();
  135. stats.end();
  136. }
  137. function render() {
  138. renderer.toneMappingExposure = params.exposure;
  139. scene.backgroundBlurriness = params.backgroundBlurriness;
  140. controls.update();
  141. renderer.render( scene, camera );
  142. }
  143. </script>
  144. </body>
  145. </html>
粤ICP备19079148号