webgl_loader_texture_pvrtc.html 5.4 KB

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