webgl_loader_texture_pvrtc.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. texture.colorSpace = THREE.SRGBColorSpace;
  42. material6.needsUpdate = true;
  43. };
  44. const onCube2Loaded = function ( texture ) {
  45. texture.magFilter = THREE.LinearFilter;
  46. // texture.minFilter = LinearMipmapNearestFilter;
  47. texture.minFilter = THREE.LinearFilter;
  48. texture.mapping = THREE.CubeReflectionMapping;
  49. texture.colorSpace = THREE.SRGBColorSpace;
  50. material8.needsUpdate = true;
  51. };
  52. //
  53. const loader = new PVRLoader();
  54. const disturb_4bpp_rgb = loader.load( 'textures/compressed/disturb_4bpp_rgb.pvr' );
  55. const disturb_4bpp_rgb_v3 = loader.load( 'textures/compressed/disturb_4bpp_rgb_v3.pvr' );
  56. const disturb_4bpp_rgb_mips = loader.load( 'textures/compressed/disturb_4bpp_rgb_mips.pvr' );
  57. const disturb_2bpp_rgb = loader.load( 'textures/compressed/disturb_2bpp_rgb.pvr' );
  58. const flare_4bpp_rgba = loader.load( 'textures/compressed/flare_4bpp_rgba.pvr' );
  59. const flare_2bpp_rgba = loader.load( 'textures/compressed/flare_2bpp_rgba.pvr' );
  60. const park3_cube_nomip_4bpp_rgb = loader.load( 'textures/compressed/park3_cube_nomip_4bpp_rgb.pvr', onCube1Loaded );
  61. const park3_cube_mip_2bpp_rgb_v3 = loader.load( 'textures/compressed/park3_cube_mip_2bpp_rgb_v3.pvr', onCube2Loaded );
  62. disturb_2bpp_rgb.minFilter =
  63. disturb_2bpp_rgb.magFilter =
  64. flare_4bpp_rgba.minFilter =
  65. flare_4bpp_rgba.magFilter =
  66. disturb_4bpp_rgb.minFilter =
  67. disturb_4bpp_rgb.magFilter =
  68. disturb_4bpp_rgb_v3.minFilter =
  69. disturb_4bpp_rgb_v3.magFilter =
  70. flare_2bpp_rgba.minFilter =
  71. flare_2bpp_rgba.magFilter = THREE.LinearFilter;
  72. disturb_2bpp_rgb.encoding =
  73. flare_4bpp_rgba.encoding =
  74. disturb_4bpp_rgb.encoding =
  75. disturb_4bpp_rgb_v3.encoding =
  76. flare_2bpp_rgba.colorSpace = THREE.SRGBColorSpace;
  77. const material1 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb } );
  78. const material2 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb_mips } );
  79. const material3 = new THREE.MeshBasicMaterial( { map: disturb_2bpp_rgb } );
  80. const material4 = new THREE.MeshBasicMaterial( { map: flare_4bpp_rgba, side: THREE.DoubleSide, depthTest: false, transparent: true } );
  81. const material5 = new THREE.MeshBasicMaterial( { map: flare_2bpp_rgba, side: THREE.DoubleSide, depthTest: false, transparent: true } );
  82. const material6 = new THREE.MeshBasicMaterial( { envMap: park3_cube_nomip_4bpp_rgb } );
  83. const material8 = new THREE.MeshBasicMaterial( { envMap: park3_cube_mip_2bpp_rgb_v3 } );
  84. const material7 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb_v3 } );
  85. //
  86. let mesh = new THREE.Mesh( geometry, material1 );
  87. mesh.position.x = - 500;
  88. mesh.position.y = 200;
  89. scene.add( mesh );
  90. meshes.push( mesh );
  91. mesh = new THREE.Mesh( geometry, material2 );
  92. mesh.position.x = - 166;
  93. mesh.position.y = 200;
  94. scene.add( mesh );
  95. meshes.push( mesh );
  96. mesh = new THREE.Mesh( geometry, material3 );
  97. mesh.position.x = 166;
  98. mesh.position.y = 200;
  99. scene.add( mesh );
  100. meshes.push( mesh );
  101. mesh = new THREE.Mesh( geometry, material7 );
  102. mesh.position.x = 500;
  103. mesh.position.y = 200;
  104. scene.add( mesh );
  105. meshes.push( mesh );
  106. mesh = new THREE.Mesh( geometry, material4 );
  107. mesh.position.x = - 500;
  108. mesh.position.y = - 200;
  109. scene.add( mesh );
  110. meshes.push( mesh );
  111. mesh = new THREE.Mesh( geometry, material5 );
  112. mesh.position.x = - 166;
  113. mesh.position.y = - 200;
  114. scene.add( mesh );
  115. meshes.push( mesh );
  116. const torus = new THREE.TorusGeometry( 100, 50, 32, 24 );
  117. mesh = new THREE.Mesh( torus, material6 );
  118. mesh.position.x = 166;
  119. mesh.position.y = - 200;
  120. scene.add( mesh );
  121. meshes.push( mesh );
  122. mesh = new THREE.Mesh( torus, material8 );
  123. mesh.position.x = 500;
  124. mesh.position.y = - 200;
  125. scene.add( mesh );
  126. meshes.push( mesh );
  127. //
  128. renderer = new THREE.WebGLRenderer( { antialias: true } );
  129. renderer.setPixelRatio( window.devicePixelRatio );
  130. renderer.setSize( window.innerWidth, window.innerHeight );
  131. document.body.appendChild( renderer.domElement );
  132. window.addEventListener( 'resize', onWindowResize );
  133. }
  134. function onWindowResize() {
  135. camera.aspect = window.innerWidth / window.innerHeight;
  136. camera.updateProjectionMatrix();
  137. renderer.setSize( window.innerWidth, window.innerHeight );
  138. }
  139. function animate() {
  140. requestAnimationFrame( animate );
  141. const time = Date.now() * 0.001;
  142. for ( let i = 0; i < meshes.length; i ++ ) {
  143. const mesh = meshes[ i ];
  144. mesh.rotation.x = time;
  145. mesh.rotation.y = time;
  146. }
  147. renderer.render( scene, camera );
  148. }
  149. </script>
  150. </body>
  151. </html>