webgl_loader_texture_pvrtc.html 5.8 KB

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