2
0

webgl_loader_texture_pvrtc.html 5.7 KB

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