webgl_loader_texture_pvrtc.html 5.9 KB

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