webgl_loader_texture_pvrtc.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - materials - compressed textures</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 - PVR compressed textures
  12. </div>
  13. <!-- Import maps polyfill -->
  14. <!-- Remove this when import maps will be widely supported -->
  15. <script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
  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 { PVRLoader } from 'three/addons/loaders/PVRLoader.js';
  27. let camera, scene, renderer;
  28. const meshes = [];
  29. init();
  30. animate();
  31. function init() {
  32. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 );
  33. camera.position.z = 1000;
  34. scene = new THREE.Scene();
  35. const geometry = new THREE.BoxGeometry( 200, 200, 200 );
  36. //
  37. const onCube1Loaded = function ( texture ) {
  38. texture.magFilter = THREE.LinearFilter;
  39. texture.minFilter = THREE.LinearFilter;
  40. texture.mapping = THREE.CubeReflectionMapping;
  41. material6.needsUpdate = true;
  42. };
  43. const onCube2Loaded = function ( texture ) {
  44. texture.magFilter = THREE.LinearFilter;
  45. // texture.minFilter = LinearMipmapNearestFilter;
  46. texture.minFilter = THREE.LinearFilter;
  47. texture.mapping = THREE.CubeReflectionMapping;
  48. material8.needsUpdate = true;
  49. };
  50. //
  51. const loader = new PVRLoader();
  52. const disturb_4bpp_rgb = loader.load( 'textures/compressed/disturb_4bpp_rgb.pvr' );
  53. const disturb_4bpp_rgb_v3 = loader.load( 'textures/compressed/disturb_4bpp_rgb_v3.pvr' );
  54. const disturb_4bpp_rgb_mips = loader.load( 'textures/compressed/disturb_4bpp_rgb_mips.pvr' );
  55. const disturb_2bpp_rgb = loader.load( 'textures/compressed/disturb_2bpp_rgb.pvr' );
  56. const flare_4bpp_rgba = loader.load( 'textures/compressed/flare_4bpp_rgba.pvr' );
  57. const flare_2bpp_rgba = loader.load( 'textures/compressed/flare_2bpp_rgba.pvr' );
  58. const park3_cube_nomip_4bpp_rgb = loader.load( 'textures/compressed/park3_cube_nomip_4bpp_rgb.pvr', onCube1Loaded );
  59. const park3_cube_mip_2bpp_rgb_v3 = loader.load( 'textures/compressed/park3_cube_mip_2bpp_rgb_v3.pvr', onCube2Loaded );
  60. disturb_2bpp_rgb.minFilter =
  61. disturb_2bpp_rgb.magFilter =
  62. flare_4bpp_rgba.minFilter =
  63. flare_4bpp_rgba.magFilter =
  64. disturb_4bpp_rgb.minFilter =
  65. disturb_4bpp_rgb.magFilter =
  66. disturb_4bpp_rgb_v3.minFilter =
  67. disturb_4bpp_rgb_v3.magFilter =
  68. flare_2bpp_rgba.minFilter =
  69. flare_2bpp_rgba.magFilter = THREE.LinearFilter;
  70. const material1 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb } );
  71. const material2 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb_mips } );
  72. const material3 = new THREE.MeshBasicMaterial( { map: disturb_2bpp_rgb } );
  73. const material4 = new THREE.MeshBasicMaterial( { map: flare_4bpp_rgba, side: THREE.DoubleSide, depthTest: false, transparent: true } );
  74. const material5 = new THREE.MeshBasicMaterial( { map: flare_2bpp_rgba, side: THREE.DoubleSide, depthTest: false, transparent: true } );
  75. const material6 = new THREE.MeshBasicMaterial( { envMap: park3_cube_nomip_4bpp_rgb } );
  76. const material8 = new THREE.MeshBasicMaterial( { envMap: park3_cube_mip_2bpp_rgb_v3 } );
  77. const material7 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb_v3 } );
  78. //
  79. let mesh = new THREE.Mesh( geometry, material1 );
  80. mesh.position.x = - 500;
  81. mesh.position.y = 200;
  82. scene.add( mesh );
  83. meshes.push( mesh );
  84. mesh = new THREE.Mesh( geometry, material2 );
  85. mesh.position.x = - 166;
  86. mesh.position.y = 200;
  87. scene.add( mesh );
  88. meshes.push( mesh );
  89. mesh = new THREE.Mesh( geometry, material3 );
  90. mesh.position.x = 166;
  91. mesh.position.y = 200;
  92. scene.add( mesh );
  93. meshes.push( mesh );
  94. mesh = new THREE.Mesh( geometry, material7 );
  95. mesh.position.x = 500;
  96. mesh.position.y = 200;
  97. scene.add( mesh );
  98. meshes.push( mesh );
  99. mesh = new THREE.Mesh( geometry, material4 );
  100. mesh.position.x = - 500;
  101. mesh.position.y = - 200;
  102. scene.add( mesh );
  103. meshes.push( mesh );
  104. mesh = new THREE.Mesh( geometry, material5 );
  105. mesh.position.x = - 166;
  106. mesh.position.y = - 200;
  107. scene.add( mesh );
  108. meshes.push( mesh );
  109. const torus = new THREE.TorusGeometry( 100, 50, 32, 24 );
  110. mesh = new THREE.Mesh( torus, material6 );
  111. mesh.position.x = 166;
  112. mesh.position.y = - 200;
  113. scene.add( mesh );
  114. meshes.push( mesh );
  115. mesh = new THREE.Mesh( torus, material8 );
  116. mesh.position.x = 500;
  117. mesh.position.y = - 200;
  118. scene.add( mesh );
  119. meshes.push( mesh );
  120. //
  121. renderer = new THREE.WebGLRenderer( { antialias: true } );
  122. renderer.setPixelRatio( window.devicePixelRatio );
  123. renderer.setSize( window.innerWidth, window.innerHeight );
  124. document.body.appendChild( renderer.domElement );
  125. window.addEventListener( 'resize', onWindowResize );
  126. }
  127. function onWindowResize() {
  128. camera.aspect = window.innerWidth / window.innerHeight;
  129. camera.updateProjectionMatrix();
  130. renderer.setSize( window.innerWidth, window.innerHeight );
  131. }
  132. function animate() {
  133. requestAnimationFrame( animate );
  134. const time = Date.now() * 0.001;
  135. for ( let i = 0; i < meshes.length; i ++ ) {
  136. const mesh = meshes[ i ];
  137. mesh.rotation.x = time;
  138. mesh.rotation.y = time;
  139. }
  140. renderer.render( scene, camera );
  141. }
  142. </script>
  143. </body>
  144. </html>